pi-openai-toolkit 0.14.13 → 0.15.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.
- package/README.md +250 -241
- package/README.zh.md +250 -241
- package/config.schema.json +352 -0
- package/docs/configuration.md +176 -0
- package/docs/internals.md +139 -128
- package/package.json +135 -127
- package/src/auto-mode/extension.ts +35 -13
- package/src/config/legacy.ts +717 -0
- package/src/config/migration.ts +100 -0
- package/src/config/notifications.ts +28 -0
- package/src/config/policy.ts +122 -0
- package/src/config/v2.ts +1347 -0
- package/src/config-command.ts +73 -0
- package/src/config.ts +318 -739
- package/src/context-management/tools.ts +353 -347
- package/src/context-management/window-manager.ts +696 -693
- package/src/debug.ts +5 -5
- package/src/deferred-tool-carryover.ts +3 -1
- package/src/extension-runtime.ts +1375 -1329
- package/src/image-generation/extension.ts +14 -18
- package/src/image-generation/protocol.ts +10 -4
- package/src/image-generation/service.ts +9 -3
- package/src/request-context-cache.ts +2 -1
- package/src/types.ts +641 -628
- package/src/web-search/alpha-client.ts +876 -875
- package/src/web-search/extension.ts +529 -523
- package/src/web-search/payload.ts +299 -295
- package/src/web-search/prompt.ts +60 -59
- package/src/web-search/types.ts +144 -144
|
@@ -1,295 +1,299 @@
|
|
|
1
|
-
import type { WebSearchConfig } from "../types";
|
|
2
|
-
import {
|
|
3
|
-
LOCAL_WEB_SEARCH_TOOL_NAME,
|
|
4
|
-
resolveWebSearchRoute,
|
|
5
|
-
WEB_RUN_TOOL_NAME,
|
|
6
|
-
WEB_SEARCH_SOURCE_INCLUDE,
|
|
7
|
-
isWebSearchRoute,
|
|
8
|
-
type WebSearchModel,
|
|
9
|
-
type WebSearchPayloadTransform,
|
|
10
|
-
} from "./types";
|
|
11
|
-
|
|
12
|
-
type JsonObject = Record<string, unknown>;
|
|
13
|
-
|
|
14
|
-
function isRecord(value: unknown): value is JsonObject {
|
|
15
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function isLocalWebSearchFunction(tool: unknown): boolean {
|
|
19
|
-
return isRecord(tool) && tool.type === "function" && tool.name === LOCAL_WEB_SEARCH_TOOL_NAME;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function isStandaloneWebRunFunction(tool: unknown): boolean {
|
|
23
|
-
return isRecord(tool) && tool.type === "function" && tool.name === WEB_RUN_TOOL_NAME;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function isNativeWebSearchTool(tool: unknown): boolean {
|
|
27
|
-
return isRecord(tool) && (tool.type === "web_search" || tool.type === "web_search_preview");
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function explicitRouteFailure(resolution: ReturnType<typeof resolveWebSearchRoute>): WebSearchPayloadTransform {
|
|
31
|
-
const reason = resolution.route === "none" ? resolution.reason : resolution.reason;
|
|
32
|
-
return {
|
|
33
|
-
payload: undefined,
|
|
34
|
-
outcome: "unavailable-route",
|
|
35
|
-
changed: false,
|
|
36
|
-
fatal: true,
|
|
37
|
-
errorMessage: `Web Search route is unavailable${reason ? ` (${reason})` : ""}; request aborted without fallback.`,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function unavailableRouteTransform(
|
|
42
|
-
payload: unknown,
|
|
43
|
-
resolution: ReturnType<typeof resolveWebSearchRoute>,
|
|
44
|
-
): WebSearchPayloadTransform {
|
|
45
|
-
const base = explicitRouteFailure(resolution);
|
|
46
|
-
return { ...base, payload };
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function transformStandalonePayload(args: {
|
|
50
|
-
payload: JsonObject;
|
|
51
|
-
resolution: ReturnType<typeof resolveWebSearchRoute>;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
...
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
...
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if (
|
|
246
|
-
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
normalizedTools.push(
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
payload:
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
1
|
+
import type { WebSearchConfig } from "../types";
|
|
2
|
+
import {
|
|
3
|
+
LOCAL_WEB_SEARCH_TOOL_NAME,
|
|
4
|
+
resolveWebSearchRoute,
|
|
5
|
+
WEB_RUN_TOOL_NAME,
|
|
6
|
+
WEB_SEARCH_SOURCE_INCLUDE,
|
|
7
|
+
isWebSearchRoute,
|
|
8
|
+
type WebSearchModel,
|
|
9
|
+
type WebSearchPayloadTransform,
|
|
10
|
+
} from "./types";
|
|
11
|
+
|
|
12
|
+
type JsonObject = Record<string, unknown>;
|
|
13
|
+
|
|
14
|
+
function isRecord(value: unknown): value is JsonObject {
|
|
15
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function isLocalWebSearchFunction(tool: unknown): boolean {
|
|
19
|
+
return isRecord(tool) && tool.type === "function" && tool.name === LOCAL_WEB_SEARCH_TOOL_NAME;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function isStandaloneWebRunFunction(tool: unknown): boolean {
|
|
23
|
+
return isRecord(tool) && tool.type === "function" && tool.name === WEB_RUN_TOOL_NAME;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isNativeWebSearchTool(tool: unknown): boolean {
|
|
27
|
+
return isRecord(tool) && (tool.type === "web_search" || tool.type === "web_search_preview");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function explicitRouteFailure(resolution: ReturnType<typeof resolveWebSearchRoute>): WebSearchPayloadTransform {
|
|
31
|
+
const reason = resolution.route === "none" ? resolution.reason : resolution.reason;
|
|
32
|
+
return {
|
|
33
|
+
payload: undefined,
|
|
34
|
+
outcome: "unavailable-route",
|
|
35
|
+
changed: false,
|
|
36
|
+
fatal: true,
|
|
37
|
+
errorMessage: `Web Search route is unavailable${reason ? ` (${reason})` : ""}; request aborted without fallback.`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function unavailableRouteTransform(
|
|
42
|
+
payload: unknown,
|
|
43
|
+
resolution: ReturnType<typeof resolveWebSearchRoute>,
|
|
44
|
+
): WebSearchPayloadTransform {
|
|
45
|
+
const base = explicitRouteFailure(resolution);
|
|
46
|
+
return { ...base, payload };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function transformStandalonePayload(args: {
|
|
50
|
+
payload: JsonObject;
|
|
51
|
+
resolution: ReturnType<typeof resolveWebSearchRoute>;
|
|
52
|
+
standaloneToolExcluded?: boolean;
|
|
53
|
+
}): WebSearchPayloadTransform {
|
|
54
|
+
const { payload, resolution, standaloneToolExcluded = false } = args;
|
|
55
|
+
const toolsValue = payload.tools;
|
|
56
|
+
if (toolsValue !== undefined && !Array.isArray(toolsValue)) {
|
|
57
|
+
return {
|
|
58
|
+
payload,
|
|
59
|
+
outcome: "invalid-tools",
|
|
60
|
+
changed: false,
|
|
61
|
+
fatal: resolution.source !== "legacy",
|
|
62
|
+
errorMessage: "Standalone Web Search requires a provider payload tools array.",
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
const includeValue = payload.include;
|
|
66
|
+
if (includeValue !== undefined && !Array.isArray(includeValue)) {
|
|
67
|
+
return {
|
|
68
|
+
payload,
|
|
69
|
+
outcome: "invalid-include",
|
|
70
|
+
changed: false,
|
|
71
|
+
fatal: resolution.source !== "legacy",
|
|
72
|
+
errorMessage: "Standalone Web Search requires a provider payload include array.",
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const tools = toolsValue ?? [];
|
|
77
|
+
let standaloneToolCount = 0;
|
|
78
|
+
const normalizedTools = tools.filter((tool) => {
|
|
79
|
+
if (isLocalWebSearchFunction(tool) || isNativeWebSearchTool(tool)) return false;
|
|
80
|
+
if (!isStandaloneWebRunFunction(tool)) return true;
|
|
81
|
+
if (standaloneToolExcluded) return false;
|
|
82
|
+
standaloneToolCount += 1;
|
|
83
|
+
return standaloneToolCount === 1;
|
|
84
|
+
});
|
|
85
|
+
const include = includeValue ?? [];
|
|
86
|
+
const normalizedInclude = include.filter((item) => item !== WEB_SEARCH_SOURCE_INCLUDE);
|
|
87
|
+
const toolsChanged = normalizedTools.length !== tools.length;
|
|
88
|
+
const includeChanged = normalizedInclude.length !== include.length;
|
|
89
|
+
if (!standaloneToolExcluded && toolsValue !== undefined && !normalizedTools.some(isStandaloneWebRunFunction)) {
|
|
90
|
+
return {
|
|
91
|
+
payload,
|
|
92
|
+
outcome: "unavailable-route",
|
|
93
|
+
changed: false,
|
|
94
|
+
fatal: resolution.source !== "legacy",
|
|
95
|
+
errorMessage: `Standalone Web Search requires the registered ${WEB_RUN_TOOL_NAME} tool in the provider payload.`,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
if (!toolsChanged && !includeChanged) {
|
|
99
|
+
return { payload, outcome: "standalone-route", changed: false };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return {
|
|
103
|
+
payload: {
|
|
104
|
+
...payload,
|
|
105
|
+
...(toolsChanged ? { tools: normalizedTools } : {}),
|
|
106
|
+
...(includeChanged ? { include: normalizedInclude } : {}),
|
|
107
|
+
},
|
|
108
|
+
outcome: "removed-conflicting-tools",
|
|
109
|
+
changed: true,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function transformLocalPayload(args: {
|
|
114
|
+
payload: JsonObject;
|
|
115
|
+
resolution: ReturnType<typeof resolveWebSearchRoute>;
|
|
116
|
+
}): WebSearchPayloadTransform {
|
|
117
|
+
const { payload, resolution } = args;
|
|
118
|
+
const toolsValue = payload.tools;
|
|
119
|
+
if (toolsValue !== undefined && !Array.isArray(toolsValue)) {
|
|
120
|
+
return {
|
|
121
|
+
payload,
|
|
122
|
+
outcome: "invalid-tools",
|
|
123
|
+
changed: false,
|
|
124
|
+
fatal: resolution.source !== "legacy",
|
|
125
|
+
errorMessage: "Local Web Search requires a provider payload tools array.",
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
const includeValue = payload.include;
|
|
129
|
+
if (includeValue !== undefined && !Array.isArray(includeValue)) {
|
|
130
|
+
return {
|
|
131
|
+
payload,
|
|
132
|
+
outcome: "invalid-include",
|
|
133
|
+
changed: false,
|
|
134
|
+
fatal: resolution.source !== "legacy",
|
|
135
|
+
errorMessage: "Local Web Search requires a provider payload include array.",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const tools = toolsValue ?? [];
|
|
140
|
+
const normalizedTools = tools.filter(
|
|
141
|
+
(tool) => !isStandaloneWebRunFunction(tool) && !isNativeWebSearchTool(tool),
|
|
142
|
+
);
|
|
143
|
+
const include = includeValue ?? [];
|
|
144
|
+
const normalizedInclude = include.filter((item) => item !== WEB_SEARCH_SOURCE_INCLUDE);
|
|
145
|
+
const toolsChanged = normalizedTools.length !== tools.length;
|
|
146
|
+
const includeChanged = normalizedInclude.length !== include.length;
|
|
147
|
+
if (!toolsChanged && !includeChanged) return { payload, outcome: "local-route", changed: false };
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
payload: {
|
|
151
|
+
...payload,
|
|
152
|
+
...(toolsChanged ? { tools: normalizedTools } : {}),
|
|
153
|
+
...(includeChanged ? { include: normalizedInclude } : {}),
|
|
154
|
+
},
|
|
155
|
+
outcome: "removed-conflicting-tools",
|
|
156
|
+
changed: true,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function transformWebSearchPayload(args: {
|
|
161
|
+
model: WebSearchModel | undefined;
|
|
162
|
+
config: WebSearchConfig;
|
|
163
|
+
payload: unknown;
|
|
164
|
+
/** The host filtered a successfully registered web_run out of this session's tool catalog. */
|
|
165
|
+
standaloneToolExcluded?: boolean;
|
|
166
|
+
}): WebSearchPayloadTransform {
|
|
167
|
+
const { model, config, payload } = args;
|
|
168
|
+
const resolution = resolveWebSearchRoute({ model, config });
|
|
169
|
+
|
|
170
|
+
if (resolution.route === "none") {
|
|
171
|
+
return {
|
|
172
|
+
payload,
|
|
173
|
+
outcome: resolution.reason === "disabled" ? "disabled" : "unsupported-model",
|
|
174
|
+
changed: false,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (!resolution.available) {
|
|
178
|
+
return unavailableRouteTransform(payload, resolution);
|
|
179
|
+
}
|
|
180
|
+
if (resolution.route === "local") {
|
|
181
|
+
if (!isRecord(payload)) {
|
|
182
|
+
return {
|
|
183
|
+
payload,
|
|
184
|
+
outcome: "non-object-payload",
|
|
185
|
+
changed: false,
|
|
186
|
+
fatal: resolution.source !== "legacy",
|
|
187
|
+
errorMessage: "Local Web Search requires an object provider payload.",
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
return transformLocalPayload({ payload, resolution });
|
|
191
|
+
}
|
|
192
|
+
if (resolution.route === "standalone-alpha") {
|
|
193
|
+
if (!isRecord(payload)) {
|
|
194
|
+
return {
|
|
195
|
+
payload,
|
|
196
|
+
outcome: "non-object-payload",
|
|
197
|
+
changed: false,
|
|
198
|
+
fatal: resolution.source !== "legacy",
|
|
199
|
+
errorMessage: "Standalone Web Search requires an object provider payload.",
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
return transformStandalonePayload({ payload, resolution, standaloneToolExcluded: args.standaloneToolExcluded });
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
if (!isRecord(payload)) {
|
|
206
|
+
return {
|
|
207
|
+
payload,
|
|
208
|
+
outcome: "non-object-payload",
|
|
209
|
+
changed: false,
|
|
210
|
+
...(resolution.source !== "legacy"
|
|
211
|
+
? { fatal: true, errorMessage: "Hosted Web Search requires an object provider payload." }
|
|
212
|
+
: {}),
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const toolsValue = payload.tools;
|
|
217
|
+
if (toolsValue !== undefined && !Array.isArray(toolsValue)) {
|
|
218
|
+
return {
|
|
219
|
+
payload,
|
|
220
|
+
outcome: "invalid-tools",
|
|
221
|
+
changed: false,
|
|
222
|
+
...(resolution.source !== "legacy"
|
|
223
|
+
? { fatal: true, errorMessage: "Hosted Web Search requires a provider payload tools array." }
|
|
224
|
+
: {}),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
const tools = toolsValue ?? [];
|
|
228
|
+
const includeValue = payload.include;
|
|
229
|
+
if (includeValue !== undefined && !Array.isArray(includeValue)) {
|
|
230
|
+
return {
|
|
231
|
+
payload,
|
|
232
|
+
outcome: "invalid-include",
|
|
233
|
+
changed: false,
|
|
234
|
+
...(resolution.source !== "legacy"
|
|
235
|
+
? { fatal: true, errorMessage: "Hosted Web Search requires a provider payload include array." }
|
|
236
|
+
: {}),
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const include = includeValue ?? [];
|
|
240
|
+
const normalizedTools: unknown[] = [];
|
|
241
|
+
let nativeToolCount = 0;
|
|
242
|
+
let localToolRemoved = false;
|
|
243
|
+
let standaloneToolRemoved = false;
|
|
244
|
+
for (const tool of tools) {
|
|
245
|
+
if (isLocalWebSearchFunction(tool)) {
|
|
246
|
+
localToolRemoved = true;
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (isStandaloneWebRunFunction(tool)) {
|
|
250
|
+
standaloneToolRemoved = true;
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
if (isNativeWebSearchTool(tool)) {
|
|
254
|
+
nativeToolCount += 1;
|
|
255
|
+
if (nativeToolCount > 1) continue;
|
|
256
|
+
}
|
|
257
|
+
normalizedTools.push(tool);
|
|
258
|
+
}
|
|
259
|
+
const hasNativeTool = nativeToolCount > 0;
|
|
260
|
+
if (!hasNativeTool) {
|
|
261
|
+
normalizedTools.push({ type: "web_search" });
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const normalizedInclude: unknown[] = [];
|
|
265
|
+
let sourceIncludeCount = 0;
|
|
266
|
+
for (const item of include) {
|
|
267
|
+
if (item === WEB_SEARCH_SOURCE_INCLUDE) {
|
|
268
|
+
sourceIncludeCount += 1;
|
|
269
|
+
if (sourceIncludeCount > 1) continue;
|
|
270
|
+
}
|
|
271
|
+
normalizedInclude.push(item);
|
|
272
|
+
}
|
|
273
|
+
if (sourceIncludeCount === 0) {
|
|
274
|
+
normalizedInclude.push(WEB_SEARCH_SOURCE_INCLUDE);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
const toolsChanged = localToolRemoved || standaloneToolRemoved || !hasNativeTool || nativeToolCount > 1;
|
|
278
|
+
const includeChanged = sourceIncludeCount !== 1;
|
|
279
|
+
if (!toolsChanged && !includeChanged) {
|
|
280
|
+
return { payload, outcome: "existing-native-tool", changed: false };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
return {
|
|
284
|
+
payload: {
|
|
285
|
+
...payload,
|
|
286
|
+
...(toolsChanged ? { tools: normalizedTools } : {}),
|
|
287
|
+
...(includeChanged ? { include: normalizedInclude } : {}),
|
|
288
|
+
},
|
|
289
|
+
outcome: hasNativeTool ? "existing-native-tool" : "injected-native-tool",
|
|
290
|
+
changed: true,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export const _payloadTest = {
|
|
295
|
+
isLocalWebSearchFunction,
|
|
296
|
+
isNativeWebSearchTool,
|
|
297
|
+
isStandaloneWebRunFunction,
|
|
298
|
+
isWebSearchRoute,
|
|
299
|
+
};
|