@swifty.js/swifty 0.0.21 → 0.0.22

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 (34) hide show
  1. package/dist/{agent-ZCMBUWLZ.js → agent-5T7KNC7V.js} +1 -1
  2. package/dist/{anthropic-4ZVG7AMA.js → anthropic-P2R4GW6F.js} +1 -1
  3. package/dist/{chunk-Y5WGBAGP.js → chunk-HJIGA37J.js} +1 -1
  4. package/dist/{chunk-DDBH5AEN.js → chunk-L73IHJF4.js} +53 -53
  5. package/dist/{chunk-S6ZADC7C.js → chunk-NEAR6YPZ.js} +1 -1
  6. package/dist/{chunk-MUPVOATV.js → chunk-NLNH3IRT.js} +1 -1
  7. package/dist/{chunk-6E6UA7MT.js → chunk-YQQVB6VB.js} +9 -8
  8. package/dist/lib/agent-2AGRYN3R.js +9 -0
  9. package/dist/lib/anthropic-GFWP3ORB.js +22 -0
  10. package/dist/lib/bwrap-QRGPUP4J.js +6 -0
  11. package/dist/lib/checker-IIXJXQCB.js +19 -0
  12. package/dist/lib/chunk-6GOWRPYS.js +339 -0
  13. package/dist/lib/chunk-7URDLWQN.js +426 -0
  14. package/dist/lib/chunk-C7IHCJZ3.js +849 -0
  15. package/dist/lib/chunk-EJLGB2EJ.js +377 -0
  16. package/dist/lib/chunk-GHF2PSEW.js +8 -0
  17. package/dist/lib/chunk-GNBXECZN.js +243 -0
  18. package/dist/lib/chunk-HK2Z6WP4.js +223 -0
  19. package/dist/lib/chunk-LUEP4JMF.js +549 -0
  20. package/dist/lib/chunk-ORSYNBMM.js +38 -0
  21. package/dist/lib/chunk-RR2CZ6CY.js +598 -0
  22. package/dist/lib/chunk-UHVO63Y7.js +1246 -0
  23. package/dist/lib/chunk-UMFNTXKA.js +88 -0
  24. package/dist/lib/chunk-VUD72RTY.js +39 -0
  25. package/dist/lib/glob.wasm +0 -0
  26. package/dist/lib/index.d.ts +5350 -0
  27. package/dist/lib/index.js +12002 -0
  28. package/dist/lib/openai-HXRMPNB7.js +15 -0
  29. package/dist/lib/seatbelt-FT5IY73W.js +6 -0
  30. package/dist/lib/tool-filter-VF7TZRE5.js +19 -0
  31. package/dist/main.js +225 -225
  32. package/dist/{openai-HXD52MZB.js → openai-TVUUHRG7.js} +1 -1
  33. package/dist/{server-VMHWEO2Y.js → server-ZTLHJWEQ.js} +14 -14
  34. package/package.json +14 -2
@@ -0,0 +1,223 @@
1
+ import {
2
+ MCP_CALL_TOOL_NAME,
3
+ TOOL_SEARCH_TOOL_NAME
4
+ } from "./chunk-GHF2PSEW.js";
5
+
6
+ // src/tools/registry.ts
7
+ var ToolRegistry = class {
8
+ tools = /* @__PURE__ */ new Map();
9
+ discovered = /* @__PURE__ */ new Set();
10
+ /**
11
+ * How MCP tools are loaded, written by mcp/strategy after connecting to the
12
+ * server. ToolSearch relies on it to decide what to return, and the client
13
+ * relies on it to decide whether to send defer_loading. It stays eager when
14
+ * there is no MCP, which behaves the same as no deferral.
15
+ */
16
+ mcpLoadingMode = "eager";
17
+ /**
18
+ * Whether to expose the search and dispatch tools to the model is computed once
19
+ * by applyMode in mcp/strategy at session start. It is not recomputed each turn
20
+ * based on "are there still deferred tools": tools may be disabled at runtime,
21
+ * and recomputing would drop one from tools[] mid-session — that's an array
22
+ * change, which breaks the cache prefix just the same.
23
+ */
24
+ exposeToolSearch = false;
25
+ exposeMcpCall = false;
26
+ register(tool) {
27
+ this.tools.set(tool.name, tool);
28
+ }
29
+ get(name) {
30
+ return this.tools.get(name);
31
+ }
32
+ listTools() {
33
+ return [...this.tools.values()];
34
+ }
35
+ getAllSchemas(protocol = "anthropic") {
36
+ const isOpenAI = protocol === "openai" || protocol === "openai-compat";
37
+ const native = this.mcpLoadingMode === "native" && !isOpenAI;
38
+ const schemas = [];
39
+ for (const tool of this.tools.values()) {
40
+ if (tool.name === TOOL_SEARCH_TOOL_NAME && !this.exposeToolSearch || tool.name === MCP_CALL_TOOL_NAME && !this.exposeMcpCall) {
41
+ continue;
42
+ }
43
+ const deferred = Boolean(tool.deferred) && !this.discovered.has(tool.name);
44
+ if (deferred && !native) {
45
+ continue;
46
+ }
47
+ const s = tool.schema();
48
+ if (isOpenAI) {
49
+ schemas.push({
50
+ strict: false,
51
+ // Whether to enforce strict parameter validation. Default true.
52
+ type: "function",
53
+ name: s.name,
54
+ description: s.description,
55
+ parameters: s.input_schema,
56
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
57
+ // @ts-ignore
58
+ function: {
59
+ name: s.name,
60
+ description: s.description,
61
+ parameters: s.input_schema
62
+ }
63
+ });
64
+ } else {
65
+ schemas.push(
66
+ deferred ? {
67
+ ...s,
68
+ type: "custom",
69
+ defer_loading: true
70
+ } : {
71
+ ...s,
72
+ type: "custom"
73
+ }
74
+ );
75
+ }
76
+ }
77
+ return schemas;
78
+ }
79
+ /**
80
+ * Names of deferred tools not yet discovered, in lexicographic order.
81
+ *
82
+ * Sorting is not cosmetic: callers compare this list to detect pool changes;
83
+ * unstable ordering would produce different text for the same set of tools
84
+ * and break the comparison.
85
+ */
86
+ getDeferredToolNames() {
87
+ const names = [];
88
+ for (const tool of this.tools.values()) {
89
+ if (tool.deferred && !this.discovered.has(tool.name)) {
90
+ names.push(tool.name);
91
+ }
92
+ }
93
+ return names.sort();
94
+ }
95
+ getDeferredTools() {
96
+ return [...this.tools.values()].filter((t) => t.deferred && !this.discovered.has(t.name));
97
+ }
98
+ searchDeferred(query, maxResults = 5) {
99
+ const lower = query.toLowerCase();
100
+ const matches = [];
101
+ for (const tool of this.tools.values()) {
102
+ if (!tool.deferred || this.discovered.has(tool.name)) {
103
+ continue;
104
+ }
105
+ if (tool.name.toLowerCase().includes(lower) || tool.description.toLowerCase().includes(lower)) {
106
+ matches.push(tool);
107
+ if (matches.length >= maxResults) {
108
+ break;
109
+ }
110
+ }
111
+ }
112
+ return matches;
113
+ }
114
+ findDeferredByNames(names) {
115
+ const lowerMap = /* @__PURE__ */ new Map();
116
+ for (const [name, tool] of this.tools) {
117
+ lowerMap.set(name.toLowerCase(), tool);
118
+ }
119
+ return names.map((n) => lowerMap.get(n.toLowerCase())).filter((t) => t?.deferred ?? false);
120
+ }
121
+ markDiscovered(name) {
122
+ this.discovered.add(name);
123
+ }
124
+ isDiscovered(name) {
125
+ return this.discovered.has(name);
126
+ }
127
+ };
128
+
129
+ // src/subagent/tool-filter.ts
130
+ var SUBAGENT_DISALLOWED_TOOLS = /* @__PURE__ */ new Set([
131
+ "ExitPlanMode",
132
+ "Agent",
133
+ // Prevents recursive spawning of subagents
134
+ "AskUserQuestion",
135
+ "TaskStop"
136
+ ]);
137
+ var TEAMMATE_DISALLOWED_TOOLS = /* @__PURE__ */ new Set(["TeamCreate", "TeamDelete"]);
138
+ var CUSTOM_AGENT_DISALLOWED_TOOLS = /* @__PURE__ */ new Set([
139
+ "ExitPlanMode",
140
+ "Agent",
141
+ "AskUserQuestion",
142
+ "TaskStop"
143
+ ]);
144
+ var ASYNC_AGENT_ALLOWED_TOOLS = /* @__PURE__ */ new Set([
145
+ "ReadFile",
146
+ // "WebSearch",
147
+ "Grep",
148
+ "Glob",
149
+ "Bash",
150
+ "PowerShell",
151
+ "EditFile",
152
+ "WriteFile",
153
+ "LoadSkill",
154
+ "SyntheticOutput",
155
+ "ToolSearch",
156
+ "EnterWorktree",
157
+ "ExitWorktree",
158
+ // ToolSearch only reads out schemas; actual invocation relies on McpCall.
159
+ // The two must be allowed together, or the subagent sees tools but cannot call them
160
+ "McpCall"
161
+ ]);
162
+ function isMCPTool(name) {
163
+ return name.startsWith("mcp__");
164
+ }
165
+ function filterToolsForAgent(registry, allowedTools, disallowedTools, isAsync, isCustom = false) {
166
+ const disallowed = new Set(disallowedTools ?? []);
167
+ const allowed = new Set(allowedTools ?? []);
168
+ const hasWhitelist = allowed.size > 0 && !(allowed.size === 1 && allowed.has("*"));
169
+ const filtered = new ToolRegistry();
170
+ for (const tool of registry.listTools()) {
171
+ const name = tool.name;
172
+ if (isMCPTool(name)) {
173
+ filtered.register(tool);
174
+ continue;
175
+ }
176
+ if (SUBAGENT_DISALLOWED_TOOLS.has(name)) {
177
+ continue;
178
+ }
179
+ if (isCustom && CUSTOM_AGENT_DISALLOWED_TOOLS.has(name)) {
180
+ continue;
181
+ }
182
+ if (isAsync && !ASYNC_AGENT_ALLOWED_TOOLS.has(name)) {
183
+ continue;
184
+ }
185
+ if (disallowed.has(name)) {
186
+ continue;
187
+ }
188
+ if (hasWhitelist && !allowed.has(name)) {
189
+ continue;
190
+ }
191
+ filtered.register(tool);
192
+ }
193
+ return filtered;
194
+ }
195
+ var FORK_QUERY_SOURCE = "agent:builtin:fork";
196
+ function cloneRegistryForFork(registry) {
197
+ const forked = new ToolRegistry();
198
+ for (const tool of registry.listTools()) {
199
+ if (tool.name === "Agent" && "querySource" in tool) {
200
+ const clone = Object.create(
201
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
202
+ Object.getPrototypeOf(tool),
203
+ Object.getOwnPropertyDescriptors(tool)
204
+ );
205
+ clone.querySource = FORK_QUERY_SOURCE;
206
+ forked.register(clone);
207
+ } else {
208
+ forked.register(tool);
209
+ }
210
+ }
211
+ return forked;
212
+ }
213
+
214
+ export {
215
+ ToolRegistry,
216
+ SUBAGENT_DISALLOWED_TOOLS,
217
+ TEAMMATE_DISALLOWED_TOOLS,
218
+ CUSTOM_AGENT_DISALLOWED_TOOLS,
219
+ ASYNC_AGENT_ALLOWED_TOOLS,
220
+ filterToolsForAgent,
221
+ FORK_QUERY_SOURCE,
222
+ cloneRegistryForFork
223
+ };