pi-openai-toolkit 0.23.2 → 0.24.1

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 (54) hide show
  1. package/LICENSE +21 -21
  2. package/NOTICE +83 -83
  3. package/README.md +4 -15
  4. package/README.zh.md +4 -15
  5. package/config.schema.json +264 -278
  6. package/docs/configuration.md +304 -306
  7. package/docs/internals.md +34 -120
  8. package/package.json +123 -136
  9. package/src/compact-client.ts +412 -412
  10. package/src/compaction-projection.ts +35 -35
  11. package/src/config/legacy.ts +469 -519
  12. package/src/config/migration.ts +115 -103
  13. package/src/config/notifications.ts +46 -36
  14. package/src/config/policy.ts +115 -116
  15. package/src/config/v2.ts +1128 -1167
  16. package/src/config.ts +320 -310
  17. package/src/debug.ts +238 -238
  18. package/src/deferred-tool-carryover.ts +282 -282
  19. package/src/details-store.ts +151 -151
  20. package/src/extension-runtime.ts +1095 -1919
  21. package/src/image-generation/extension.ts +189 -189
  22. package/src/image-generation/protocol.ts +579 -579
  23. package/src/image-generation/types.ts +300 -300
  24. package/src/native-fallback.ts +140 -152
  25. package/src/payload-rewrite.ts +515 -515
  26. package/src/pi-context-hook.ts +117 -117
  27. package/src/remote-v2-client.ts +811 -811
  28. package/src/request-context-cache.ts +155 -155
  29. package/src/responses-headers.ts +180 -180
  30. package/src/retired-remote-windows.ts +35 -0
  31. package/src/runtime.ts +875 -865
  32. package/src/serializer.ts +882 -882
  33. package/src/supported-environment.ts +27 -27
  34. package/src/types.ts +541 -565
  35. package/src/web-search/alpha-client.ts +876 -876
  36. package/src/web-search/extension.ts +530 -530
  37. package/src/web-search/payload.ts +299 -299
  38. package/src/web-search/prompt.ts +60 -60
  39. package/src/web-search/types.ts +166 -166
  40. package/tsconfig.check.json +50 -50
  41. package/src/context-management/codex-provider.ts +0 -270
  42. package/src/context-management/history-notes.ts +0 -357
  43. package/src/context-management/manual-compact.ts +0 -247
  44. package/src/context-management/messages.ts +0 -238
  45. package/src/context-management/namespace-tools.ts +0 -426
  46. package/src/context-management/responses-tools.ts +0 -238
  47. package/src/context-management/scoped-compaction.ts +0 -89
  48. package/src/context-management/tool-contract.ts +0 -62
  49. package/src/context-management/tools.ts +0 -371
  50. package/src/context-management/types.ts +0 -168
  51. package/src/context-management/window-budget.ts +0 -83
  52. package/src/context-management/window-bulk.ts +0 -155
  53. package/src/context-management/window-manager.ts +0 -912
  54. package/src/context-management/window-request.ts +0 -125
@@ -1,282 +1,282 @@
1
- import type { ResponsesCompatibleRequestPayload } from "./runtime";
2
- import { isDeferredToolCarryover, type DeferredToolCarryoverV1 } from "./types";
3
- import { LOCAL_WEB_SEARCH_TOOL_NAME, WEB_RUN_TOOL_NAME } from "./web-search/types";
4
-
5
- type JsonObject = Record<string, unknown>;
6
-
7
- type DeferredToolCompat = {
8
- supportsAdditionalTools?: boolean;
9
- supportsToolSearch?: boolean;
10
- };
11
-
12
- export type DeferredToolCarryoverMode = "additional-tools" | "tool-search";
13
-
14
- export type DeferredToolCarryoverRewrite = {
15
- payload: ResponsesCompatibleRequestPayload;
16
- changed: boolean;
17
- mode?: DeferredToolCarryoverMode;
18
- movedToolNames: string[];
19
- };
20
-
21
- function isRecord(value: unknown): value is JsonObject {
22
- return !!value && typeof value === "object" && !Array.isArray(value);
23
- }
24
-
25
- function getDeferredToolName(value: unknown): string | undefined {
26
- if (!isRecord(value) || (value.type !== "function" && value.type !== "custom")) {
27
- return undefined;
28
- }
29
-
30
- return typeof value.name === "string" && value.name.trim().length > 0 ? value.name : undefined;
31
- }
32
-
33
- function hasOptionalBooleanField(value: JsonObject, field: string): boolean {
34
- return value[field] === undefined || typeof value[field] === "boolean";
35
- }
36
-
37
- function hasOptionalBooleanOrNullField(value: JsonObject, field: string): boolean {
38
- return value[field] === undefined || value[field] === null || typeof value[field] === "boolean";
39
- }
40
-
41
- function isCustomToolFormat(value: unknown): boolean {
42
- if (!isRecord(value)) return false;
43
- if (value.type === "text") return true;
44
- return (
45
- value.type === "grammar" &&
46
- (value.syntax === "lark" || value.syntax === "regex") &&
47
- typeof value.definition === "string"
48
- );
49
- }
50
-
51
- /** Validate only the provider-facing function/custom shapes emitted by official Pi. */
52
- function isDeferredToolSchema(value: unknown): value is JsonObject {
53
- const name = getDeferredToolName(value);
54
- if (!name || !isRecord(value)) return false;
55
-
56
- if (value.type === "function") {
57
- return (
58
- "parameters" in value &&
59
- (value.parameters === null || isRecord(value.parameters)) &&
60
- hasOptionalBooleanOrNullField(value, "strict") &&
61
- hasOptionalBooleanField(value, "defer_loading") &&
62
- (value.description === undefined || value.description === null || typeof value.description === "string")
63
- );
64
- }
65
-
66
- return (
67
- hasOptionalBooleanField(value, "defer_loading") &&
68
- (value.description === undefined || typeof value.description === "string") &&
69
- (value.format === undefined || isCustomToolFormat(value.format))
70
- );
71
- }
72
-
73
- function addLoadedToolSchemas(tools: unknown, loaded: Set<string>): boolean {
74
- if (!Array.isArray(tools)) return false;
75
- for (const tool of tools) {
76
- const name = getDeferredToolName(tool);
77
- if (!name || !isDeferredToolSchema(tool)) return false;
78
- loaded.add(name);
79
- }
80
- return true;
81
- }
82
-
83
- function isCompletedClientToolSearchCall(value: JsonObject): value is JsonObject & { call_id: string } {
84
- if (
85
- value.type !== "tool_search_call" ||
86
- typeof value.call_id !== "string" ||
87
- value.call_id.length === 0 ||
88
- value.execution !== "client" ||
89
- value.status !== "completed" ||
90
- !isRecord(value.arguments)
91
- ) {
92
- return false;
93
- }
94
-
95
- return (
96
- typeof value.arguments.query === "string" &&
97
- typeof value.arguments.limit === "number" &&
98
- Number.isInteger(value.arguments.limit) &&
99
- value.arguments.limit >= 0
100
- );
101
- }
102
-
103
- function collectLoadedToolNames(input: readonly unknown[], startIndex: number): Set<string> | undefined {
104
- const loaded = new Set<string>();
105
-
106
- for (let index = startIndex; index < input.length; index += 1) {
107
- const item = input[index];
108
- if (!isRecord(item)) continue;
109
-
110
- if (item.type === "additional_tools") {
111
- if (item.role !== "developer" || !addLoadedToolSchemas(item.tools, loaded)) return undefined;
112
- continue;
113
- }
114
-
115
- if (item.type === "tool_search_call") {
116
- if (!isCompletedClientToolSearchCall(item)) return undefined;
117
- const output = input[index + 1];
118
- if (
119
- !isRecord(output) ||
120
- output.type !== "tool_search_output" ||
121
- output.call_id !== item.call_id ||
122
- output.execution !== "client" ||
123
- output.status !== "completed" ||
124
- !addLoadedToolSchemas(output.tools, loaded)
125
- ) {
126
- return undefined;
127
- }
128
- index += 1;
129
- continue;
130
- }
131
-
132
- if (item.type === "tool_search_output") return undefined;
133
- }
134
-
135
- return loaded;
136
- }
137
-
138
- function createToolSearchCallId(compactionEntryId: string, names: readonly string[]): string {
139
- let hash = 2166136261;
140
- for (const value of `${compactionEntryId}\u0000${names.join("\u0000")}`) {
141
- hash ^= value.codePointAt(0) ?? 0;
142
- hash = Math.imul(hash, 16777619);
143
- }
144
- return `pi_tool_load_${(hash >>> 0).toString(16).padStart(8, "0")}`;
145
- }
146
-
147
- function cloneTool(value: JsonObject): JsonObject | undefined {
148
- try {
149
- return structuredClone(value);
150
- } catch {
151
- return undefined;
152
- }
153
- }
154
-
155
- function selectMode(compat: DeferredToolCompat | undefined): DeferredToolCarryoverMode | undefined {
156
- if (compat?.supportsAdditionalTools === true) return "additional-tools";
157
- if (compat?.supportsToolSearch === true) return "tool-search";
158
- return undefined;
159
- }
160
-
161
- function createLoadPoint(
162
- mode: DeferredToolCarryoverMode,
163
- compactionEntryId: string,
164
- schemas: readonly JsonObject[],
165
- ): JsonObject[] | undefined {
166
- const clonedSchemas: JsonObject[] = [];
167
- for (const schema of schemas) {
168
- const clone = cloneTool(schema);
169
- if (!clone) return undefined;
170
- if (mode === "tool-search") clone.defer_loading = true;
171
- clonedSchemas.push(clone);
172
- }
173
-
174
- if (mode === "additional-tools") {
175
- return [{ type: "additional_tools", role: "developer", tools: clonedSchemas }];
176
- }
177
-
178
- const names = clonedSchemas.map((schema) => getDeferredToolName(schema));
179
- if (names.some((name): name is undefined => name === undefined)) return undefined;
180
- const callId = createToolSearchCallId(compactionEntryId, names as string[]);
181
- return [
182
- {
183
- type: "tool_search_call",
184
- call_id: callId,
185
- execution: "client",
186
- status: "completed",
187
- arguments: { query: (names as string[]).join(" "), limit: names.length },
188
- },
189
- {
190
- type: "tool_search_output",
191
- call_id: callId,
192
- execution: "client",
193
- status: "completed",
194
- tools: clonedSchemas,
195
- },
196
- ];
197
- }
198
-
199
- /**
200
- * Restore cache-stack's activated function/custom schemas after an opaque
201
- * compaction checkpoint. This is deliberately fail-open: malformed state or
202
- * payloads leave the provider request untouched so Pi keeps its immediate-tool
203
- * fallback behavior.
204
- */
205
- export function rewritePayloadWithDeferredToolCarryover(args: {
206
- payload: ResponsesCompatibleRequestPayload;
207
- carryover?: DeferredToolCarryoverV1;
208
- compactionEntryId: string;
209
- checkpointEndIndex: number;
210
- compat?: DeferredToolCompat;
211
- }): DeferredToolCarryoverRewrite {
212
- const unchanged: DeferredToolCarryoverRewrite = {
213
- payload: args.payload,
214
- changed: false,
215
- movedToolNames: [],
216
- };
217
-
218
- const mode = selectMode(args.compat);
219
- if (!mode || !args.carryover || !isDeferredToolCarryover(args.carryover) || !Array.isArray(args.payload.input)) {
220
- return unchanged;
221
- }
222
- if (!Number.isInteger(args.checkpointEndIndex) || args.checkpointEndIndex < 0 || args.checkpointEndIndex > args.payload.input.length) {
223
- return unchanged;
224
- }
225
- if (!Array.isArray(args.payload.tools)) return unchanged;
226
-
227
- // Search routing needs its local callable at the top level on every request.
228
- const carryoverNames = new Set(
229
- args.carryover.toolNames
230
- .map((name) => name.trim())
231
- .filter((name) => name.length > 0 && name !== LOCAL_WEB_SEARCH_TOOL_NAME && name !== WEB_RUN_TOOL_NAME),
232
- );
233
- if (carryoverNames.size === 0) return unchanged;
234
-
235
- const schemasByName = new Map<string, JsonObject>();
236
- const duplicateNames = new Set<string>();
237
- for (const tool of args.payload.tools) {
238
- const name = getDeferredToolName(tool);
239
- if (!name || !carryoverNames.has(name)) continue;
240
- if (!isDeferredToolSchema(tool)) return unchanged;
241
- const schema = tool;
242
- if (schemasByName.has(name)) {
243
- duplicateNames.add(name);
244
- continue;
245
- }
246
- schemasByName.set(name, schema);
247
- }
248
- for (const name of duplicateNames) schemasByName.delete(name);
249
- if (schemasByName.size === 0) return unchanged;
250
-
251
- const loadedNames = collectLoadedToolNames(args.payload.input, args.checkpointEndIndex);
252
- if (!loadedNames) return unchanged;
253
- const matchingNames = [...schemasByName.keys()];
254
- const movedNames = matchingNames.filter((name) => !loadedNames.has(name));
255
- const matchingNameSet = new Set(matchingNames);
256
- const nextTools = args.payload.tools.filter((tool) => {
257
- const name = getDeferredToolName(tool);
258
- return !name || !matchingNameSet.has(name);
259
- });
260
- const toolsChanged = nextTools.length !== args.payload.tools.length;
261
- if (movedNames.length === 0 && !toolsChanged) return unchanged;
262
-
263
- const nextInput = [...args.payload.input];
264
- if (movedNames.length > 0) {
265
- const schemas = movedNames.map((name) => schemasByName.get(name));
266
- if (schemas.some((schema): schema is undefined => schema === undefined)) return unchanged;
267
- const loadPoint = createLoadPoint(mode, args.compactionEntryId, schemas as JsonObject[]);
268
- if (!loadPoint) return unchanged;
269
- nextInput.splice(args.checkpointEndIndex, 0, ...loadPoint);
270
- }
271
-
272
- return {
273
- payload: {
274
- ...args.payload,
275
- tools: nextTools,
276
- input: nextInput,
277
- },
278
- changed: true,
279
- mode,
280
- movedToolNames: movedNames,
281
- };
282
- }
1
+ import type { ResponsesCompatibleRequestPayload } from "./runtime";
2
+ import { isDeferredToolCarryover, type DeferredToolCarryoverV1 } from "./types";
3
+ import { LOCAL_WEB_SEARCH_TOOL_NAME, WEB_RUN_TOOL_NAME } from "./web-search/types";
4
+
5
+ type JsonObject = Record<string, unknown>;
6
+
7
+ type DeferredToolCompat = {
8
+ supportsAdditionalTools?: boolean;
9
+ supportsToolSearch?: boolean;
10
+ };
11
+
12
+ export type DeferredToolCarryoverMode = "additional-tools" | "tool-search";
13
+
14
+ export type DeferredToolCarryoverRewrite = {
15
+ payload: ResponsesCompatibleRequestPayload;
16
+ changed: boolean;
17
+ mode?: DeferredToolCarryoverMode;
18
+ movedToolNames: string[];
19
+ };
20
+
21
+ function isRecord(value: unknown): value is JsonObject {
22
+ return !!value && typeof value === "object" && !Array.isArray(value);
23
+ }
24
+
25
+ function getDeferredToolName(value: unknown): string | undefined {
26
+ if (!isRecord(value) || (value.type !== "function" && value.type !== "custom")) {
27
+ return undefined;
28
+ }
29
+
30
+ return typeof value.name === "string" && value.name.trim().length > 0 ? value.name : undefined;
31
+ }
32
+
33
+ function hasOptionalBooleanField(value: JsonObject, field: string): boolean {
34
+ return value[field] === undefined || typeof value[field] === "boolean";
35
+ }
36
+
37
+ function hasOptionalBooleanOrNullField(value: JsonObject, field: string): boolean {
38
+ return value[field] === undefined || value[field] === null || typeof value[field] === "boolean";
39
+ }
40
+
41
+ function isCustomToolFormat(value: unknown): boolean {
42
+ if (!isRecord(value)) return false;
43
+ if (value.type === "text") return true;
44
+ return (
45
+ value.type === "grammar" &&
46
+ (value.syntax === "lark" || value.syntax === "regex") &&
47
+ typeof value.definition === "string"
48
+ );
49
+ }
50
+
51
+ /** Validate only the provider-facing function/custom shapes emitted by official Pi. */
52
+ function isDeferredToolSchema(value: unknown): value is JsonObject {
53
+ const name = getDeferredToolName(value);
54
+ if (!name || !isRecord(value)) return false;
55
+
56
+ if (value.type === "function") {
57
+ return (
58
+ "parameters" in value &&
59
+ (value.parameters === null || isRecord(value.parameters)) &&
60
+ hasOptionalBooleanOrNullField(value, "strict") &&
61
+ hasOptionalBooleanField(value, "defer_loading") &&
62
+ (value.description === undefined || value.description === null || typeof value.description === "string")
63
+ );
64
+ }
65
+
66
+ return (
67
+ hasOptionalBooleanField(value, "defer_loading") &&
68
+ (value.description === undefined || typeof value.description === "string") &&
69
+ (value.format === undefined || isCustomToolFormat(value.format))
70
+ );
71
+ }
72
+
73
+ function addLoadedToolSchemas(tools: unknown, loaded: Set<string>): boolean {
74
+ if (!Array.isArray(tools)) return false;
75
+ for (const tool of tools) {
76
+ const name = getDeferredToolName(tool);
77
+ if (!name || !isDeferredToolSchema(tool)) return false;
78
+ loaded.add(name);
79
+ }
80
+ return true;
81
+ }
82
+
83
+ function isCompletedClientToolSearchCall(value: JsonObject): value is JsonObject & { call_id: string } {
84
+ if (
85
+ value.type !== "tool_search_call" ||
86
+ typeof value.call_id !== "string" ||
87
+ value.call_id.length === 0 ||
88
+ value.execution !== "client" ||
89
+ value.status !== "completed" ||
90
+ !isRecord(value.arguments)
91
+ ) {
92
+ return false;
93
+ }
94
+
95
+ return (
96
+ typeof value.arguments.query === "string" &&
97
+ typeof value.arguments.limit === "number" &&
98
+ Number.isInteger(value.arguments.limit) &&
99
+ value.arguments.limit >= 0
100
+ );
101
+ }
102
+
103
+ function collectLoadedToolNames(input: readonly unknown[], startIndex: number): Set<string> | undefined {
104
+ const loaded = new Set<string>();
105
+
106
+ for (let index = startIndex; index < input.length; index += 1) {
107
+ const item = input[index];
108
+ if (!isRecord(item)) continue;
109
+
110
+ if (item.type === "additional_tools") {
111
+ if (item.role !== "developer" || !addLoadedToolSchemas(item.tools, loaded)) return undefined;
112
+ continue;
113
+ }
114
+
115
+ if (item.type === "tool_search_call") {
116
+ if (!isCompletedClientToolSearchCall(item)) return undefined;
117
+ const output = input[index + 1];
118
+ if (
119
+ !isRecord(output) ||
120
+ output.type !== "tool_search_output" ||
121
+ output.call_id !== item.call_id ||
122
+ output.execution !== "client" ||
123
+ output.status !== "completed" ||
124
+ !addLoadedToolSchemas(output.tools, loaded)
125
+ ) {
126
+ return undefined;
127
+ }
128
+ index += 1;
129
+ continue;
130
+ }
131
+
132
+ if (item.type === "tool_search_output") return undefined;
133
+ }
134
+
135
+ return loaded;
136
+ }
137
+
138
+ function createToolSearchCallId(compactionEntryId: string, names: readonly string[]): string {
139
+ let hash = 2166136261;
140
+ for (const value of `${compactionEntryId}\u0000${names.join("\u0000")}`) {
141
+ hash ^= value.codePointAt(0) ?? 0;
142
+ hash = Math.imul(hash, 16777619);
143
+ }
144
+ return `pi_tool_load_${(hash >>> 0).toString(16).padStart(8, "0")}`;
145
+ }
146
+
147
+ function cloneTool(value: JsonObject): JsonObject | undefined {
148
+ try {
149
+ return structuredClone(value);
150
+ } catch {
151
+ return undefined;
152
+ }
153
+ }
154
+
155
+ function selectMode(compat: DeferredToolCompat | undefined): DeferredToolCarryoverMode | undefined {
156
+ if (compat?.supportsAdditionalTools === true) return "additional-tools";
157
+ if (compat?.supportsToolSearch === true) return "tool-search";
158
+ return undefined;
159
+ }
160
+
161
+ function createLoadPoint(
162
+ mode: DeferredToolCarryoverMode,
163
+ compactionEntryId: string,
164
+ schemas: readonly JsonObject[],
165
+ ): JsonObject[] | undefined {
166
+ const clonedSchemas: JsonObject[] = [];
167
+ for (const schema of schemas) {
168
+ const clone = cloneTool(schema);
169
+ if (!clone) return undefined;
170
+ if (mode === "tool-search") clone.defer_loading = true;
171
+ clonedSchemas.push(clone);
172
+ }
173
+
174
+ if (mode === "additional-tools") {
175
+ return [{ type: "additional_tools", role: "developer", tools: clonedSchemas }];
176
+ }
177
+
178
+ const names = clonedSchemas.map((schema) => getDeferredToolName(schema));
179
+ if (names.some((name): name is undefined => name === undefined)) return undefined;
180
+ const callId = createToolSearchCallId(compactionEntryId, names as string[]);
181
+ return [
182
+ {
183
+ type: "tool_search_call",
184
+ call_id: callId,
185
+ execution: "client",
186
+ status: "completed",
187
+ arguments: { query: (names as string[]).join(" "), limit: names.length },
188
+ },
189
+ {
190
+ type: "tool_search_output",
191
+ call_id: callId,
192
+ execution: "client",
193
+ status: "completed",
194
+ tools: clonedSchemas,
195
+ },
196
+ ];
197
+ }
198
+
199
+ /**
200
+ * Restore cache-stack's activated function/custom schemas after an opaque
201
+ * compaction checkpoint. This is deliberately fail-open: malformed state or
202
+ * payloads leave the provider request untouched so Pi keeps its immediate-tool
203
+ * fallback behavior.
204
+ */
205
+ export function rewritePayloadWithDeferredToolCarryover(args: {
206
+ payload: ResponsesCompatibleRequestPayload;
207
+ carryover?: DeferredToolCarryoverV1;
208
+ compactionEntryId: string;
209
+ checkpointEndIndex: number;
210
+ compat?: DeferredToolCompat;
211
+ }): DeferredToolCarryoverRewrite {
212
+ const unchanged: DeferredToolCarryoverRewrite = {
213
+ payload: args.payload,
214
+ changed: false,
215
+ movedToolNames: [],
216
+ };
217
+
218
+ const mode = selectMode(args.compat);
219
+ if (!mode || !args.carryover || !isDeferredToolCarryover(args.carryover) || !Array.isArray(args.payload.input)) {
220
+ return unchanged;
221
+ }
222
+ if (!Number.isInteger(args.checkpointEndIndex) || args.checkpointEndIndex < 0 || args.checkpointEndIndex > args.payload.input.length) {
223
+ return unchanged;
224
+ }
225
+ if (!Array.isArray(args.payload.tools)) return unchanged;
226
+
227
+ // Search routing needs its local callable at the top level on every request.
228
+ const carryoverNames = new Set(
229
+ args.carryover.toolNames
230
+ .map((name) => name.trim())
231
+ .filter((name) => name.length > 0 && name !== LOCAL_WEB_SEARCH_TOOL_NAME && name !== WEB_RUN_TOOL_NAME),
232
+ );
233
+ if (carryoverNames.size === 0) return unchanged;
234
+
235
+ const schemasByName = new Map<string, JsonObject>();
236
+ const duplicateNames = new Set<string>();
237
+ for (const tool of args.payload.tools) {
238
+ const name = getDeferredToolName(tool);
239
+ if (!name || !carryoverNames.has(name)) continue;
240
+ if (!isDeferredToolSchema(tool)) return unchanged;
241
+ const schema = tool;
242
+ if (schemasByName.has(name)) {
243
+ duplicateNames.add(name);
244
+ continue;
245
+ }
246
+ schemasByName.set(name, schema);
247
+ }
248
+ for (const name of duplicateNames) schemasByName.delete(name);
249
+ if (schemasByName.size === 0) return unchanged;
250
+
251
+ const loadedNames = collectLoadedToolNames(args.payload.input, args.checkpointEndIndex);
252
+ if (!loadedNames) return unchanged;
253
+ const matchingNames = [...schemasByName.keys()];
254
+ const movedNames = matchingNames.filter((name) => !loadedNames.has(name));
255
+ const matchingNameSet = new Set(matchingNames);
256
+ const nextTools = args.payload.tools.filter((tool) => {
257
+ const name = getDeferredToolName(tool);
258
+ return !name || !matchingNameSet.has(name);
259
+ });
260
+ const toolsChanged = nextTools.length !== args.payload.tools.length;
261
+ if (movedNames.length === 0 && !toolsChanged) return unchanged;
262
+
263
+ const nextInput = [...args.payload.input];
264
+ if (movedNames.length > 0) {
265
+ const schemas = movedNames.map((name) => schemasByName.get(name));
266
+ if (schemas.some((schema): schema is undefined => schema === undefined)) return unchanged;
267
+ const loadPoint = createLoadPoint(mode, args.compactionEntryId, schemas as JsonObject[]);
268
+ if (!loadPoint) return unchanged;
269
+ nextInput.splice(args.checkpointEndIndex, 0, ...loadPoint);
270
+ }
271
+
272
+ return {
273
+ payload: {
274
+ ...args.payload,
275
+ tools: nextTools,
276
+ input: nextInput,
277
+ },
278
+ changed: true,
279
+ mode,
280
+ movedToolNames: movedNames,
281
+ };
282
+ }