@jsonstudio/llms 0.6.1892 → 0.6.2172

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.
Files changed (159) hide show
  1. package/dist/conversion/compat/actions/deepseek-web-request.js +16 -2
  2. package/dist/conversion/compat/actions/deepseek-web-response.d.ts +7 -1
  3. package/dist/conversion/compat/actions/deepseek-web-response.js +302 -40
  4. package/dist/conversion/compat/actions/harvest-tool-calls-from-text.d.ts +5 -0
  5. package/dist/conversion/compat/actions/harvest-tool-calls-from-text.js +7 -4
  6. package/dist/conversion/compat/actions/iflow-tool-text-fallback.d.ts +1 -0
  7. package/dist/conversion/compat/actions/iflow-tool-text-fallback.js +12 -0
  8. package/dist/conversion/compat/actions/strip-orphan-function-calls-tag.js +1 -1
  9. package/dist/conversion/compat/actions/tool-text-request-guidance.d.ts +9 -0
  10. package/dist/conversion/compat/actions/tool-text-request-guidance.js +177 -0
  11. package/dist/conversion/compat/antigravity-session-signature.d.ts +6 -0
  12. package/dist/conversion/compat/antigravity-session-signature.js +15 -0
  13. package/dist/conversion/compat/profiles/chat-deepseek-web.json +52 -1
  14. package/dist/conversion/compat/profiles/chat-glm.json +22 -0
  15. package/dist/conversion/compat/profiles/chat-iflow.json +4 -0
  16. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +13 -27
  17. package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +10 -1
  18. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +13 -4
  19. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +1 -53
  20. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +8 -0
  21. package/dist/conversion/hub/pipeline/hub-pipeline.js +8 -4
  22. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +191 -9
  23. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +118 -15
  24. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +65 -2
  25. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.d.ts +34 -0
  26. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.js +75 -0
  27. package/dist/conversion/hub/process/chat-process.js +85 -18
  28. package/dist/conversion/hub/response/provider-response.js +21 -50
  29. package/dist/conversion/hub/response/response-runtime.js +71 -10
  30. package/dist/conversion/responses/responses-openai-bridge/response-payload.d.ts +3 -0
  31. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +576 -0
  32. package/dist/conversion/responses/responses-openai-bridge/types.d.ts +42 -0
  33. package/dist/conversion/responses/responses-openai-bridge/types.js +1 -0
  34. package/dist/conversion/responses/responses-openai-bridge.d.ts +3 -44
  35. package/dist/conversion/responses/responses-openai-bridge.js +193 -504
  36. package/dist/conversion/shared/anthropic-message-utils.js +82 -2
  37. package/dist/conversion/shared/bridge-message-utils.js +92 -39
  38. package/dist/conversion/shared/snapshot-hooks.js +8 -13
  39. package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.d.ts +2 -0
  40. package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.js +129 -0
  41. package/dist/conversion/shared/text-markup-normalizer/extractors-json.d.ts +4 -0
  42. package/dist/conversion/shared/text-markup-normalizer/extractors-json.js +637 -0
  43. package/dist/conversion/shared/text-markup-normalizer/extractors-shared.d.ts +21 -0
  44. package/dist/conversion/shared/text-markup-normalizer/extractors-shared.js +177 -0
  45. package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.d.ts +5 -0
  46. package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.js +385 -0
  47. package/dist/conversion/shared/text-markup-normalizer/extractors-xml.d.ts +10 -0
  48. package/dist/conversion/shared/text-markup-normalizer/extractors-xml.js +602 -0
  49. package/dist/conversion/shared/text-markup-normalizer/extractors.d.ts +5 -0
  50. package/dist/conversion/shared/text-markup-normalizer/extractors.js +4 -0
  51. package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +2 -0
  52. package/dist/conversion/shared/text-markup-normalizer/normalize.js +76 -0
  53. package/dist/conversion/shared/text-markup-normalizer.d.ts +3 -25
  54. package/dist/conversion/shared/text-markup-normalizer.js +2 -1386
  55. package/dist/conversion/shared/tool-governor.js +136 -10
  56. package/dist/filters/utils/snapshot-writer.js +3 -3
  57. package/dist/router/virtual-router/bootstrap/auth-utils.d.ts +6 -0
  58. package/dist/router/virtual-router/bootstrap/auth-utils.js +288 -0
  59. package/dist/router/virtual-router/bootstrap/claude-code-helpers.d.ts +11 -0
  60. package/dist/router/virtual-router/bootstrap/claude-code-helpers.js +18 -0
  61. package/dist/router/virtual-router/bootstrap/config-defaults.d.ts +5 -0
  62. package/dist/router/virtual-router/bootstrap/config-defaults.js +13 -0
  63. package/dist/router/virtual-router/bootstrap/config-normalizers.d.ts +4 -0
  64. package/dist/router/virtual-router/bootstrap/config-normalizers.js +106 -0
  65. package/dist/router/virtual-router/bootstrap/profile-builder.d.ts +7 -0
  66. package/dist/router/virtual-router/bootstrap/profile-builder.js +68 -0
  67. package/dist/router/virtual-router/bootstrap/provider-normalization.d.ts +40 -0
  68. package/dist/router/virtual-router/bootstrap/provider-normalization.js +212 -0
  69. package/dist/router/virtual-router/bootstrap/responses-helpers.d.ts +15 -0
  70. package/dist/router/virtual-router/bootstrap/responses-helpers.js +65 -0
  71. package/dist/router/virtual-router/bootstrap/routing-config.d.ts +23 -0
  72. package/dist/router/virtual-router/bootstrap/routing-config.js +293 -0
  73. package/dist/router/virtual-router/bootstrap/streaming-helpers.d.ts +12 -0
  74. package/dist/router/virtual-router/bootstrap/streaming-helpers.js +128 -0
  75. package/dist/router/virtual-router/bootstrap/utils.d.ts +5 -0
  76. package/dist/router/virtual-router/bootstrap/utils.js +41 -0
  77. package/dist/router/virtual-router/bootstrap/web-search-config.d.ts +4 -0
  78. package/dist/router/virtual-router/bootstrap/web-search-config.js +131 -0
  79. package/dist/router/virtual-router/bootstrap.d.ts +0 -4
  80. package/dist/router/virtual-router/bootstrap.js +31 -1275
  81. package/dist/router/virtual-router/classifier.js +32 -14
  82. package/dist/router/virtual-router/engine/antigravity/alias-lease.js +2 -2
  83. package/dist/router/virtual-router/engine/cooldown-manager.d.ts +34 -0
  84. package/dist/router/virtual-router/engine/cooldown-manager.js +118 -0
  85. package/dist/router/virtual-router/engine/route-analytics.d.ts +28 -0
  86. package/dist/router/virtual-router/engine/route-analytics.js +44 -0
  87. package/dist/router/virtual-router/engine/routing-pools/index.js +165 -4
  88. package/dist/router/virtual-router/engine/sticky-session-manager.d.ts +29 -0
  89. package/dist/router/virtual-router/engine/sticky-session-manager.js +55 -0
  90. package/dist/router/virtual-router/engine-logging.d.ts +42 -1
  91. package/dist/router/virtual-router/engine-logging.js +82 -15
  92. package/dist/router/virtual-router/engine-selection/multimodal-capability.d.ts +3 -0
  93. package/dist/router/virtual-router/engine-selection/multimodal-capability.js +26 -0
  94. package/dist/router/virtual-router/engine-selection/route-utils.js +6 -2
  95. package/dist/router/virtual-router/engine-selection/selection-deps.d.ts +1 -0
  96. package/dist/router/virtual-router/engine-selection/tier-selection.js +31 -1
  97. package/dist/router/virtual-router/engine.d.ts +21 -7
  98. package/dist/router/virtual-router/engine.js +198 -194
  99. package/dist/router/virtual-router/features.js +12 -4
  100. package/dist/router/virtual-router/message-utils.d.ts +8 -0
  101. package/dist/router/virtual-router/message-utils.js +170 -45
  102. package/dist/router/virtual-router/pre-command-file-resolver.js +40 -2
  103. package/dist/router/virtual-router/routing-instructions.d.ts +8 -0
  104. package/dist/router/virtual-router/routing-instructions.js +18 -2
  105. package/dist/router/virtual-router/routing-stop-message-actions.js +34 -10
  106. package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +2 -0
  107. package/dist/router/virtual-router/routing-stop-message-state-codec.js +50 -1
  108. package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
  109. package/dist/router/virtual-router/stop-message-state-sync.js +3 -0
  110. package/dist/router/virtual-router/token-counter.js +51 -10
  111. package/dist/router/virtual-router/tool-signals.js +4 -0
  112. package/dist/router/virtual-router/types.d.ts +15 -0
  113. package/dist/servertool/clock/session-scope.d.ts +3 -0
  114. package/dist/servertool/clock/session-scope.js +52 -0
  115. package/dist/servertool/clock/state.js +9 -0
  116. package/dist/servertool/clock/tasks.js +12 -1
  117. package/dist/servertool/clock/types.d.ts +3 -0
  118. package/dist/servertool/engine.js +177 -31
  119. package/dist/servertool/handlers/clock-auto.js +2 -8
  120. package/dist/servertool/handlers/clock.js +6 -9
  121. package/dist/servertool/handlers/recursive-detection-guard.js +53 -14
  122. package/dist/servertool/handlers/stop-message-auto/blocked-report.d.ts +16 -0
  123. package/dist/servertool/handlers/stop-message-auto/blocked-report.js +349 -0
  124. package/dist/servertool/handlers/stop-message-auto/iflow-followup.d.ts +23 -0
  125. package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +503 -0
  126. package/dist/servertool/handlers/stop-message-auto/routing-state.d.ts +38 -0
  127. package/dist/servertool/handlers/stop-message-auto/routing-state.js +149 -0
  128. package/dist/servertool/handlers/stop-message-auto/runtime-utils.d.ts +67 -0
  129. package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +387 -0
  130. package/dist/servertool/handlers/stop-message-auto.d.ts +1 -1
  131. package/dist/servertool/handlers/stop-message-auto.js +80 -556
  132. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.d.ts +18 -0
  133. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.js +398 -0
  134. package/dist/servertool/handlers/stop-message-stage-policy/decision.d.ts +9 -0
  135. package/dist/servertool/handlers/stop-message-stage-policy/decision.js +127 -0
  136. package/dist/servertool/handlers/stop-message-stage-policy/observation.d.ts +2 -0
  137. package/dist/servertool/handlers/stop-message-stage-policy/observation.js +179 -0
  138. package/dist/servertool/handlers/stop-message-stage-policy/templates.d.ts +4 -0
  139. package/dist/servertool/handlers/stop-message-stage-policy/templates.js +96 -0
  140. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.d.ts +9 -0
  141. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.js +89 -0
  142. package/dist/servertool/handlers/stop-message-stage-policy/types.d.ts +59 -0
  143. package/dist/servertool/handlers/stop-message-stage-policy/types.js +1 -0
  144. package/dist/servertool/handlers/stop-message-stage-policy.d.ts +3 -43
  145. package/dist/servertool/handlers/stop-message-stage-policy.js +2 -684
  146. package/dist/servertool/handlers/web-search.js +117 -0
  147. package/dist/servertool/server-side-tools.d.ts +0 -1
  148. package/dist/servertool/server-side-tools.js +4 -3
  149. package/dist/sse/sse-to-json/builders/response-builder.js +16 -0
  150. package/dist/sse/sse-to-json/chat-sse-to-json-converter.d.ts +1 -0
  151. package/dist/sse/sse-to-json/chat-sse-to-json-converter.js +110 -37
  152. package/dist/telemetry/stats-center.d.ts +9 -0
  153. package/dist/telemetry/stats-center.js +29 -1
  154. package/dist/tools/apply-patch/structured/coercion.js +3 -11
  155. package/dist/tools/exec-command/validator.d.ts +1 -0
  156. package/dist/tools/exec-command/validator.js +132 -0
  157. package/dist/tools/tool-registry.d.ts +1 -0
  158. package/dist/tools/tool-registry.js +1 -1
  159. package/package.json +1 -1
@@ -0,0 +1,67 @@
1
+ import type { JsonObject } from '../../../conversion/hub/types/json.js';
2
+ import type { RoutingInstructionState } from '../../../router/virtual-router/routing-instructions.js';
3
+ export declare function resolveStickyKey(record: {
4
+ requestId?: unknown;
5
+ providerProtocol?: unknown;
6
+ responsesResume?: unknown;
7
+ sessionId?: unknown;
8
+ conversationId?: unknown;
9
+ metadata?: unknown;
10
+ originalRequest?: unknown;
11
+ [key: string]: unknown;
12
+ }, runtimeMetadata?: unknown): string | undefined;
13
+ export declare function persistStopMessageState(stickyKey: string | undefined, state: RoutingInstructionState): void;
14
+ export declare function resolveBdWorkingDirectoryForRecord(record: {
15
+ metadata?: unknown;
16
+ originalRequest?: unknown;
17
+ [key: string]: unknown;
18
+ }, runtimeMetadata: unknown): string | undefined;
19
+ export declare function readServerToolFollowupFlowId(runtimeMetadata: unknown): string;
20
+ export declare function resolveStopMessageFollowupProviderKey(args: {
21
+ record: {
22
+ providerKey?: unknown;
23
+ providerId?: unknown;
24
+ metadata?: unknown;
25
+ };
26
+ runtimeMetadata?: unknown;
27
+ }): string;
28
+ export declare function resolveStopMessageFollowupToolContentMaxChars(params: {
29
+ providerKey?: string;
30
+ model?: string;
31
+ }): number | undefined;
32
+ export declare function getCapturedRequest(adapterContext: unknown): JsonObject | null;
33
+ export declare function resolveClientConnectionState(value: unknown): {
34
+ disconnected?: boolean;
35
+ } | null;
36
+ export declare function hasCompactionFlag(rt: unknown): boolean;
37
+ export declare function resolveImplicitGeminiStopMessageSnapshot(ctx: {
38
+ base: unknown;
39
+ adapterContext: unknown;
40
+ providerProtocol?: string;
41
+ }, record: {
42
+ providerProtocol?: unknown;
43
+ entryEndpoint?: unknown;
44
+ metadata?: unknown;
45
+ }): {
46
+ text: string;
47
+ maxRepeats: number;
48
+ used: number;
49
+ source?: string;
50
+ updatedAt?: number;
51
+ lastUsedAt?: number;
52
+ } | null;
53
+ export declare function resolveDefaultStopMessageSnapshot(ctx: {
54
+ base: unknown;
55
+ adapterContext: unknown;
56
+ }, options?: {
57
+ text?: string;
58
+ maxRepeats?: number;
59
+ }): {
60
+ text: string;
61
+ maxRepeats: number;
62
+ used: number;
63
+ source?: string;
64
+ updatedAt?: number;
65
+ lastUsedAt?: number;
66
+ } | null;
67
+ export declare function resolveEntryEndpoint(record: Record<string, unknown>): string;
@@ -0,0 +1,387 @@
1
+ import { readRuntimeMetadata } from '../../../conversion/shared/runtime-metadata.js';
2
+ import { saveRoutingInstructionStateAsync, saveRoutingInstructionStateSync } from '../../../router/virtual-router/sticky-session-store.js';
3
+ import { isStopEligibleForServerTool } from '../../stop-gateway-context.js';
4
+ import { extractResponsesOutputText, hasToolLikeOutput } from './iflow-followup.js';
5
+ export function resolveStickyKey(record, runtimeMetadata) {
6
+ const sessionId = readSessionScopeValue(record, runtimeMetadata, 'sessionId') ||
7
+ readSessionScopeValue(record, runtimeMetadata, 'session_id');
8
+ const conversationId = readSessionScopeValue(record, runtimeMetadata, 'conversationId') ||
9
+ readSessionScopeValue(record, runtimeMetadata, 'conversation_id');
10
+ if (sessionId) {
11
+ return `session:${sessionId}`;
12
+ }
13
+ if (conversationId) {
14
+ return `conversation:${conversationId}`;
15
+ }
16
+ const providerProtocol = resolveProviderProtocol(record, runtimeMetadata);
17
+ if (providerProtocol === 'openai-responses') {
18
+ const previousRequestId = resolveResponsesResumePreviousRequestId(record, runtimeMetadata);
19
+ if (previousRequestId) {
20
+ return previousRequestId;
21
+ }
22
+ const requestId = resolveRequestId(record, runtimeMetadata);
23
+ if (requestId) {
24
+ return requestId;
25
+ }
26
+ }
27
+ const requestId = resolveRequestId(record, runtimeMetadata);
28
+ return requestId || undefined;
29
+ }
30
+ export function persistStopMessageState(stickyKey, state) {
31
+ if (!stickyKey) {
32
+ return;
33
+ }
34
+ saveRoutingInstructionStateSync(stickyKey, state);
35
+ saveRoutingInstructionStateAsync(stickyKey, state);
36
+ }
37
+ export function resolveBdWorkingDirectoryForRecord(record, runtimeMetadata) {
38
+ const fromWorkdir = readSessionScopeValue(record, runtimeMetadata, 'workdir');
39
+ if (fromWorkdir) {
40
+ return fromWorkdir;
41
+ }
42
+ const fromCwd = readSessionScopeValue(record, runtimeMetadata, 'cwd');
43
+ if (fromCwd) {
44
+ return fromCwd;
45
+ }
46
+ const fromWorkingDirectory = readSessionScopeValue(record, runtimeMetadata, 'workingDirectory');
47
+ if (fromWorkingDirectory) {
48
+ return fromWorkingDirectory;
49
+ }
50
+ return undefined;
51
+ }
52
+ export function readServerToolFollowupFlowId(runtimeMetadata) {
53
+ const runtime = asRecord(runtimeMetadata);
54
+ const loopState = runtime ? asRecord(runtime.serverToolLoopState) : null;
55
+ const flowId = loopState ? toNonEmptyText(loopState.flowId) : '';
56
+ return flowId;
57
+ }
58
+ export function resolveStopMessageFollowupProviderKey(args) {
59
+ const direct = toNonEmptyText(args.record.providerKey) ||
60
+ toNonEmptyText(args.record.providerId) ||
61
+ readProviderKeyFromMetadata(args.record.metadata) ||
62
+ readProviderKeyFromMetadata(args.runtimeMetadata);
63
+ return direct;
64
+ }
65
+ export function resolveStopMessageFollowupToolContentMaxChars(params) {
66
+ const raw = String(process.env.ROUTECODEX_STOPMESSAGE_FOLLOWUP_TOOL_CONTENT_MAX_CHARS || '').trim();
67
+ if (raw) {
68
+ const parsed = Number(raw);
69
+ if (Number.isFinite(parsed) && parsed > 0) {
70
+ return Math.max(64, Math.floor(parsed));
71
+ }
72
+ return undefined;
73
+ }
74
+ const providerKey = typeof params.providerKey === 'string' ? params.providerKey.trim().toLowerCase() : '';
75
+ if (providerKey.startsWith('iflow.')) {
76
+ return 1200;
77
+ }
78
+ const model = typeof params.model === 'string' ? params.model.trim().toLowerCase() : '';
79
+ if (model === 'kimi-k2.5' || model.startsWith('kimi-k2.5-')) {
80
+ return 1200;
81
+ }
82
+ return undefined;
83
+ }
84
+ export function getCapturedRequest(adapterContext) {
85
+ if (!adapterContext || typeof adapterContext !== 'object') {
86
+ return null;
87
+ }
88
+ const contextRecord = adapterContext;
89
+ const direct = contextRecord.capturedChatRequest;
90
+ if (direct && typeof direct === 'object' && !Array.isArray(direct)) {
91
+ return direct;
92
+ }
93
+ const runtime = readRuntimeMetadata(contextRecord);
94
+ const runtimeCaptured = runtime && typeof runtime === 'object' && !Array.isArray(runtime)
95
+ ? runtime.capturedChatRequest
96
+ : undefined;
97
+ if (runtimeCaptured && typeof runtimeCaptured === 'object' && !Array.isArray(runtimeCaptured)) {
98
+ return runtimeCaptured;
99
+ }
100
+ const originalRequest = contextRecord.originalRequest;
101
+ if (originalRequest && typeof originalRequest === 'object' && !Array.isArray(originalRequest)) {
102
+ return originalRequest;
103
+ }
104
+ return null;
105
+ }
106
+ export function resolveClientConnectionState(value) {
107
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
108
+ return null;
109
+ }
110
+ return value;
111
+ }
112
+ export function hasCompactionFlag(rt) {
113
+ const flag = rt && typeof rt === 'object' && !Array.isArray(rt) ? rt.compactionRequest : undefined;
114
+ if (flag === true) {
115
+ return true;
116
+ }
117
+ if (typeof flag === 'string' && flag.trim().toLowerCase() === 'true') {
118
+ return true;
119
+ }
120
+ return false;
121
+ }
122
+ export function resolveImplicitGeminiStopMessageSnapshot(ctx, record) {
123
+ try {
124
+ const protoFromCtx = ctx.providerProtocol;
125
+ const protoFromRecord = typeof record.providerProtocol === 'string' && record.providerProtocol.trim()
126
+ ? String(record.providerProtocol).trim()
127
+ : undefined;
128
+ const providerProtocol = (protoFromCtx || protoFromRecord || '').toString().toLowerCase();
129
+ if (providerProtocol !== 'gemini-chat') {
130
+ return null;
131
+ }
132
+ const entryFromRecord = typeof record.entryEndpoint === 'string' && record.entryEndpoint.trim()
133
+ ? String(record.entryEndpoint).trim()
134
+ : undefined;
135
+ const metaEntry = record.metadata &&
136
+ typeof record.metadata === 'object' &&
137
+ record.metadata.entryEndpoint;
138
+ const entryFromMeta = typeof metaEntry === 'string' && metaEntry.trim() ? metaEntry.trim() : undefined;
139
+ const entryEndpoint = (entryFromRecord || entryFromMeta || '').toLowerCase();
140
+ if (!entryEndpoint.includes('/v1/responses')) {
141
+ return null;
142
+ }
143
+ if (!isStopEligibleForServerTool(ctx.base, ctx.adapterContext)) {
144
+ return null;
145
+ }
146
+ if (!isEmptyAssistantReply(ctx.base)) {
147
+ return null;
148
+ }
149
+ return {
150
+ text: '继续执行',
151
+ maxRepeats: 1,
152
+ used: 0,
153
+ source: 'auto'
154
+ };
155
+ }
156
+ catch {
157
+ return null;
158
+ }
159
+ }
160
+ export function resolveDefaultStopMessageSnapshot(ctx, options) {
161
+ try {
162
+ if (!isStopEligibleForServerTool(ctx.base, ctx.adapterContext)) {
163
+ return null;
164
+ }
165
+ const text = typeof options?.text === 'string' && options.text.trim().length
166
+ ? options.text.trim()
167
+ : '继续执行';
168
+ const maxRepeats = typeof options?.maxRepeats === 'number' && Number.isFinite(options.maxRepeats) && options.maxRepeats > 0
169
+ ? Math.floor(options.maxRepeats)
170
+ : 1;
171
+ return {
172
+ text,
173
+ maxRepeats,
174
+ used: 0,
175
+ source: 'default'
176
+ };
177
+ }
178
+ catch {
179
+ return null;
180
+ }
181
+ }
182
+ export function resolveEntryEndpoint(record) {
183
+ const raw = typeof record.entryEndpoint === 'string' && record.entryEndpoint.trim()
184
+ ? record.entryEndpoint.trim()
185
+ : undefined;
186
+ if (raw) {
187
+ return raw;
188
+ }
189
+ const metaEntry = record.metadata && typeof record.metadata === 'object' && record.metadata.entryEndpoint;
190
+ if (typeof metaEntry === 'string' && metaEntry.trim()) {
191
+ return metaEntry.trim();
192
+ }
193
+ return '/v1/chat/completions';
194
+ }
195
+ function isEmptyAssistantReply(base) {
196
+ if (!base || typeof base !== 'object' || Array.isArray(base)) {
197
+ return false;
198
+ }
199
+ const payload = base;
200
+ const choicesRaw = payload.choices;
201
+ if (Array.isArray(choicesRaw) && choicesRaw.length) {
202
+ const first = choicesRaw[0];
203
+ if (!first || typeof first !== 'object' || Array.isArray(first)) {
204
+ return false;
205
+ }
206
+ const finishReasonRaw = first.finish_reason;
207
+ const finishReason = typeof finishReasonRaw === 'string' && finishReasonRaw.trim()
208
+ ? finishReasonRaw.trim().toLowerCase()
209
+ : '';
210
+ if (finishReason !== 'stop') {
211
+ return false;
212
+ }
213
+ const message = first.message &&
214
+ typeof first.message === 'object' &&
215
+ !Array.isArray(first.message)
216
+ ? first.message
217
+ : null;
218
+ if (!message) {
219
+ return false;
220
+ }
221
+ const toolCalls = Array.isArray(message.tool_calls) ? message.tool_calls : [];
222
+ if (toolCalls.length > 0) {
223
+ return false;
224
+ }
225
+ const contentRaw = message.content;
226
+ const text = typeof contentRaw === 'string' ? contentRaw.trim() : '';
227
+ return text.length === 0;
228
+ }
229
+ const statusRaw = typeof payload.status === 'string' ? payload.status.trim().toLowerCase() : '';
230
+ if (statusRaw && statusRaw !== 'completed') {
231
+ return false;
232
+ }
233
+ if (payload.required_action && typeof payload.required_action === 'object') {
234
+ return false;
235
+ }
236
+ const outputText = extractResponsesOutputText(payload);
237
+ if (outputText.length > 0) {
238
+ return false;
239
+ }
240
+ const outputRaw = Array.isArray(payload.output) ? payload.output : [];
241
+ if (outputRaw.some((item) => hasToolLikeOutput(item))) {
242
+ return false;
243
+ }
244
+ return true;
245
+ }
246
+ function readSessionScopeValue(record, runtimeMetadata, key) {
247
+ const direct = toNonEmptyText(record[key]);
248
+ if (direct) {
249
+ return direct;
250
+ }
251
+ const metadata = asRecord(record.metadata);
252
+ const fromMetadata = metadata ? toNonEmptyText(metadata[key]) : '';
253
+ if (fromMetadata) {
254
+ return fromMetadata;
255
+ }
256
+ const fromRecordCapture = readHubCaptureContextValue(record, key);
257
+ if (fromRecordCapture) {
258
+ return fromRecordCapture;
259
+ }
260
+ const fromMetadataContext = metadata ? toNonEmptyText(asRecord(metadata.context)?.[key]) : '';
261
+ if (fromMetadataContext) {
262
+ return fromMetadataContext;
263
+ }
264
+ const fromMetadataCapture = metadata ? readHubCaptureContextValue(metadata, key) : '';
265
+ if (fromMetadataCapture) {
266
+ return fromMetadataCapture;
267
+ }
268
+ const originalRequest = asRecord(record.originalRequest);
269
+ const fromOriginalMetadata = originalRequest
270
+ ? toNonEmptyText(asRecord(originalRequest.metadata)?.[key])
271
+ : '';
272
+ if (fromOriginalMetadata) {
273
+ return fromOriginalMetadata;
274
+ }
275
+ const fromOriginalCapture = originalRequest ? readHubCaptureContextValue(originalRequest, key) : '';
276
+ if (fromOriginalCapture) {
277
+ return fromOriginalCapture;
278
+ }
279
+ const fromOriginalMetadataCapture = originalRequest
280
+ ? readHubCaptureContextValue(asRecord(originalRequest.metadata), key)
281
+ : '';
282
+ if (fromOriginalMetadataCapture) {
283
+ return fromOriginalMetadataCapture;
284
+ }
285
+ const runtime = asRecord(runtimeMetadata);
286
+ const fromRuntime = runtime ? toNonEmptyText(runtime[key]) : '';
287
+ if (fromRuntime) {
288
+ return fromRuntime;
289
+ }
290
+ const fromRuntimeCapture = runtime ? readHubCaptureContextValue(runtime, key) : '';
291
+ if (fromRuntimeCapture) {
292
+ return fromRuntimeCapture;
293
+ }
294
+ return '';
295
+ }
296
+ function readHubCaptureContextValue(source, key) {
297
+ if (!source) {
298
+ return '';
299
+ }
300
+ const hubCapture = asRecord(source.__hub_capture);
301
+ const capturedContext = asRecord(source.capturedContext);
302
+ const capturedHubCapture = asRecord(capturedContext?.__hub_capture);
303
+ const candidateRecords = [
304
+ source,
305
+ asRecord(source.context),
306
+ hubCapture,
307
+ asRecord(hubCapture?.context),
308
+ capturedContext,
309
+ asRecord(capturedContext?.context),
310
+ capturedHubCapture,
311
+ asRecord(capturedHubCapture?.context)
312
+ ];
313
+ for (const candidate of candidateRecords) {
314
+ if (!candidate) {
315
+ continue;
316
+ }
317
+ const value = toNonEmptyText(candidate[key]);
318
+ if (value) {
319
+ return value;
320
+ }
321
+ }
322
+ return '';
323
+ }
324
+ function resolveProviderProtocol(record, runtimeMetadata) {
325
+ const protocol = toNonEmptyText(record.providerProtocol) ||
326
+ readSessionScopeValue(record, runtimeMetadata, 'providerProtocol') ||
327
+ readSessionScopeValue(record, runtimeMetadata, 'provider_protocol');
328
+ return protocol.trim().toLowerCase();
329
+ }
330
+ function resolveRequestId(record, runtimeMetadata) {
331
+ return (toNonEmptyText(record.requestId) ||
332
+ readSessionScopeValue(record, runtimeMetadata, 'requestId') ||
333
+ readSessionScopeValue(record, runtimeMetadata, 'request_id'));
334
+ }
335
+ function resolveResponsesResumePreviousRequestId(record, runtimeMetadata) {
336
+ const runtime = asRecord(runtimeMetadata);
337
+ const metadata = asRecord(record.metadata);
338
+ const originalRequest = asRecord(record.originalRequest);
339
+ const metadataContext = metadata ? asRecord(metadata.context) : null;
340
+ const originalMetadata = originalRequest ? asRecord(originalRequest.metadata) : null;
341
+ const candidates = [
342
+ record.responsesResume,
343
+ metadata?.responsesResume,
344
+ metadataContext?.responsesResume,
345
+ originalRequest?.responsesResume,
346
+ originalMetadata?.responsesResume,
347
+ runtime?.responsesResume
348
+ ];
349
+ for (const candidate of candidates) {
350
+ const resume = asRecord(candidate);
351
+ if (!resume) {
352
+ continue;
353
+ }
354
+ const previousRequestId = toNonEmptyText(resume.previousRequestId) || toNonEmptyText(resume.previous_request_id);
355
+ if (previousRequestId) {
356
+ return previousRequestId;
357
+ }
358
+ }
359
+ return '';
360
+ }
361
+ function readProviderKeyFromMetadata(value) {
362
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
363
+ return '';
364
+ }
365
+ const metadata = value;
366
+ const direct = toNonEmptyText(metadata.providerKey) ||
367
+ toNonEmptyText(metadata.providerId) ||
368
+ toNonEmptyText(metadata.targetProviderKey);
369
+ if (direct) {
370
+ return direct;
371
+ }
372
+ const target = metadata.target;
373
+ if (target && typeof target === 'object' && !Array.isArray(target)) {
374
+ const targetRecord = target;
375
+ return toNonEmptyText(targetRecord.providerKey) || toNonEmptyText(targetRecord.providerId);
376
+ }
377
+ return '';
378
+ }
379
+ function asRecord(value) {
380
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
381
+ return null;
382
+ }
383
+ return value;
384
+ }
385
+ function toNonEmptyText(value) {
386
+ return typeof value === 'string' && value.trim().length ? value.trim() : '';
387
+ }
@@ -1 +1 @@
1
- export {};
1
+ export { extractBlockedReportFromMessagesForTests } from './stop-message-auto/blocked-report.js';