@jsonstudio/llms 0.6.802 → 0.6.938
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/bridge/routecodex-adapter.d.ts +74 -0
- package/dist/config-unified/enhanced-path-resolver.d.ts +5 -0
- package/dist/config-unified/unified-config.d.ts +26 -0
- package/dist/conversion/codec-registry.d.ts +10 -0
- package/dist/conversion/codecs/gemini-openai-codec.d.ts +16 -0
- package/dist/conversion/codecs/openai-openai-codec.d.ts +12 -0
- package/dist/conversion/codecs/responses-openai-codec.d.ts +12 -0
- package/dist/conversion/compat/profiles/chat-gemini.json +12 -0
- package/dist/conversion/config/config-manager.d.ts +212 -0
- package/dist/conversion/hub/config/types.d.ts +26 -0
- package/dist/conversion/hub/core/detour-registry.d.ts +9 -0
- package/dist/conversion/hub/core/hub-context.d.ts +21 -0
- package/dist/conversion/hub/core/index.d.ts +3 -0
- package/dist/conversion/hub/core/stage-driver.d.ts +30 -0
- package/dist/conversion/hub/format-adapters/anthropic-format-adapter.d.ts +16 -0
- package/dist/conversion/hub/format-adapters/chat-format-adapter.d.ts +17 -0
- package/dist/conversion/hub/format-adapters/gemini-format-adapter.d.ts +16 -0
- package/dist/conversion/hub/format-adapters/index.d.ts +21 -0
- package/dist/conversion/hub/hub-feature.d.ts +1 -0
- package/dist/conversion/hub/node-support.d.ts +19 -0
- package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +11 -0
- package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +3 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +7 -0
- package/dist/conversion/hub/pipeline/hub-pipeline.js +71 -14
- package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +4 -0
- package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +23 -1
- package/dist/conversion/hub/pipelines/inbound.d.ts +22 -0
- package/dist/conversion/hub/pipelines/outbound.d.ts +22 -0
- package/dist/conversion/hub/policy/policy-engine.d.ts +46 -0
- package/dist/conversion/hub/policy/policy-engine.js +176 -0
- package/dist/conversion/hub/policy/protocol-spec.d.ts +50 -0
- package/dist/conversion/hub/policy/protocol-spec.js +105 -0
- package/dist/conversion/hub/process/chat-process.d.ts +32 -0
- package/dist/conversion/hub/registry.d.ts +28 -0
- package/dist/conversion/hub/response/chat-response-utils.d.ts +6 -0
- package/dist/conversion/hub/response/provider-response.js +31 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +7 -0
- package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +87 -1
- package/dist/conversion/hub/semantic-mappers/index.d.ts +4 -0
- package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +21 -0
- package/dist/conversion/hub/standardized-bridge.d.ts +12 -0
- package/dist/conversion/hub/types/chat-schema.d.ts +112 -0
- package/dist/conversion/hub/types/errors.d.ts +5 -0
- package/dist/conversion/hub/types/format-envelope.d.ts +7 -0
- package/dist/conversion/hub/types/index.d.ts +6 -0
- package/dist/conversion/hub/types/json.d.ts +9 -0
- package/dist/conversion/hub/types/node.d.ts +31 -0
- package/dist/conversion/responses/responses-openai-bridge.js +263 -10
- package/dist/conversion/schema-validator.d.ts +7 -0
- package/dist/conversion/shared/args-mapping.d.ts +18 -0
- package/dist/conversion/shared/chat-request-filters.d.ts +9 -0
- package/dist/conversion/shared/errors.d.ts +1 -1
- package/dist/conversion/shared/gemini-tool-utils.js +61 -0
- package/dist/conversion/shared/jsonish.d.ts +3 -0
- package/dist/conversion/shared/mcp-injection.d.ts +2 -0
- package/dist/conversion/shared/media.d.ts +1 -0
- package/dist/conversion/shared/openai-message-normalize.d.ts +1 -0
- package/dist/conversion/shared/payload-budget.d.ts +13 -0
- package/dist/conversion/shared/reasoning-mapping.d.ts +5 -0
- package/dist/conversion/shared/responses-request-adapter.d.ts +1 -28
- package/dist/conversion/shared/responses-request-adapter.js +1 -430
- package/dist/conversion/shared/snapshot-hooks.js +58 -3
- package/dist/conversion/shared/tool-governor.js +8 -2
- package/dist/conversion/shared/tool-harvester.d.ts +31 -0
- package/dist/conversion/shared/tool-mapping.js +10 -29
- package/dist/conversion/types.d.ts +33 -0
- package/dist/filters/builtin/add-fields-filter.d.ts +8 -0
- package/dist/filters/builtin/blacklist-filter.d.ts +8 -0
- package/dist/filters/builtin/whitelist-filter.d.ts +8 -0
- package/dist/filters/engine.d.ts +16 -0
- package/dist/filters/special/request-tool-choice-policy.d.ts +11 -0
- package/dist/filters/special/response-finish-invariants.d.ts +11 -0
- package/dist/filters/special/response-openai-to-responses-bridge.d.ts +13 -0
- package/dist/filters/special/response-tool-arguments-blacklist.d.ts +12 -0
- package/dist/filters/special/response-tool-arguments-schema-converge.d.ts +13 -0
- package/dist/filters/special/response-tool-arguments-stringify.d.ts +9 -0
- package/dist/filters/special/response-tool-arguments-whitelist.d.ts +11 -0
- package/dist/filters/special/tool-filter-hooks.d.ts +19 -0
- package/dist/filters/special/tool-post-constraints.d.ts +31 -0
- package/dist/filters/types.d.ts +68 -0
- package/dist/filters/utils/fieldmap-loader.d.ts +2 -0
- package/dist/filters/utils/snapshot-writer.d.ts +10 -0
- package/dist/guidance/index.d.ts +3 -0
- package/dist/guidance/index.js +78 -83
- package/dist/http/sse-response.d.ts +22 -0
- package/dist/router/virtual-router/bootstrap.d.ts +6 -0
- package/dist/router/virtual-router/bootstrap.js +49 -5
- package/dist/router/virtual-router/classifier.d.ts +10 -0
- package/dist/router/virtual-router/engine-selection.js +98 -11
- package/dist/router/virtual-router/engine.js +177 -31
- package/dist/router/virtual-router/error-center.d.ts +10 -0
- package/dist/router/virtual-router/features.d.ts +3 -0
- package/dist/router/virtual-router/routing-instructions.d.ts +23 -1
- package/dist/router/virtual-router/routing-instructions.js +120 -30
- package/dist/router/virtual-router/types.d.ts +11 -0
- package/dist/servertool/engine.js +189 -16
- package/dist/servertool/handlers/apply-patch-guard.js +269 -0
- package/dist/servertool/handlers/exec-command-guard.js +558 -0
- package/dist/servertool/handlers/followup-message-trimmer.d.ts +16 -0
- package/dist/servertool/handlers/followup-message-trimmer.js +198 -0
- package/dist/servertool/handlers/followup-request-builder.d.ts +17 -0
- package/dist/servertool/handlers/followup-request-builder.js +122 -0
- package/dist/servertool/handlers/gemini-empty-reply-continue.js +252 -51
- package/dist/servertool/handlers/iflow-model-error-retry.js +12 -22
- package/dist/servertool/handlers/stop-message-auto.js +237 -75
- package/dist/servertool/handlers/vision.js +15 -27
- package/dist/servertool/handlers/web-search.js +17 -43
- package/dist/servertool/server-side-tools.d.ts +3 -0
- package/dist/servertool/server-side-tools.js +3 -0
- package/dist/sse/json-to-sse/anthropic-json-to-sse-converter.d.ts +2 -1
- package/dist/sse/json-to-sse/chat-json-to-sse-converter.d.ts +80 -0
- package/dist/sse/json-to-sse/event-generators/chat.d.ts +55 -0
- package/dist/sse/json-to-sse/event-generators/responses.d.ts +99 -0
- package/dist/sse/json-to-sse/gemini-json-to-sse-converter.d.ts +2 -1
- package/dist/sse/json-to-sse/responses-json-to-sse-converter.d.ts +80 -0
- package/dist/sse/json-to-sse/sequencers/anthropic-sequencer.d.ts +1 -1
- package/dist/sse/json-to-sse/sequencers/chat-sequencer.d.ts +2 -2
- package/dist/sse/json-to-sse/sequencers/gemini-sequencer.d.ts +1 -1
- package/dist/sse/json-to-sse/sequencers/responses-sequencer.d.ts +40 -0
- package/dist/sse/shared/chat-serializer.d.ts +4 -0
- package/dist/sse/shared/constants.d.ts +272 -0
- package/dist/sse/shared/serializers/anthropic-event-serializer.d.ts +1 -1
- package/dist/sse/shared/serializers/base-serializer.d.ts +158 -0
- package/dist/sse/shared/serializers/chat-event-serializer.d.ts +82 -0
- package/dist/sse/shared/serializers/gemini-event-serializer.d.ts +1 -1
- package/dist/sse/shared/serializers/index.d.ts +2 -1
- package/dist/sse/shared/serializers/responses-event-serializer.d.ts +123 -0
- package/dist/sse/shared/serializers/types.d.ts +51 -0
- package/dist/sse/shared/utils.d.ts +254 -0
- package/dist/sse/shared/writer.d.ts +2 -2
- package/dist/sse/sse-to-json/anthropic-sse-to-json-converter.d.ts +1 -1
- package/dist/sse/sse-to-json/builders/anthropic-response-builder.d.ts +1 -1
- package/dist/sse/sse-to-json/builders/response-builder.d.ts +1 -1
- package/dist/sse/sse-to-json/chat-sse-to-json-converter.d.ts +2 -1
- package/dist/sse/sse-to-json/gemini-sse-to-json-converter.d.ts +2 -1
- package/dist/sse/sse-to-json/parsers/sse-parser.d.ts +73 -0
- package/dist/sse/sse-to-json/responses-sse-to-json-converter.d.ts +1 -1
- package/dist/sse/types/chat-types.d.ts +1 -1
- package/dist/sse/types/responses-types.d.ts +1 -1
- package/dist/tools/apply-patch/execution-capturer.d.ts +13 -0
- package/dist/tools/apply-patch/execution-capturer.js +158 -0
- package/dist/tools/apply-patch/regression-capturer.d.ts +1 -0
- package/dist/tools/apply-patch/regression-capturer.js +5 -4
- package/dist/tools/apply-patch/structured.js +109 -13
- package/dist/tools/apply-patch/validator.js +112 -18
- package/dist/tools/tool-registry.d.ts +8 -0
- package/dist/tools/tool-registry.js +2 -1
- package/package.json +4 -4
- package/dist/conversion/compat/actions/apply-patch-format-fixer.js +0 -233
- package/dist/conversion/config/compat-profiles.json +0 -38
- package/dist/conversion/hub/pipeline/context-limit.d.ts +0 -13
- package/dist/conversion/hub/pipeline/context-limit.js +0 -55
- package/dist/conversion/hub/response/server-side-tools.d.ts +0 -26
- package/dist/conversion/hub/response/server-side-tools.js +0 -383
- package/dist/conversion/shared/bridge-conversation-store.d.ts +0 -41
- package/dist/conversion/shared/bridge-conversation-store.js +0 -279
- package/dist/conversion/shared/bridge-request-adapter.d.ts +0 -28
- package/dist/conversion/shared/bridge-request-adapter.js +0 -430
- package/dist/conversion/shared/responses-id-utils.js +0 -42
- package/dist/conversion/shared/responses-instructions.js +0 -113
- package/dist/conversion/shared/responses-message-utils.d.ts +0 -15
- package/dist/conversion/shared/responses-message-utils.js +0 -206
- package/dist/conversion/shared/responses-metadata.js +0 -1
- package/dist/conversion/shared/responses-output-utils.d.ts +0 -7
- package/dist/conversion/shared/responses-output-utils.js +0 -108
- package/dist/conversion/shared/responses-types.d.ts +0 -33
- package/dist/conversion/shared/tool-normalizers.d.ts +0 -4
- package/dist/conversion/shared/tool-normalizers.js +0 -84
- package/dist/filters/special/request-streaming-to-nonstreaming.d.ts +0 -13
- package/dist/filters/special/request-streaming-to-nonstreaming.js +0 -39
- package/dist/filters/special/response-apply-patch-toon-decode.d.ts +0 -23
- package/dist/filters/special/response-apply-patch-toon-decode.js +0 -460
- package/dist/filters/special/response-tool-arguments-toon-decode.d.ts +0 -10
- package/dist/filters/special/response-tool-arguments-toon-decode.js +0 -154
- package/dist/servertool/flow-types.d.ts +0 -40
- package/dist/servertool/flow-types.js +0 -1
- package/dist/servertool/orchestration-types.d.ts +0 -33
- package/dist/servertool/orchestration-types.js +0 -1
- package/dist/servertool/vision-tool.d.ts +0 -2
- package/dist/servertool/vision-tool.js +0 -185
- package/dist/tools/patch-args-normalizer.d.ts +0 -15
- package/dist/tools/patch-args-normalizer.js +0 -472
- package/dist/utils/toon.d.ts +0 -4
- package/dist/utils/toon.js +0 -75
- /package/dist/{conversion/compat/actions/apply-patch-format-fixer.d.ts → servertool/handlers/apply-patch-guard.d.ts} +0 -0
- /package/dist/{conversion/shared/responses-types.js → servertool/handlers/exec-command-guard.d.ts} +0 -0
|
@@ -1,472 +0,0 @@
|
|
|
1
|
-
// Unified apply_patch arguments normalizer
|
|
2
|
-
// Centralizes all fixable format repairs: missing headers, prefix issues, field aliases, etc.
|
|
3
|
-
// Does NOT fix context mismatches (those must be reported to user).
|
|
4
|
-
import { buildStructuredPatch, isStructuredApplyPatchPayload } from './apply-patch-structured.js';
|
|
5
|
-
/**
|
|
6
|
-
* Attempt to fix common apply_patch argument format issues:
|
|
7
|
-
* 1. Missing *** Begin Patch / *** End Patch markers
|
|
8
|
-
* 2. Lines missing +/- prefix in hunks
|
|
9
|
-
* 3. Field aliases (input->patch, code->patch, diff->patch)
|
|
10
|
-
* 4. Structured changes array conversion
|
|
11
|
-
* 5. Git diff format conversion
|
|
12
|
-
*/
|
|
13
|
-
export function normalizeApplyPatchArgs(argsStr) {
|
|
14
|
-
try {
|
|
15
|
-
let args;
|
|
16
|
-
try {
|
|
17
|
-
args = JSON.parse(argsStr);
|
|
18
|
-
}
|
|
19
|
-
catch {
|
|
20
|
-
// Fallback: raw patch text without JSON wrapper
|
|
21
|
-
if (argsStr.includes('*** Begin Patch')) {
|
|
22
|
-
return { normalized: JSON.stringify({ patch: argsStr }) };
|
|
23
|
-
}
|
|
24
|
-
return { error: 'invalid_json' };
|
|
25
|
-
}
|
|
26
|
-
if (!args || typeof args !== 'object') {
|
|
27
|
-
return { error: 'invalid_args_type' };
|
|
28
|
-
}
|
|
29
|
-
let modified = false;
|
|
30
|
-
// Fix 1: Handle field aliases
|
|
31
|
-
if (args.patch && args.input) {
|
|
32
|
-
delete args.input;
|
|
33
|
-
modified = true;
|
|
34
|
-
}
|
|
35
|
-
else if (!args.patch && args.input) {
|
|
36
|
-
args.patch = args.input;
|
|
37
|
-
delete args.input;
|
|
38
|
-
modified = true;
|
|
39
|
-
}
|
|
40
|
-
// Fix 2: Convert structured changes to patch text
|
|
41
|
-
if (!args.patch && isStructuredApplyPatchPayload(args)) {
|
|
42
|
-
try {
|
|
43
|
-
args.patch = buildStructuredPatch(args);
|
|
44
|
-
delete args.changes;
|
|
45
|
-
delete args.file;
|
|
46
|
-
delete args.instructions;
|
|
47
|
-
modified = true;
|
|
48
|
-
}
|
|
49
|
-
catch {
|
|
50
|
-
// Let structured errors pass through
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Fix 2.1: Convert { changes:[{search,replace}] } to structured replace
|
|
54
|
-
if (!args.patch && Array.isArray(args.changes)) {
|
|
55
|
-
const converted = convertSearchReplaceChanges(args);
|
|
56
|
-
if (converted) {
|
|
57
|
-
try {
|
|
58
|
-
args.patch = buildStructuredPatch(converted);
|
|
59
|
-
delete args.changes;
|
|
60
|
-
delete args.file;
|
|
61
|
-
delete args.instructions;
|
|
62
|
-
modified = true;
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
// Ignore conversion failure
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
// Fix 3: Alias fields (code, diff) -> patch
|
|
70
|
-
if (!args.patch) {
|
|
71
|
-
if (typeof args.code === 'string') {
|
|
72
|
-
args.patch = args.code;
|
|
73
|
-
delete args.code;
|
|
74
|
-
modified = true;
|
|
75
|
-
}
|
|
76
|
-
else if (typeof args.diff === 'string') {
|
|
77
|
-
args.patch = args.diff;
|
|
78
|
-
delete args.diff;
|
|
79
|
-
modified = true;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
// Fix 4: Normalize patch text format
|
|
83
|
-
if (typeof args.patch === 'string') {
|
|
84
|
-
const cleaned = stripConflictMarkers(args.patch);
|
|
85
|
-
if (cleaned !== args.patch) {
|
|
86
|
-
args.patch = cleaned;
|
|
87
|
-
modified = true;
|
|
88
|
-
}
|
|
89
|
-
const fixed = fixPatchTextFormat(args.patch);
|
|
90
|
-
if (fixed !== args.patch) {
|
|
91
|
-
args.patch = fixed;
|
|
92
|
-
modified = true;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return modified ? { normalized: JSON.stringify(args) } : { normalized: null };
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
return { error: 'normalization_failed' };
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
export function looksLikePatch(text) {
|
|
102
|
-
if (!text)
|
|
103
|
-
return false;
|
|
104
|
-
const t = text.trim();
|
|
105
|
-
if (!t)
|
|
106
|
-
return false;
|
|
107
|
-
return (t.includes('*** Begin Patch') ||
|
|
108
|
-
t.includes('*** Update File:') ||
|
|
109
|
-
t.includes('*** Add File:') ||
|
|
110
|
-
t.includes('*** Delete File:') ||
|
|
111
|
-
t.includes('diff --git') ||
|
|
112
|
-
/^(?:@@|\+\+\+\s|---\s)/m.test(t));
|
|
113
|
-
}
|
|
114
|
-
export function normalizeApplyPatchText(raw) {
|
|
115
|
-
if (!raw)
|
|
116
|
-
return raw;
|
|
117
|
-
let text = raw.replace(/\r\n/g, '\n');
|
|
118
|
-
text = decodeEscapedNewlinesIfNeeded(text);
|
|
119
|
-
text = stripCodeFences(text);
|
|
120
|
-
text = text.trim();
|
|
121
|
-
if (!text) {
|
|
122
|
-
return raw;
|
|
123
|
-
}
|
|
124
|
-
if (!text.includes('*** Begin Patch') && text.includes('diff --git')) {
|
|
125
|
-
const converted = convertGitDiffToApplyPatch(text);
|
|
126
|
-
if (converted) {
|
|
127
|
-
text = converted;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else if (!text.includes('*** Begin Patch') && !text.includes('diff --git')) {
|
|
131
|
-
const minusMatch = text.match(/^---\s+(.*)$/m);
|
|
132
|
-
const plusMatch = text.match(/^\+\+\+\s+(.*)$/m);
|
|
133
|
-
if (minusMatch && plusMatch) {
|
|
134
|
-
const rawPlus = plusMatch[1] || '';
|
|
135
|
-
const pathMatch = rawPlus.match(/^(?:b\/)?(.+)$/);
|
|
136
|
-
const path = (pathMatch && pathMatch[1] ? pathMatch[1] : rawPlus).trim();
|
|
137
|
-
if (path) {
|
|
138
|
-
const synthetic = `diff --git a/${path} b/${path}\n${text}`;
|
|
139
|
-
const converted = convertGitDiffToApplyPatch(synthetic);
|
|
140
|
-
if (converted) {
|
|
141
|
-
text = converted;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (text.includes('*** Add File:')) {
|
|
147
|
-
text = text.replace(/\*\*\* Create File:/g, '*** Add File:');
|
|
148
|
-
}
|
|
149
|
-
let hasBegin = text.includes('*** Begin Patch');
|
|
150
|
-
const hasEnd = text.includes('*** End Patch');
|
|
151
|
-
if (hasBegin && !hasEnd) {
|
|
152
|
-
text = `${text}\n*** End Patch`;
|
|
153
|
-
}
|
|
154
|
-
if (!hasBegin && /^\*\*\* (Add|Update|Delete) File:/m.test(text)) {
|
|
155
|
-
text = `*** Begin Patch\n${text}\n*** End Patch`;
|
|
156
|
-
hasBegin = true;
|
|
157
|
-
}
|
|
158
|
-
if (!text.includes('*** Begin Patch')) {
|
|
159
|
-
return text;
|
|
160
|
-
}
|
|
161
|
-
const beginIndex = text.indexOf('*** Begin Patch');
|
|
162
|
-
if (beginIndex > 0) {
|
|
163
|
-
text = text.slice(beginIndex);
|
|
164
|
-
}
|
|
165
|
-
const endMarker = '*** End Patch';
|
|
166
|
-
const firstEndIndex = text.indexOf(endMarker);
|
|
167
|
-
const concatSignatures = [
|
|
168
|
-
`${endMarker}","input":"*** Begin Patch`,
|
|
169
|
-
`${endMarker}","patch":"*** Begin Patch`,
|
|
170
|
-
`${endMarker}\\",\\"input\\":\\"*** Begin Patch`,
|
|
171
|
-
`${endMarker}\\",\\"patch\\":\\"*** Begin Patch`
|
|
172
|
-
];
|
|
173
|
-
const hasConcatenationSignal = concatSignatures.some((sig) => text.includes(sig));
|
|
174
|
-
if (hasConcatenationSignal && firstEndIndex >= 0) {
|
|
175
|
-
text = text.slice(0, firstEndIndex + endMarker.length);
|
|
176
|
-
}
|
|
177
|
-
else {
|
|
178
|
-
const lastEndIndex = text.lastIndexOf(endMarker);
|
|
179
|
-
if (lastEndIndex >= 0) {
|
|
180
|
-
const afterEnd = text.slice(lastEndIndex + endMarker.length);
|
|
181
|
-
if (afterEnd.trim().length > 0) {
|
|
182
|
-
text = text.slice(0, lastEndIndex + endMarker.length);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
const lines = text.split('\n');
|
|
187
|
-
const output = [];
|
|
188
|
-
let inUpdateSection = false;
|
|
189
|
-
let afterUpdateHeader = false;
|
|
190
|
-
for (const line of lines) {
|
|
191
|
-
if (line.startsWith('*** Begin Patch')) {
|
|
192
|
-
output.push(line);
|
|
193
|
-
inUpdateSection = false;
|
|
194
|
-
afterUpdateHeader = false;
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
if (line.startsWith('*** End Patch')) {
|
|
198
|
-
output.push(line);
|
|
199
|
-
inUpdateSection = false;
|
|
200
|
-
afterUpdateHeader = false;
|
|
201
|
-
continue;
|
|
202
|
-
}
|
|
203
|
-
if (line.startsWith('*** Update File:')) {
|
|
204
|
-
output.push(line);
|
|
205
|
-
inUpdateSection = true;
|
|
206
|
-
afterUpdateHeader = true;
|
|
207
|
-
continue;
|
|
208
|
-
}
|
|
209
|
-
if (line.startsWith('*** Add File:') || line.startsWith('*** Delete File:')) {
|
|
210
|
-
output.push(line);
|
|
211
|
-
inUpdateSection = false;
|
|
212
|
-
afterUpdateHeader = false;
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
if (inUpdateSection) {
|
|
216
|
-
if (afterUpdateHeader && line.trim() === '') {
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
afterUpdateHeader = false;
|
|
220
|
-
if (line.startsWith('@@') || line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) {
|
|
221
|
-
output.push(line);
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
output.push(` ${line}`);
|
|
225
|
-
}
|
|
226
|
-
continue;
|
|
227
|
-
}
|
|
228
|
-
output.push(line);
|
|
229
|
-
}
|
|
230
|
-
return output.join('\n');
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Fix common patch text format issues:
|
|
234
|
-
* - Missing *** Begin/End Patch markers
|
|
235
|
-
* - Lines missing +/- prefix in update hunks
|
|
236
|
-
* - Extra whitespace/comments
|
|
237
|
-
*/
|
|
238
|
-
function fixPatchTextFormat(patchText) {
|
|
239
|
-
let text = patchText.trim();
|
|
240
|
-
if (!text)
|
|
241
|
-
return patchText;
|
|
242
|
-
// Fix 1: Add missing *** Begin Patch
|
|
243
|
-
const hasBegin = text.includes('*** Begin Patch');
|
|
244
|
-
const hasEnd = text.includes('*** End Patch');
|
|
245
|
-
const hasFileOp = /^\*\*\* (Add|Update|Delete) File:/m.test(text);
|
|
246
|
-
if (!hasBegin && hasFileOp) {
|
|
247
|
-
text = `*** Begin Patch\n${text}`;
|
|
248
|
-
}
|
|
249
|
-
// Fix 2: Add missing *** End Patch
|
|
250
|
-
if (text.includes('*** Begin Patch') && !hasEnd) {
|
|
251
|
-
text = `${text}\n*** End Patch`;
|
|
252
|
-
}
|
|
253
|
-
// Fix 3: Normalize lines in update hunks
|
|
254
|
-
text = fixHunkLinePrefixes(text);
|
|
255
|
-
return text;
|
|
256
|
-
}
|
|
257
|
-
/**
|
|
258
|
-
* Fix missing +/- prefixes in update hunks.
|
|
259
|
-
* Pattern: After "*** Update File:" and before next file operation,
|
|
260
|
-
* lines should start with ' ', '+', '-', or '@@'.
|
|
261
|
-
*/
|
|
262
|
-
function fixHunkLinePrefixes(text) {
|
|
263
|
-
const lines = text.split('\n');
|
|
264
|
-
const output = [];
|
|
265
|
-
let inUpdateHunk = false;
|
|
266
|
-
let afterUpdateHeader = false;
|
|
267
|
-
for (const line of lines) {
|
|
268
|
-
// Track section boundaries
|
|
269
|
-
if (line.startsWith('*** Begin Patch') || line.startsWith('*** End Patch')) {
|
|
270
|
-
output.push(line);
|
|
271
|
-
inUpdateHunk = false;
|
|
272
|
-
afterUpdateHeader = false;
|
|
273
|
-
continue;
|
|
274
|
-
}
|
|
275
|
-
if (line.startsWith('*** Update File:')) {
|
|
276
|
-
output.push(line);
|
|
277
|
-
inUpdateHunk = true;
|
|
278
|
-
afterUpdateHeader = true;
|
|
279
|
-
continue;
|
|
280
|
-
}
|
|
281
|
-
if (line.startsWith('*** Add File:') || line.startsWith('*** Delete File:')) {
|
|
282
|
-
output.push(line);
|
|
283
|
-
inUpdateHunk = false;
|
|
284
|
-
afterUpdateHeader = false;
|
|
285
|
-
continue;
|
|
286
|
-
}
|
|
287
|
-
// Skip empty line after Update File: header
|
|
288
|
-
if (inUpdateHunk && afterUpdateHeader && line.trim() === '') {
|
|
289
|
-
afterUpdateHeader = false;
|
|
290
|
-
continue;
|
|
291
|
-
}
|
|
292
|
-
if (inUpdateHunk) {
|
|
293
|
-
afterUpdateHeader = false;
|
|
294
|
-
// Line should start with ' ', '+', '-', or '@@'
|
|
295
|
-
if (line.startsWith('@@') || line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) {
|
|
296
|
-
output.push(line);
|
|
297
|
-
}
|
|
298
|
-
else if (line.trim() === '') {
|
|
299
|
-
// Empty lines in hunks become context lines
|
|
300
|
-
output.push(' ');
|
|
301
|
-
}
|
|
302
|
-
else {
|
|
303
|
-
// Missing prefix: treat as context line
|
|
304
|
-
output.push(` ${line}`);
|
|
305
|
-
}
|
|
306
|
-
continue;
|
|
307
|
-
}
|
|
308
|
-
// Not in update hunk: pass through
|
|
309
|
-
output.push(line);
|
|
310
|
-
}
|
|
311
|
-
return output.join('\n');
|
|
312
|
-
}
|
|
313
|
-
function stripConflictMarkers(patchText) {
|
|
314
|
-
if (!patchText.includes('<<<<<<<') && !patchText.includes('>>>>>>>') && !patchText.includes('=======')) {
|
|
315
|
-
return patchText;
|
|
316
|
-
}
|
|
317
|
-
const lines = patchText.split('\n');
|
|
318
|
-
const cleanLines = [];
|
|
319
|
-
for (const line of lines) {
|
|
320
|
-
if (line.startsWith('<<<<<<<')) {
|
|
321
|
-
if (line.includes('SEARCH')) {
|
|
322
|
-
cleanLines.push(line);
|
|
323
|
-
}
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
if (line.startsWith('=======')) {
|
|
327
|
-
cleanLines.push(line);
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (line.startsWith('>>>>>>>')) {
|
|
331
|
-
if (line.includes('REPLACE')) {
|
|
332
|
-
cleanLines.push(line);
|
|
333
|
-
}
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
cleanLines.push(line);
|
|
337
|
-
}
|
|
338
|
-
return cleanLines.join('\n');
|
|
339
|
-
}
|
|
340
|
-
function convertSearchReplaceChanges(payload) {
|
|
341
|
-
if (!payload || !Array.isArray(payload.changes))
|
|
342
|
-
return null;
|
|
343
|
-
const outChanges = [];
|
|
344
|
-
let saw = false;
|
|
345
|
-
for (const entry of payload.changes) {
|
|
346
|
-
if (!entry || typeof entry !== 'object')
|
|
347
|
-
continue;
|
|
348
|
-
if (typeof entry.search === 'string' && typeof entry.replace === 'string') {
|
|
349
|
-
outChanges.push({
|
|
350
|
-
kind: 'replace',
|
|
351
|
-
file: typeof entry.file === 'string' ? entry.file : payload.file,
|
|
352
|
-
target: entry.search,
|
|
353
|
-
lines: entry.replace
|
|
354
|
-
});
|
|
355
|
-
saw = true;
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
if (!saw)
|
|
359
|
-
return null;
|
|
360
|
-
return { file: payload.file, changes: outChanges };
|
|
361
|
-
}
|
|
362
|
-
function decodeEscapedNewlinesIfNeeded(value) {
|
|
363
|
-
if (!value)
|
|
364
|
-
return value;
|
|
365
|
-
if (value.includes('\n'))
|
|
366
|
-
return value;
|
|
367
|
-
const lower = value.toLowerCase();
|
|
368
|
-
const looksEscaped = value.includes('\\r\\n') ||
|
|
369
|
-
(value.includes('\\n') && /\\n[ \t]/.test(value)) ||
|
|
370
|
-
lower.includes('\\u000a') ||
|
|
371
|
-
lower.includes('\\u000d');
|
|
372
|
-
if (!looksEscaped) {
|
|
373
|
-
return value;
|
|
374
|
-
}
|
|
375
|
-
let out = value;
|
|
376
|
-
out = out.replace(/\\r\\n/g, '\n');
|
|
377
|
-
out = out.replace(/\\n/g, '\n');
|
|
378
|
-
out = out.replace(/\\r/g, '\n');
|
|
379
|
-
out = out.replace(/\\u000a/gi, '\n');
|
|
380
|
-
out = out.replace(/\\u000d/gi, '\n');
|
|
381
|
-
return out;
|
|
382
|
-
}
|
|
383
|
-
function stripCodeFences(text) {
|
|
384
|
-
const trimmed = text.trim();
|
|
385
|
-
if (!trimmed.startsWith('```')) {
|
|
386
|
-
return text;
|
|
387
|
-
}
|
|
388
|
-
const fenceRe = /^```(?:diff|patch|apply_patch|text|json)?[ \t]*\n([\s\S]*?)\n```/gmi;
|
|
389
|
-
const candidates = [];
|
|
390
|
-
let match = null;
|
|
391
|
-
while ((match = fenceRe.exec(trimmed))) {
|
|
392
|
-
if (match[1]) {
|
|
393
|
-
candidates.push(match[1].trim());
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
if (!candidates.length) {
|
|
397
|
-
return text;
|
|
398
|
-
}
|
|
399
|
-
for (const candidate of candidates) {
|
|
400
|
-
if (candidate.includes('*** Begin Patch') ||
|
|
401
|
-
candidate.includes('*** Update File:') ||
|
|
402
|
-
candidate.includes('diff --git')) {
|
|
403
|
-
return candidate;
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return candidates[0] ?? text;
|
|
407
|
-
}
|
|
408
|
-
function convertGitDiffToApplyPatch(text) {
|
|
409
|
-
const lines = text.replace(/\r\n/g, '\n').split('\n');
|
|
410
|
-
const files = [];
|
|
411
|
-
let current = null;
|
|
412
|
-
const flush = () => {
|
|
413
|
-
if (!current)
|
|
414
|
-
return;
|
|
415
|
-
if (current.path && current.kind === 'delete') {
|
|
416
|
-
files.push(current);
|
|
417
|
-
current = null;
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
if (!current.path || (current.kind === 'update' && current.lines.length === 0)) {
|
|
421
|
-
current = null;
|
|
422
|
-
return;
|
|
423
|
-
}
|
|
424
|
-
files.push(current);
|
|
425
|
-
current = null;
|
|
426
|
-
};
|
|
427
|
-
for (const raw of lines) {
|
|
428
|
-
const line = raw;
|
|
429
|
-
const diffMatch = line.match(/^diff --git a\/(.+?) b\/(.+)$/);
|
|
430
|
-
if (diffMatch) {
|
|
431
|
-
flush();
|
|
432
|
-
const path = diffMatch[2] || diffMatch[1];
|
|
433
|
-
current = { path, kind: 'update', lines: [] };
|
|
434
|
-
continue;
|
|
435
|
-
}
|
|
436
|
-
if (!current)
|
|
437
|
-
continue;
|
|
438
|
-
if (line.startsWith('new file mode')) {
|
|
439
|
-
current.kind = 'add';
|
|
440
|
-
continue;
|
|
441
|
-
}
|
|
442
|
-
if (line.startsWith('deleted file mode')) {
|
|
443
|
-
current.kind = 'delete';
|
|
444
|
-
continue;
|
|
445
|
-
}
|
|
446
|
-
if (line.startsWith('@@') || line.startsWith('+') || line.startsWith('-') || line.startsWith(' ')) {
|
|
447
|
-
current.lines.push(line);
|
|
448
|
-
continue;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
flush();
|
|
452
|
-
if (!files.length)
|
|
453
|
-
return null;
|
|
454
|
-
const out = ['*** Begin Patch'];
|
|
455
|
-
for (const file of files) {
|
|
456
|
-
if (file.kind === 'add') {
|
|
457
|
-
out.push(`*** Add File: ${file.path}`);
|
|
458
|
-
for (const line of file.lines) {
|
|
459
|
-
out.push(line.startsWith('+') ? line : `+${line}`);
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
else if (file.kind === 'delete') {
|
|
463
|
-
out.push(`*** Delete File: ${file.path}`);
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
out.push(`*** Update File: ${file.path}`);
|
|
467
|
-
out.push(...file.lines);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
out.push('*** End Patch');
|
|
471
|
-
return out.join('\n');
|
|
472
|
-
}
|
package/dist/utils/toon.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export type ToonKeyValue = Record<string, string>;
|
|
2
|
-
export declare function decodeToonToKeyValue(toon: string): ToonKeyValue | null;
|
|
3
|
-
export declare function coerceToonValue(value: string): unknown;
|
|
4
|
-
export declare function decodeToonToJson(toon: string): Record<string, unknown> | null;
|
package/dist/utils/toon.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export function decodeToonToKeyValue(toon) {
|
|
2
|
-
try {
|
|
3
|
-
const output = {};
|
|
4
|
-
const lines = String(toon ?? '')
|
|
5
|
-
.replace(/\r\n/g, '\n')
|
|
6
|
-
.split('\n');
|
|
7
|
-
let currentKey = null;
|
|
8
|
-
let currentValue = '';
|
|
9
|
-
const flush = () => {
|
|
10
|
-
if (currentKey) {
|
|
11
|
-
output[currentKey] = currentValue;
|
|
12
|
-
}
|
|
13
|
-
currentKey = null;
|
|
14
|
-
currentValue = '';
|
|
15
|
-
};
|
|
16
|
-
for (const raw of lines) {
|
|
17
|
-
const match = raw.match(/^([A-Za-z0-9_\-]+)\s*:\s*(.*)$/);
|
|
18
|
-
if (match) {
|
|
19
|
-
flush();
|
|
20
|
-
currentKey = match[1];
|
|
21
|
-
currentValue = match[2] ?? '';
|
|
22
|
-
}
|
|
23
|
-
else if (currentKey) {
|
|
24
|
-
currentValue += (currentValue ? '\n' : '') + raw;
|
|
25
|
-
}
|
|
26
|
-
else if (raw.trim()) {
|
|
27
|
-
// Encountered non-empty line before any key was established → treat as invalid TOON.
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
flush();
|
|
32
|
-
return Object.keys(output).length ? output : null;
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export function coerceToonValue(value) {
|
|
39
|
-
const trimmed = value.trim();
|
|
40
|
-
if (!trimmed) {
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
43
|
-
const lowered = trimmed.toLowerCase();
|
|
44
|
-
if (lowered === 'true')
|
|
45
|
-
return true;
|
|
46
|
-
if (lowered === 'false')
|
|
47
|
-
return false;
|
|
48
|
-
if (/^[+-]?\d+(\.\d+)?$/.test(trimmed)) {
|
|
49
|
-
const num = Number(trimmed);
|
|
50
|
-
if (Number.isFinite(num)) {
|
|
51
|
-
return num;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if ((trimmed.startsWith('{') && trimmed.endsWith('}')) ||
|
|
55
|
-
(trimmed.startsWith('[') && trimmed.endsWith(']'))) {
|
|
56
|
-
try {
|
|
57
|
-
return JSON.parse(trimmed);
|
|
58
|
-
}
|
|
59
|
-
catch {
|
|
60
|
-
// fall through
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
64
|
-
}
|
|
65
|
-
export function decodeToonToJson(toon) {
|
|
66
|
-
const kv = decodeToonToKeyValue(toon);
|
|
67
|
-
if (!kv) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
const result = {};
|
|
71
|
-
for (const [key, value] of Object.entries(kv)) {
|
|
72
|
-
result[key] = coerceToonValue(value);
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
File without changes
|
/package/dist/{conversion/shared/responses-types.js → servertool/handlers/exec-command-guard.d.ts}
RENAMED
|
File without changes
|