@nathanstephenson/flow 0.1.10-beta.3 → 0.1.10-beta.5
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 +11 -3
- package/build/backend-worker-chunks/{chunk-LO7O6NAM.mjs → chunk-JOI2POLP.mjs} +1 -1
- package/build/backend-worker-chunks/{chunk-UQDH2COY.mjs → chunk-K774KOGL.mjs} +2 -7
- package/build/backend-worker-chunks/chunk-LAEUXDNH.mjs +130 -0
- package/build/backend-worker-chunks/{chunk-MLOUI3ZM.mjs → chunk-NZZME2I3.mjs} +6 -1
- package/build/backend-worker-chunks/claude-GY27HBAY.mjs +35739 -0
- package/build/backend-worker-chunks/{pi-QNU2YE4G.mjs → pi-JV6MWPW7.mjs} +1891 -35
- package/build/backend-worker.mjs +25 -126
- package/build/workflow-runtime.cjs +12 -12
- package/dist/backend/claude/index.js +69 -11
- package/dist/backend/claude/subagents.js +11 -0
- package/dist/backend/claude/workflow-parent.js +1 -1
- package/dist/backend/fake/index.js +8 -2
- package/dist/backend/pi/cache-warming.js +8 -0
- package/dist/backend/pi/canonical-json.js +120 -0
- package/dist/backend/pi/compaction-model.js +3 -2
- package/dist/backend/pi/host-auth.js +258 -0
- package/dist/backend/pi/index.js +37 -12
- package/dist/backend/pi/model-auth.js +159 -0
- package/dist/backend/pi/model-catalog.js +120 -0
- package/dist/backend/pi/model-config.js +5 -0
- package/dist/backend/pi/model-selection.js +32 -0
- package/dist/backend/pi/work.js +9 -1
- package/dist/backend/pi/workflow-parent.js +1 -1
- package/dist/backend/pi/workflow-subagent.js +4 -3
- package/dist/backend/worker/entry.js +13 -1
- package/dist/backend/worker/index.js +69 -7
- package/dist/backend/worker/launcher.js +11 -4
- package/dist/build-id +1 -1
- package/dist/cli/application.js +5 -5
- package/dist/cli/bootstrap.js +1 -1
- package/dist/cli/host-control.js +1 -1
- package/dist/cli/install-guard.js +1 -1
- package/dist/cli/main.js +4 -4
- package/dist/cli/systemd-update.js +3 -3
- package/dist/cli/update.js +6 -6
- package/dist/cli/web-update.js +6 -6
- package/dist/client/reduce.js +2 -0
- package/dist/client/tool-summary.js +26 -15
- package/dist/daemon/changes.js +116 -0
- package/dist/daemon/commit.js +84 -0
- package/dist/daemon/config-store.js +3 -3
- package/dist/daemon/git-state.js +197 -0
- package/dist/daemon/github.js +54 -0
- package/dist/daemon/host-control-routes.js +1 -1
- package/dist/daemon/host.js +147 -78
- package/dist/daemon/log.js +3 -0
- package/dist/daemon/mcp-auth.js +1 -1
- package/dist/daemon/models.js +2 -2
- package/dist/daemon/pi-model-cache.js +44 -0
- package/dist/daemon/pull-request.js +156 -129
- package/dist/daemon/push.js +43 -0
- package/dist/daemon/repository.js +106 -0
- package/dist/daemon/runtime.js +27 -20
- package/dist/daemon/secret-store.js +1 -1
- package/dist/daemon/server.js +11 -10
- package/dist/daemon/stack-metadata.js +12 -5
- package/dist/daemon/stack.js +127 -656
- package/dist/daemon/summariser.js +19 -8
- package/dist/daemon/workflow-authoring-scope-checks.js +1 -1
- package/dist/daemon/workflow-authoring-scope.js +1 -1
- package/dist/daemon/workflow-builder-files.js +2 -2
- package/dist/daemon/workflow-builder-routes.js +2 -2
- package/dist/daemon/workflow-builder.js +5 -5
- package/dist/daemon/workflow-environment.js +5 -5
- package/dist/daemon/workflow-execution-launch.js +5 -5
- package/dist/daemon/workflow-execution-resources.js +3 -3
- package/dist/daemon/workflow-execution-routes.js +3 -3
- package/dist/daemon/workflow-execution-values.js +5 -5
- package/dist/daemon/workflow-executions.js +19 -19
- package/dist/daemon/workflow-mcp-authoring-routes.js +2 -2
- package/dist/daemon/workflow-mcp-authoring.js +4 -4
- package/dist/daemon/workflow-mcp.js +1 -1
- package/dist/daemon/workflow-routes.js +3 -3
- package/dist/daemon/workflow-schedule-driver.js +8 -8
- package/dist/daemon/workflow-schedule-routes.js +5 -5
- package/dist/daemon/workflow-schedules.js +3 -3
- package/dist/isolation/filesystem.js +5 -1
- package/dist/isolation/sandbox.js +31 -4
- package/dist/isolation/toolchain-assets.js +1 -1
- package/dist/protocol/stack.js +1 -41
- package/dist/workflows/calls.js +2 -2
- package/dist/workflows/executors.js +3 -3
- package/dist/workflows/graph.js +6 -6
- package/dist/workflows/invocations.js +1 -1
- package/dist/workflows/mcp.js +1 -1
- package/dist/workflows/records.js +6 -6
- package/dist/workflows/recovery.js +2 -2
- package/dist/workflows/runtime-settings.js +1 -1
- package/dist/workflows/runtime.js +2 -2
- package/dist/workflows/schedule-store.js +2 -2
- package/dist/workflows/scheduler.js +9 -9
- package/dist/workflows/schema.js +1 -1
- package/dist/workflows/store.js +3 -3
- package/package.json +9 -6
- package/web/dist/assets/index-BqZ_iUmY.css +2 -0
- package/web/dist/assets/index-CxdSb7k0.js +51 -0
- package/web/dist/assets/{settings-mcp-Vf_fCXyE.js → settings-mcp-BwOPXAfH.js} +1 -1
- package/web/dist/assets/settings-workflows-DocTa31_.js +23 -0
- package/web/dist/assets/{switch-DIogWclb.js → switch-B00FEUA7.js} +1 -1
- package/web/dist/assets/{workflows-Dobqzjg-.js → workflows-DJqUuGyg.js} +41 -41
- package/web/dist/assets/{workflows-pane-KB-Q76KZ.js → workflows-pane-oM1fO_BC.js} +1 -1
- package/web/dist/index.html +4 -4
- package/build/backend-worker-chunks/claude-6L5KCQWJ.mjs +0 -30894
- package/dist/daemon/publish.js +0 -289
- package/dist/protocol/publish.js +0 -1
- package/web/dist/assets/index-BGu3YSP7.css +0 -2
- package/web/dist/assets/index-Miy2nveb.js +0 -40
- package/web/dist/assets/settings-workflows-DVKxJWQm.js +0 -23
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createRequire as __flowCreateRequire } from 'node:module'; const require = __flowCreateRequire(import.meta.url);
|
|
2
|
+
import "./chunk-LAEUXDNH.mjs";
|
|
2
3
|
import {
|
|
3
4
|
EFFORT_ORDER,
|
|
4
5
|
clampEffort,
|
|
@@ -18,11 +19,1591 @@ import {
|
|
|
18
19
|
workflowInspectInput,
|
|
19
20
|
workflowRecoverInput,
|
|
20
21
|
workflowRelayInput
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-JOI2POLP.mjs";
|
|
22
23
|
import {
|
|
24
|
+
__commonJS,
|
|
23
25
|
__export,
|
|
26
|
+
__require,
|
|
27
|
+
__toESM,
|
|
24
28
|
external_exports
|
|
25
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-NZZME2I3.mjs";
|
|
30
|
+
|
|
31
|
+
// node_modules/graceful-fs/polyfills.js
|
|
32
|
+
var require_polyfills = __commonJS({
|
|
33
|
+
"node_modules/graceful-fs/polyfills.js"(exports, module) {
|
|
34
|
+
var constants = __require("constants");
|
|
35
|
+
var origCwd = process.cwd;
|
|
36
|
+
var cwd = null;
|
|
37
|
+
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
|
|
38
|
+
process.cwd = function() {
|
|
39
|
+
if (!cwd)
|
|
40
|
+
cwd = origCwd.call(process);
|
|
41
|
+
return cwd;
|
|
42
|
+
};
|
|
43
|
+
try {
|
|
44
|
+
process.cwd();
|
|
45
|
+
} catch (er) {
|
|
46
|
+
}
|
|
47
|
+
if (typeof process.chdir === "function") {
|
|
48
|
+
chdir = process.chdir;
|
|
49
|
+
process.chdir = function(d) {
|
|
50
|
+
cwd = null;
|
|
51
|
+
chdir.call(process, d);
|
|
52
|
+
};
|
|
53
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(process.chdir, chdir);
|
|
54
|
+
}
|
|
55
|
+
var chdir;
|
|
56
|
+
module.exports = patch;
|
|
57
|
+
function patch(fs) {
|
|
58
|
+
if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
|
|
59
|
+
patchLchmod(fs);
|
|
60
|
+
}
|
|
61
|
+
if (!fs.lutimes) {
|
|
62
|
+
patchLutimes(fs);
|
|
63
|
+
}
|
|
64
|
+
fs.chown = chownFix(fs.chown);
|
|
65
|
+
fs.fchown = chownFix(fs.fchown);
|
|
66
|
+
fs.lchown = chownFix(fs.lchown);
|
|
67
|
+
fs.chmod = chmodFix(fs.chmod);
|
|
68
|
+
fs.fchmod = chmodFix(fs.fchmod);
|
|
69
|
+
fs.lchmod = chmodFix(fs.lchmod);
|
|
70
|
+
fs.chownSync = chownFixSync(fs.chownSync);
|
|
71
|
+
fs.fchownSync = chownFixSync(fs.fchownSync);
|
|
72
|
+
fs.lchownSync = chownFixSync(fs.lchownSync);
|
|
73
|
+
fs.chmodSync = chmodFixSync(fs.chmodSync);
|
|
74
|
+
fs.fchmodSync = chmodFixSync(fs.fchmodSync);
|
|
75
|
+
fs.lchmodSync = chmodFixSync(fs.lchmodSync);
|
|
76
|
+
fs.stat = statFix(fs.stat);
|
|
77
|
+
fs.fstat = statFix(fs.fstat);
|
|
78
|
+
fs.lstat = statFix(fs.lstat);
|
|
79
|
+
fs.statSync = statFixSync(fs.statSync);
|
|
80
|
+
fs.fstatSync = statFixSync(fs.fstatSync);
|
|
81
|
+
fs.lstatSync = statFixSync(fs.lstatSync);
|
|
82
|
+
if (fs.chmod && !fs.lchmod) {
|
|
83
|
+
fs.lchmod = function(path, mode, cb) {
|
|
84
|
+
if (cb) process.nextTick(cb);
|
|
85
|
+
};
|
|
86
|
+
fs.lchmodSync = function() {
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (fs.chown && !fs.lchown) {
|
|
90
|
+
fs.lchown = function(path, uid, gid, cb) {
|
|
91
|
+
if (cb) process.nextTick(cb);
|
|
92
|
+
};
|
|
93
|
+
fs.lchownSync = function() {
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (platform === "win32") {
|
|
97
|
+
fs.rename = typeof fs.rename !== "function" ? fs.rename : (function(fs$rename) {
|
|
98
|
+
function rename(from, to, cb) {
|
|
99
|
+
var start = Date.now();
|
|
100
|
+
var backoff = 0;
|
|
101
|
+
fs$rename(from, to, function CB(er) {
|
|
102
|
+
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
|
|
103
|
+
setTimeout(function() {
|
|
104
|
+
fs.stat(to, function(stater, st) {
|
|
105
|
+
if (stater && stater.code === "ENOENT")
|
|
106
|
+
fs$rename(from, to, CB);
|
|
107
|
+
else
|
|
108
|
+
cb(er);
|
|
109
|
+
});
|
|
110
|
+
}, backoff);
|
|
111
|
+
if (backoff < 100)
|
|
112
|
+
backoff += 10;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
if (cb) cb(er);
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(rename, fs$rename);
|
|
119
|
+
return rename;
|
|
120
|
+
})(fs.rename);
|
|
121
|
+
}
|
|
122
|
+
fs.read = typeof fs.read !== "function" ? fs.read : (function(fs$read) {
|
|
123
|
+
function read(fd, buffer, offset, length, position, callback_) {
|
|
124
|
+
var callback;
|
|
125
|
+
if (callback_ && typeof callback_ === "function") {
|
|
126
|
+
var eagCounter = 0;
|
|
127
|
+
callback = function(er, _, __) {
|
|
128
|
+
if (er && er.code === "EAGAIN" && eagCounter < 10) {
|
|
129
|
+
eagCounter++;
|
|
130
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
|
|
131
|
+
}
|
|
132
|
+
callback_.apply(this, arguments);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
|
|
136
|
+
}
|
|
137
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(read, fs$read);
|
|
138
|
+
return read;
|
|
139
|
+
})(fs.read);
|
|
140
|
+
fs.readSync = typeof fs.readSync !== "function" ? fs.readSync : /* @__PURE__ */ (function(fs$readSync) {
|
|
141
|
+
return function(fd, buffer, offset, length, position) {
|
|
142
|
+
var eagCounter = 0;
|
|
143
|
+
while (true) {
|
|
144
|
+
try {
|
|
145
|
+
return fs$readSync.call(fs, fd, buffer, offset, length, position);
|
|
146
|
+
} catch (er) {
|
|
147
|
+
if (er.code === "EAGAIN" && eagCounter < 10) {
|
|
148
|
+
eagCounter++;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
throw er;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
})(fs.readSync);
|
|
156
|
+
function patchLchmod(fs2) {
|
|
157
|
+
fs2.lchmod = function(path, mode, callback) {
|
|
158
|
+
fs2.open(
|
|
159
|
+
path,
|
|
160
|
+
constants.O_WRONLY | constants.O_SYMLINK,
|
|
161
|
+
mode,
|
|
162
|
+
function(err, fd) {
|
|
163
|
+
if (err) {
|
|
164
|
+
if (callback) callback(err);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
fs2.fchmod(fd, mode, function(err2) {
|
|
168
|
+
fs2.close(fd, function(err22) {
|
|
169
|
+
if (callback) callback(err2 || err22);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
);
|
|
174
|
+
};
|
|
175
|
+
fs2.lchmodSync = function(path, mode) {
|
|
176
|
+
var fd = fs2.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
|
|
177
|
+
var threw = true;
|
|
178
|
+
var ret;
|
|
179
|
+
try {
|
|
180
|
+
ret = fs2.fchmodSync(fd, mode);
|
|
181
|
+
threw = false;
|
|
182
|
+
} finally {
|
|
183
|
+
if (threw) {
|
|
184
|
+
try {
|
|
185
|
+
fs2.closeSync(fd);
|
|
186
|
+
} catch (er) {
|
|
187
|
+
}
|
|
188
|
+
} else {
|
|
189
|
+
fs2.closeSync(fd);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return ret;
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
function patchLutimes(fs2) {
|
|
196
|
+
if (constants.hasOwnProperty("O_SYMLINK") && fs2.futimes) {
|
|
197
|
+
fs2.lutimes = function(path, at, mt, cb) {
|
|
198
|
+
fs2.open(path, constants.O_SYMLINK, function(er, fd) {
|
|
199
|
+
if (er) {
|
|
200
|
+
if (cb) cb(er);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
fs2.futimes(fd, at, mt, function(er2) {
|
|
204
|
+
fs2.close(fd, function(er22) {
|
|
205
|
+
if (cb) cb(er2 || er22);
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
};
|
|
210
|
+
fs2.lutimesSync = function(path, at, mt) {
|
|
211
|
+
var fd = fs2.openSync(path, constants.O_SYMLINK);
|
|
212
|
+
var ret;
|
|
213
|
+
var threw = true;
|
|
214
|
+
try {
|
|
215
|
+
ret = fs2.futimesSync(fd, at, mt);
|
|
216
|
+
threw = false;
|
|
217
|
+
} finally {
|
|
218
|
+
if (threw) {
|
|
219
|
+
try {
|
|
220
|
+
fs2.closeSync(fd);
|
|
221
|
+
} catch (er) {
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
fs2.closeSync(fd);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return ret;
|
|
228
|
+
};
|
|
229
|
+
} else if (fs2.futimes) {
|
|
230
|
+
fs2.lutimes = function(_a, _b, _c, cb) {
|
|
231
|
+
if (cb) process.nextTick(cb);
|
|
232
|
+
};
|
|
233
|
+
fs2.lutimesSync = function() {
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
function chmodFix(orig) {
|
|
238
|
+
if (!orig) return orig;
|
|
239
|
+
return function(target, mode, cb) {
|
|
240
|
+
return orig.call(fs, target, mode, function(er) {
|
|
241
|
+
if (chownErOk(er)) er = null;
|
|
242
|
+
if (cb) cb.apply(this, arguments);
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
function chmodFixSync(orig) {
|
|
247
|
+
if (!orig) return orig;
|
|
248
|
+
return function(target, mode) {
|
|
249
|
+
try {
|
|
250
|
+
return orig.call(fs, target, mode);
|
|
251
|
+
} catch (er) {
|
|
252
|
+
if (!chownErOk(er)) throw er;
|
|
253
|
+
}
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function chownFix(orig) {
|
|
257
|
+
if (!orig) return orig;
|
|
258
|
+
return function(target, uid, gid, cb) {
|
|
259
|
+
return orig.call(fs, target, uid, gid, function(er) {
|
|
260
|
+
if (chownErOk(er)) er = null;
|
|
261
|
+
if (cb) cb.apply(this, arguments);
|
|
262
|
+
});
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function chownFixSync(orig) {
|
|
266
|
+
if (!orig) return orig;
|
|
267
|
+
return function(target, uid, gid) {
|
|
268
|
+
try {
|
|
269
|
+
return orig.call(fs, target, uid, gid);
|
|
270
|
+
} catch (er) {
|
|
271
|
+
if (!chownErOk(er)) throw er;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function statFix(orig) {
|
|
276
|
+
if (!orig) return orig;
|
|
277
|
+
return function(target, options, cb) {
|
|
278
|
+
if (typeof options === "function") {
|
|
279
|
+
cb = options;
|
|
280
|
+
options = null;
|
|
281
|
+
}
|
|
282
|
+
function callback(er, stats) {
|
|
283
|
+
if (stats) {
|
|
284
|
+
if (stats.uid < 0) stats.uid += 4294967296;
|
|
285
|
+
if (stats.gid < 0) stats.gid += 4294967296;
|
|
286
|
+
}
|
|
287
|
+
if (cb) cb.apply(this, arguments);
|
|
288
|
+
}
|
|
289
|
+
return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
function statFixSync(orig) {
|
|
293
|
+
if (!orig) return orig;
|
|
294
|
+
return function(target, options) {
|
|
295
|
+
var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
|
|
296
|
+
if (stats) {
|
|
297
|
+
if (stats.uid < 0) stats.uid += 4294967296;
|
|
298
|
+
if (stats.gid < 0) stats.gid += 4294967296;
|
|
299
|
+
}
|
|
300
|
+
return stats;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function chownErOk(er) {
|
|
304
|
+
if (!er)
|
|
305
|
+
return true;
|
|
306
|
+
if (er.code === "ENOSYS")
|
|
307
|
+
return true;
|
|
308
|
+
var nonroot = !process.getuid || process.getuid() !== 0;
|
|
309
|
+
if (nonroot) {
|
|
310
|
+
if (er.code === "EINVAL" || er.code === "EPERM")
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
// node_modules/graceful-fs/legacy-streams.js
|
|
320
|
+
var require_legacy_streams = __commonJS({
|
|
321
|
+
"node_modules/graceful-fs/legacy-streams.js"(exports, module) {
|
|
322
|
+
var Stream = __require("stream").Stream;
|
|
323
|
+
module.exports = legacy;
|
|
324
|
+
function legacy(fs) {
|
|
325
|
+
return {
|
|
326
|
+
ReadStream,
|
|
327
|
+
WriteStream
|
|
328
|
+
};
|
|
329
|
+
function ReadStream(path, options) {
|
|
330
|
+
if (!(this instanceof ReadStream)) return new ReadStream(path, options);
|
|
331
|
+
Stream.call(this);
|
|
332
|
+
var self = this;
|
|
333
|
+
this.path = path;
|
|
334
|
+
this.fd = null;
|
|
335
|
+
this.readable = true;
|
|
336
|
+
this.paused = false;
|
|
337
|
+
this.flags = "r";
|
|
338
|
+
this.mode = 438;
|
|
339
|
+
this.bufferSize = 64 * 1024;
|
|
340
|
+
options = options || {};
|
|
341
|
+
var keys = Object.keys(options);
|
|
342
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
343
|
+
var key = keys[index];
|
|
344
|
+
this[key] = options[key];
|
|
345
|
+
}
|
|
346
|
+
if (this.encoding) this.setEncoding(this.encoding);
|
|
347
|
+
if (this.start !== void 0) {
|
|
348
|
+
if ("number" !== typeof this.start) {
|
|
349
|
+
throw TypeError("start must be a Number");
|
|
350
|
+
}
|
|
351
|
+
if (this.end === void 0) {
|
|
352
|
+
this.end = Infinity;
|
|
353
|
+
} else if ("number" !== typeof this.end) {
|
|
354
|
+
throw TypeError("end must be a Number");
|
|
355
|
+
}
|
|
356
|
+
if (this.start > this.end) {
|
|
357
|
+
throw new Error("start must be <= end");
|
|
358
|
+
}
|
|
359
|
+
this.pos = this.start;
|
|
360
|
+
}
|
|
361
|
+
if (this.fd !== null) {
|
|
362
|
+
process.nextTick(function() {
|
|
363
|
+
self._read();
|
|
364
|
+
});
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
fs.open(this.path, this.flags, this.mode, function(err, fd) {
|
|
368
|
+
if (err) {
|
|
369
|
+
self.emit("error", err);
|
|
370
|
+
self.readable = false;
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
self.fd = fd;
|
|
374
|
+
self.emit("open", fd);
|
|
375
|
+
self._read();
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
function WriteStream(path, options) {
|
|
379
|
+
if (!(this instanceof WriteStream)) return new WriteStream(path, options);
|
|
380
|
+
Stream.call(this);
|
|
381
|
+
this.path = path;
|
|
382
|
+
this.fd = null;
|
|
383
|
+
this.writable = true;
|
|
384
|
+
this.flags = "w";
|
|
385
|
+
this.encoding = "binary";
|
|
386
|
+
this.mode = 438;
|
|
387
|
+
this.bytesWritten = 0;
|
|
388
|
+
options = options || {};
|
|
389
|
+
var keys = Object.keys(options);
|
|
390
|
+
for (var index = 0, length = keys.length; index < length; index++) {
|
|
391
|
+
var key = keys[index];
|
|
392
|
+
this[key] = options[key];
|
|
393
|
+
}
|
|
394
|
+
if (this.start !== void 0) {
|
|
395
|
+
if ("number" !== typeof this.start) {
|
|
396
|
+
throw TypeError("start must be a Number");
|
|
397
|
+
}
|
|
398
|
+
if (this.start < 0) {
|
|
399
|
+
throw new Error("start must be >= zero");
|
|
400
|
+
}
|
|
401
|
+
this.pos = this.start;
|
|
402
|
+
}
|
|
403
|
+
this.busy = false;
|
|
404
|
+
this._queue = [];
|
|
405
|
+
if (this.fd === null) {
|
|
406
|
+
this._open = fs.open;
|
|
407
|
+
this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
|
|
408
|
+
this.flush();
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
// node_modules/graceful-fs/clone.js
|
|
416
|
+
var require_clone = __commonJS({
|
|
417
|
+
"node_modules/graceful-fs/clone.js"(exports, module) {
|
|
418
|
+
"use strict";
|
|
419
|
+
module.exports = clone;
|
|
420
|
+
var getPrototypeOf = Object.getPrototypeOf || function(obj) {
|
|
421
|
+
return obj.__proto__;
|
|
422
|
+
};
|
|
423
|
+
function clone(obj) {
|
|
424
|
+
if (obj === null || typeof obj !== "object")
|
|
425
|
+
return obj;
|
|
426
|
+
if (obj instanceof Object)
|
|
427
|
+
var copy = { __proto__: getPrototypeOf(obj) };
|
|
428
|
+
else
|
|
429
|
+
var copy = /* @__PURE__ */ Object.create(null);
|
|
430
|
+
Object.getOwnPropertyNames(obj).forEach(function(key) {
|
|
431
|
+
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
|
|
432
|
+
});
|
|
433
|
+
return copy;
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// node_modules/graceful-fs/graceful-fs.js
|
|
439
|
+
var require_graceful_fs = __commonJS({
|
|
440
|
+
"node_modules/graceful-fs/graceful-fs.js"(exports, module) {
|
|
441
|
+
var fs = __require("fs");
|
|
442
|
+
var polyfills = require_polyfills();
|
|
443
|
+
var legacy = require_legacy_streams();
|
|
444
|
+
var clone = require_clone();
|
|
445
|
+
var util = __require("util");
|
|
446
|
+
var gracefulQueue;
|
|
447
|
+
var previousSymbol;
|
|
448
|
+
if (typeof Symbol === "function" && typeof Symbol.for === "function") {
|
|
449
|
+
gracefulQueue = /* @__PURE__ */ Symbol.for("graceful-fs.queue");
|
|
450
|
+
previousSymbol = /* @__PURE__ */ Symbol.for("graceful-fs.previous");
|
|
451
|
+
} else {
|
|
452
|
+
gracefulQueue = "___graceful-fs.queue";
|
|
453
|
+
previousSymbol = "___graceful-fs.previous";
|
|
454
|
+
}
|
|
455
|
+
function noop() {
|
|
456
|
+
}
|
|
457
|
+
function publishQueue(context, queue2) {
|
|
458
|
+
Object.defineProperty(context, gracefulQueue, {
|
|
459
|
+
get: function() {
|
|
460
|
+
return queue2;
|
|
461
|
+
}
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
var debug = noop;
|
|
465
|
+
if (util.debuglog)
|
|
466
|
+
debug = util.debuglog("gfs4");
|
|
467
|
+
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
|
|
468
|
+
debug = function() {
|
|
469
|
+
var m = util.format.apply(util, arguments);
|
|
470
|
+
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
|
|
471
|
+
console.error(m);
|
|
472
|
+
};
|
|
473
|
+
if (!fs[gracefulQueue]) {
|
|
474
|
+
queue = global[gracefulQueue] || [];
|
|
475
|
+
publishQueue(fs, queue);
|
|
476
|
+
fs.close = (function(fs$close) {
|
|
477
|
+
function close(fd, cb) {
|
|
478
|
+
return fs$close.call(fs, fd, function(err) {
|
|
479
|
+
if (!err) {
|
|
480
|
+
resetQueue();
|
|
481
|
+
}
|
|
482
|
+
if (typeof cb === "function")
|
|
483
|
+
cb.apply(this, arguments);
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
Object.defineProperty(close, previousSymbol, {
|
|
487
|
+
value: fs$close
|
|
488
|
+
});
|
|
489
|
+
return close;
|
|
490
|
+
})(fs.close);
|
|
491
|
+
fs.closeSync = (function(fs$closeSync) {
|
|
492
|
+
function closeSync(fd) {
|
|
493
|
+
fs$closeSync.apply(fs, arguments);
|
|
494
|
+
resetQueue();
|
|
495
|
+
}
|
|
496
|
+
Object.defineProperty(closeSync, previousSymbol, {
|
|
497
|
+
value: fs$closeSync
|
|
498
|
+
});
|
|
499
|
+
return closeSync;
|
|
500
|
+
})(fs.closeSync);
|
|
501
|
+
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
|
|
502
|
+
process.on("exit", function() {
|
|
503
|
+
debug(fs[gracefulQueue]);
|
|
504
|
+
__require("assert").equal(fs[gracefulQueue].length, 0);
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
var queue;
|
|
509
|
+
if (!global[gracefulQueue]) {
|
|
510
|
+
publishQueue(global, fs[gracefulQueue]);
|
|
511
|
+
}
|
|
512
|
+
module.exports = patch(clone(fs));
|
|
513
|
+
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) {
|
|
514
|
+
module.exports = patch(fs);
|
|
515
|
+
fs.__patched = true;
|
|
516
|
+
}
|
|
517
|
+
function patch(fs2) {
|
|
518
|
+
polyfills(fs2);
|
|
519
|
+
fs2.gracefulify = patch;
|
|
520
|
+
fs2.createReadStream = createReadStream;
|
|
521
|
+
fs2.createWriteStream = createWriteStream;
|
|
522
|
+
var fs$readFile = fs2.readFile;
|
|
523
|
+
fs2.readFile = readFile;
|
|
524
|
+
function readFile(path, options, cb) {
|
|
525
|
+
if (typeof options === "function")
|
|
526
|
+
cb = options, options = null;
|
|
527
|
+
return go$readFile(path, options, cb);
|
|
528
|
+
function go$readFile(path2, options2, cb2, startTime) {
|
|
529
|
+
return fs$readFile(path2, options2, function(err) {
|
|
530
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
531
|
+
enqueue([go$readFile, [path2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
532
|
+
else {
|
|
533
|
+
if (typeof cb2 === "function")
|
|
534
|
+
cb2.apply(this, arguments);
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
var fs$writeFile = fs2.writeFile;
|
|
540
|
+
fs2.writeFile = writeFile;
|
|
541
|
+
function writeFile(path, data, options, cb) {
|
|
542
|
+
if (typeof options === "function")
|
|
543
|
+
cb = options, options = null;
|
|
544
|
+
return go$writeFile(path, data, options, cb);
|
|
545
|
+
function go$writeFile(path2, data2, options2, cb2, startTime) {
|
|
546
|
+
return fs$writeFile(path2, data2, options2, function(err) {
|
|
547
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
548
|
+
enqueue([go$writeFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
549
|
+
else {
|
|
550
|
+
if (typeof cb2 === "function")
|
|
551
|
+
cb2.apply(this, arguments);
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
var fs$appendFile = fs2.appendFile;
|
|
557
|
+
if (fs$appendFile)
|
|
558
|
+
fs2.appendFile = appendFile;
|
|
559
|
+
function appendFile(path, data, options, cb) {
|
|
560
|
+
if (typeof options === "function")
|
|
561
|
+
cb = options, options = null;
|
|
562
|
+
return go$appendFile(path, data, options, cb);
|
|
563
|
+
function go$appendFile(path2, data2, options2, cb2, startTime) {
|
|
564
|
+
return fs$appendFile(path2, data2, options2, function(err) {
|
|
565
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
566
|
+
enqueue([go$appendFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
567
|
+
else {
|
|
568
|
+
if (typeof cb2 === "function")
|
|
569
|
+
cb2.apply(this, arguments);
|
|
570
|
+
}
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
var fs$copyFile = fs2.copyFile;
|
|
575
|
+
if (fs$copyFile)
|
|
576
|
+
fs2.copyFile = copyFile;
|
|
577
|
+
function copyFile(src, dest, flags, cb) {
|
|
578
|
+
if (typeof flags === "function") {
|
|
579
|
+
cb = flags;
|
|
580
|
+
flags = 0;
|
|
581
|
+
}
|
|
582
|
+
return go$copyFile(src, dest, flags, cb);
|
|
583
|
+
function go$copyFile(src2, dest2, flags2, cb2, startTime) {
|
|
584
|
+
return fs$copyFile(src2, dest2, flags2, function(err) {
|
|
585
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
586
|
+
enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
587
|
+
else {
|
|
588
|
+
if (typeof cb2 === "function")
|
|
589
|
+
cb2.apply(this, arguments);
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
var fs$readdir = fs2.readdir;
|
|
595
|
+
fs2.readdir = readdir;
|
|
596
|
+
var noReaddirOptionVersions = /^v[0-5]\./;
|
|
597
|
+
function readdir(path, options, cb) {
|
|
598
|
+
if (typeof options === "function")
|
|
599
|
+
cb = options, options = null;
|
|
600
|
+
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path2, options2, cb2, startTime) {
|
|
601
|
+
return fs$readdir(path2, fs$readdirCallback(
|
|
602
|
+
path2,
|
|
603
|
+
options2,
|
|
604
|
+
cb2,
|
|
605
|
+
startTime
|
|
606
|
+
));
|
|
607
|
+
} : function go$readdir2(path2, options2, cb2, startTime) {
|
|
608
|
+
return fs$readdir(path2, options2, fs$readdirCallback(
|
|
609
|
+
path2,
|
|
610
|
+
options2,
|
|
611
|
+
cb2,
|
|
612
|
+
startTime
|
|
613
|
+
));
|
|
614
|
+
};
|
|
615
|
+
return go$readdir(path, options, cb);
|
|
616
|
+
function fs$readdirCallback(path2, options2, cb2, startTime) {
|
|
617
|
+
return function(err, files) {
|
|
618
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
619
|
+
enqueue([
|
|
620
|
+
go$readdir,
|
|
621
|
+
[path2, options2, cb2],
|
|
622
|
+
err,
|
|
623
|
+
startTime || Date.now(),
|
|
624
|
+
Date.now()
|
|
625
|
+
]);
|
|
626
|
+
else {
|
|
627
|
+
if (files && files.sort)
|
|
628
|
+
files.sort();
|
|
629
|
+
if (typeof cb2 === "function")
|
|
630
|
+
cb2.call(this, err, files);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (process.version.substr(0, 4) === "v0.8") {
|
|
636
|
+
var legStreams = legacy(fs2);
|
|
637
|
+
ReadStream = legStreams.ReadStream;
|
|
638
|
+
WriteStream = legStreams.WriteStream;
|
|
639
|
+
}
|
|
640
|
+
var fs$ReadStream = fs2.ReadStream;
|
|
641
|
+
if (fs$ReadStream) {
|
|
642
|
+
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
|
|
643
|
+
ReadStream.prototype.open = ReadStream$open;
|
|
644
|
+
}
|
|
645
|
+
var fs$WriteStream = fs2.WriteStream;
|
|
646
|
+
if (fs$WriteStream) {
|
|
647
|
+
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
|
|
648
|
+
WriteStream.prototype.open = WriteStream$open;
|
|
649
|
+
}
|
|
650
|
+
Object.defineProperty(fs2, "ReadStream", {
|
|
651
|
+
get: function() {
|
|
652
|
+
return ReadStream;
|
|
653
|
+
},
|
|
654
|
+
set: function(val) {
|
|
655
|
+
ReadStream = val;
|
|
656
|
+
},
|
|
657
|
+
enumerable: true,
|
|
658
|
+
configurable: true
|
|
659
|
+
});
|
|
660
|
+
Object.defineProperty(fs2, "WriteStream", {
|
|
661
|
+
get: function() {
|
|
662
|
+
return WriteStream;
|
|
663
|
+
},
|
|
664
|
+
set: function(val) {
|
|
665
|
+
WriteStream = val;
|
|
666
|
+
},
|
|
667
|
+
enumerable: true,
|
|
668
|
+
configurable: true
|
|
669
|
+
});
|
|
670
|
+
var FileReadStream = ReadStream;
|
|
671
|
+
Object.defineProperty(fs2, "FileReadStream", {
|
|
672
|
+
get: function() {
|
|
673
|
+
return FileReadStream;
|
|
674
|
+
},
|
|
675
|
+
set: function(val) {
|
|
676
|
+
FileReadStream = val;
|
|
677
|
+
},
|
|
678
|
+
enumerable: true,
|
|
679
|
+
configurable: true
|
|
680
|
+
});
|
|
681
|
+
var FileWriteStream = WriteStream;
|
|
682
|
+
Object.defineProperty(fs2, "FileWriteStream", {
|
|
683
|
+
get: function() {
|
|
684
|
+
return FileWriteStream;
|
|
685
|
+
},
|
|
686
|
+
set: function(val) {
|
|
687
|
+
FileWriteStream = val;
|
|
688
|
+
},
|
|
689
|
+
enumerable: true,
|
|
690
|
+
configurable: true
|
|
691
|
+
});
|
|
692
|
+
function ReadStream(path, options) {
|
|
693
|
+
if (this instanceof ReadStream)
|
|
694
|
+
return fs$ReadStream.apply(this, arguments), this;
|
|
695
|
+
else
|
|
696
|
+
return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
|
|
697
|
+
}
|
|
698
|
+
function ReadStream$open() {
|
|
699
|
+
var that = this;
|
|
700
|
+
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
701
|
+
if (err) {
|
|
702
|
+
if (that.autoClose)
|
|
703
|
+
that.destroy();
|
|
704
|
+
that.emit("error", err);
|
|
705
|
+
} else {
|
|
706
|
+
that.fd = fd;
|
|
707
|
+
that.emit("open", fd);
|
|
708
|
+
that.read();
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
function WriteStream(path, options) {
|
|
713
|
+
if (this instanceof WriteStream)
|
|
714
|
+
return fs$WriteStream.apply(this, arguments), this;
|
|
715
|
+
else
|
|
716
|
+
return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
|
|
717
|
+
}
|
|
718
|
+
function WriteStream$open() {
|
|
719
|
+
var that = this;
|
|
720
|
+
open(that.path, that.flags, that.mode, function(err, fd) {
|
|
721
|
+
if (err) {
|
|
722
|
+
that.destroy();
|
|
723
|
+
that.emit("error", err);
|
|
724
|
+
} else {
|
|
725
|
+
that.fd = fd;
|
|
726
|
+
that.emit("open", fd);
|
|
727
|
+
}
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
function createReadStream(path, options) {
|
|
731
|
+
return new fs2.ReadStream(path, options);
|
|
732
|
+
}
|
|
733
|
+
function createWriteStream(path, options) {
|
|
734
|
+
return new fs2.WriteStream(path, options);
|
|
735
|
+
}
|
|
736
|
+
var fs$open = fs2.open;
|
|
737
|
+
fs2.open = open;
|
|
738
|
+
function open(path, flags, mode, cb) {
|
|
739
|
+
if (typeof mode === "function")
|
|
740
|
+
cb = mode, mode = null;
|
|
741
|
+
return go$open(path, flags, mode, cb);
|
|
742
|
+
function go$open(path2, flags2, mode2, cb2, startTime) {
|
|
743
|
+
return fs$open(path2, flags2, mode2, function(err, fd) {
|
|
744
|
+
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
|
|
745
|
+
enqueue([go$open, [path2, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
|
|
746
|
+
else {
|
|
747
|
+
if (typeof cb2 === "function")
|
|
748
|
+
cb2.apply(this, arguments);
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return fs2;
|
|
754
|
+
}
|
|
755
|
+
function enqueue(elem) {
|
|
756
|
+
debug("ENQUEUE", elem[0].name, elem[1]);
|
|
757
|
+
fs[gracefulQueue].push(elem);
|
|
758
|
+
retry();
|
|
759
|
+
}
|
|
760
|
+
var retryTimer;
|
|
761
|
+
function resetQueue() {
|
|
762
|
+
var now = Date.now();
|
|
763
|
+
for (var i = 0; i < fs[gracefulQueue].length; ++i) {
|
|
764
|
+
if (fs[gracefulQueue][i].length > 2) {
|
|
765
|
+
fs[gracefulQueue][i][3] = now;
|
|
766
|
+
fs[gracefulQueue][i][4] = now;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
retry();
|
|
770
|
+
}
|
|
771
|
+
function retry() {
|
|
772
|
+
clearTimeout(retryTimer);
|
|
773
|
+
retryTimer = void 0;
|
|
774
|
+
if (fs[gracefulQueue].length === 0)
|
|
775
|
+
return;
|
|
776
|
+
var elem = fs[gracefulQueue].shift();
|
|
777
|
+
var fn = elem[0];
|
|
778
|
+
var args = elem[1];
|
|
779
|
+
var err = elem[2];
|
|
780
|
+
var startTime = elem[3];
|
|
781
|
+
var lastTime = elem[4];
|
|
782
|
+
if (startTime === void 0) {
|
|
783
|
+
debug("RETRY", fn.name, args);
|
|
784
|
+
fn.apply(null, args);
|
|
785
|
+
} else if (Date.now() - startTime >= 6e4) {
|
|
786
|
+
debug("TIMEOUT", fn.name, args);
|
|
787
|
+
var cb = args.pop();
|
|
788
|
+
if (typeof cb === "function")
|
|
789
|
+
cb.call(null, err);
|
|
790
|
+
} else {
|
|
791
|
+
var sinceAttempt = Date.now() - lastTime;
|
|
792
|
+
var sinceStart = Math.max(lastTime - startTime, 1);
|
|
793
|
+
var desiredDelay = Math.min(sinceStart * 1.2, 100);
|
|
794
|
+
if (sinceAttempt >= desiredDelay) {
|
|
795
|
+
debug("RETRY", fn.name, args);
|
|
796
|
+
fn.apply(null, args.concat([startTime]));
|
|
797
|
+
} else {
|
|
798
|
+
fs[gracefulQueue].push(elem);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
if (retryTimer === void 0) {
|
|
802
|
+
retryTimer = setTimeout(retry, 0);
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
|
|
808
|
+
// node_modules/proper-lockfile/node_modules/retry/lib/retry_operation.js
|
|
809
|
+
var require_retry_operation = __commonJS({
|
|
810
|
+
"node_modules/proper-lockfile/node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
811
|
+
function RetryOperation(timeouts, options) {
|
|
812
|
+
if (typeof options === "boolean") {
|
|
813
|
+
options = { forever: options };
|
|
814
|
+
}
|
|
815
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
816
|
+
this._timeouts = timeouts;
|
|
817
|
+
this._options = options || {};
|
|
818
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
819
|
+
this._fn = null;
|
|
820
|
+
this._errors = [];
|
|
821
|
+
this._attempts = 1;
|
|
822
|
+
this._operationTimeout = null;
|
|
823
|
+
this._operationTimeoutCb = null;
|
|
824
|
+
this._timeout = null;
|
|
825
|
+
this._operationStart = null;
|
|
826
|
+
if (this._options.forever) {
|
|
827
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
module.exports = RetryOperation;
|
|
831
|
+
RetryOperation.prototype.reset = function() {
|
|
832
|
+
this._attempts = 1;
|
|
833
|
+
this._timeouts = this._originalTimeouts;
|
|
834
|
+
};
|
|
835
|
+
RetryOperation.prototype.stop = function() {
|
|
836
|
+
if (this._timeout) {
|
|
837
|
+
clearTimeout(this._timeout);
|
|
838
|
+
}
|
|
839
|
+
this._timeouts = [];
|
|
840
|
+
this._cachedTimeouts = null;
|
|
841
|
+
};
|
|
842
|
+
RetryOperation.prototype.retry = function(err) {
|
|
843
|
+
if (this._timeout) {
|
|
844
|
+
clearTimeout(this._timeout);
|
|
845
|
+
}
|
|
846
|
+
if (!err) {
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
850
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
851
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
852
|
+
return false;
|
|
853
|
+
}
|
|
854
|
+
this._errors.push(err);
|
|
855
|
+
var timeout = this._timeouts.shift();
|
|
856
|
+
if (timeout === void 0) {
|
|
857
|
+
if (this._cachedTimeouts) {
|
|
858
|
+
this._errors.splice(this._errors.length - 1, this._errors.length);
|
|
859
|
+
this._timeouts = this._cachedTimeouts.slice(0);
|
|
860
|
+
timeout = this._timeouts.shift();
|
|
861
|
+
} else {
|
|
862
|
+
return false;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
var self = this;
|
|
866
|
+
var timer = setTimeout(function() {
|
|
867
|
+
self._attempts++;
|
|
868
|
+
if (self._operationTimeoutCb) {
|
|
869
|
+
self._timeout = setTimeout(function() {
|
|
870
|
+
self._operationTimeoutCb(self._attempts);
|
|
871
|
+
}, self._operationTimeout);
|
|
872
|
+
if (self._options.unref) {
|
|
873
|
+
self._timeout.unref();
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
self._fn(self._attempts);
|
|
877
|
+
}, timeout);
|
|
878
|
+
if (this._options.unref) {
|
|
879
|
+
timer.unref();
|
|
880
|
+
}
|
|
881
|
+
return true;
|
|
882
|
+
};
|
|
883
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
884
|
+
this._fn = fn;
|
|
885
|
+
if (timeoutOps) {
|
|
886
|
+
if (timeoutOps.timeout) {
|
|
887
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
888
|
+
}
|
|
889
|
+
if (timeoutOps.cb) {
|
|
890
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
var self = this;
|
|
894
|
+
if (this._operationTimeoutCb) {
|
|
895
|
+
this._timeout = setTimeout(function() {
|
|
896
|
+
self._operationTimeoutCb();
|
|
897
|
+
}, self._operationTimeout);
|
|
898
|
+
}
|
|
899
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
900
|
+
this._fn(this._attempts);
|
|
901
|
+
};
|
|
902
|
+
RetryOperation.prototype.try = function(fn) {
|
|
903
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
904
|
+
this.attempt(fn);
|
|
905
|
+
};
|
|
906
|
+
RetryOperation.prototype.start = function(fn) {
|
|
907
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
908
|
+
this.attempt(fn);
|
|
909
|
+
};
|
|
910
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
911
|
+
RetryOperation.prototype.errors = function() {
|
|
912
|
+
return this._errors;
|
|
913
|
+
};
|
|
914
|
+
RetryOperation.prototype.attempts = function() {
|
|
915
|
+
return this._attempts;
|
|
916
|
+
};
|
|
917
|
+
RetryOperation.prototype.mainError = function() {
|
|
918
|
+
if (this._errors.length === 0) {
|
|
919
|
+
return null;
|
|
920
|
+
}
|
|
921
|
+
var counts = {};
|
|
922
|
+
var mainError = null;
|
|
923
|
+
var mainErrorCount = 0;
|
|
924
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
925
|
+
var error = this._errors[i];
|
|
926
|
+
var message = error.message;
|
|
927
|
+
var count = (counts[message] || 0) + 1;
|
|
928
|
+
counts[message] = count;
|
|
929
|
+
if (count >= mainErrorCount) {
|
|
930
|
+
mainError = error;
|
|
931
|
+
mainErrorCount = count;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
return mainError;
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
// node_modules/proper-lockfile/node_modules/retry/lib/retry.js
|
|
940
|
+
var require_retry = __commonJS({
|
|
941
|
+
"node_modules/proper-lockfile/node_modules/retry/lib/retry.js"(exports) {
|
|
942
|
+
var RetryOperation = require_retry_operation();
|
|
943
|
+
exports.operation = function(options) {
|
|
944
|
+
var timeouts = exports.timeouts(options);
|
|
945
|
+
return new RetryOperation(timeouts, {
|
|
946
|
+
forever: options && options.forever,
|
|
947
|
+
unref: options && options.unref,
|
|
948
|
+
maxRetryTime: options && options.maxRetryTime
|
|
949
|
+
});
|
|
950
|
+
};
|
|
951
|
+
exports.timeouts = function(options) {
|
|
952
|
+
if (options instanceof Array) {
|
|
953
|
+
return [].concat(options);
|
|
954
|
+
}
|
|
955
|
+
var opts = {
|
|
956
|
+
retries: 10,
|
|
957
|
+
factor: 2,
|
|
958
|
+
minTimeout: 1 * 1e3,
|
|
959
|
+
maxTimeout: Infinity,
|
|
960
|
+
randomize: false
|
|
961
|
+
};
|
|
962
|
+
for (var key in options) {
|
|
963
|
+
opts[key] = options[key];
|
|
964
|
+
}
|
|
965
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
966
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
967
|
+
}
|
|
968
|
+
var timeouts = [];
|
|
969
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
970
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
971
|
+
}
|
|
972
|
+
if (options && options.forever && !timeouts.length) {
|
|
973
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
974
|
+
}
|
|
975
|
+
timeouts.sort(function(a, b) {
|
|
976
|
+
return a - b;
|
|
977
|
+
});
|
|
978
|
+
return timeouts;
|
|
979
|
+
};
|
|
980
|
+
exports.createTimeout = function(attempt, opts) {
|
|
981
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
982
|
+
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
|
|
983
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
984
|
+
return timeout;
|
|
985
|
+
};
|
|
986
|
+
exports.wrap = function(obj, options, methods) {
|
|
987
|
+
if (options instanceof Array) {
|
|
988
|
+
methods = options;
|
|
989
|
+
options = null;
|
|
990
|
+
}
|
|
991
|
+
if (!methods) {
|
|
992
|
+
methods = [];
|
|
993
|
+
for (var key in obj) {
|
|
994
|
+
if (typeof obj[key] === "function") {
|
|
995
|
+
methods.push(key);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
for (var i = 0; i < methods.length; i++) {
|
|
1000
|
+
var method = methods[i];
|
|
1001
|
+
var original = obj[method];
|
|
1002
|
+
obj[method] = function retryWrapper(original2) {
|
|
1003
|
+
var op = exports.operation(options);
|
|
1004
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
1005
|
+
var callback = args.pop();
|
|
1006
|
+
args.push(function(err) {
|
|
1007
|
+
if (op.retry(err)) {
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
if (err) {
|
|
1011
|
+
arguments[0] = op.mainError();
|
|
1012
|
+
}
|
|
1013
|
+
callback.apply(this, arguments);
|
|
1014
|
+
});
|
|
1015
|
+
op.attempt(function() {
|
|
1016
|
+
original2.apply(obj, args);
|
|
1017
|
+
});
|
|
1018
|
+
}.bind(obj, original);
|
|
1019
|
+
obj[method].options = options;
|
|
1020
|
+
}
|
|
1021
|
+
};
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
|
|
1025
|
+
// node_modules/proper-lockfile/node_modules/retry/index.js
|
|
1026
|
+
var require_retry2 = __commonJS({
|
|
1027
|
+
"node_modules/proper-lockfile/node_modules/retry/index.js"(exports, module) {
|
|
1028
|
+
module.exports = require_retry();
|
|
1029
|
+
}
|
|
1030
|
+
});
|
|
1031
|
+
|
|
1032
|
+
// node_modules/proper-lockfile/node_modules/signal-exit/signals.js
|
|
1033
|
+
var require_signals = __commonJS({
|
|
1034
|
+
"node_modules/proper-lockfile/node_modules/signal-exit/signals.js"(exports, module) {
|
|
1035
|
+
module.exports = [
|
|
1036
|
+
"SIGABRT",
|
|
1037
|
+
"SIGALRM",
|
|
1038
|
+
"SIGHUP",
|
|
1039
|
+
"SIGINT",
|
|
1040
|
+
"SIGTERM"
|
|
1041
|
+
];
|
|
1042
|
+
if (process.platform !== "win32") {
|
|
1043
|
+
module.exports.push(
|
|
1044
|
+
"SIGVTALRM",
|
|
1045
|
+
"SIGXCPU",
|
|
1046
|
+
"SIGXFSZ",
|
|
1047
|
+
"SIGUSR2",
|
|
1048
|
+
"SIGTRAP",
|
|
1049
|
+
"SIGSYS",
|
|
1050
|
+
"SIGQUIT",
|
|
1051
|
+
"SIGIOT"
|
|
1052
|
+
// should detect profiler and enable/disable accordingly.
|
|
1053
|
+
// see #21
|
|
1054
|
+
// 'SIGPROF'
|
|
1055
|
+
);
|
|
1056
|
+
}
|
|
1057
|
+
if (process.platform === "linux") {
|
|
1058
|
+
module.exports.push(
|
|
1059
|
+
"SIGIO",
|
|
1060
|
+
"SIGPOLL",
|
|
1061
|
+
"SIGPWR",
|
|
1062
|
+
"SIGSTKFLT",
|
|
1063
|
+
"SIGUNUSED"
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
// node_modules/proper-lockfile/node_modules/signal-exit/index.js
|
|
1070
|
+
var require_signal_exit = __commonJS({
|
|
1071
|
+
"node_modules/proper-lockfile/node_modules/signal-exit/index.js"(exports, module) {
|
|
1072
|
+
var process2 = global.process;
|
|
1073
|
+
var processOk = function(process3) {
|
|
1074
|
+
return process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
|
|
1075
|
+
};
|
|
1076
|
+
if (!processOk(process2)) {
|
|
1077
|
+
module.exports = function() {
|
|
1078
|
+
return function() {
|
|
1079
|
+
};
|
|
1080
|
+
};
|
|
1081
|
+
} else {
|
|
1082
|
+
assert = __require("assert");
|
|
1083
|
+
signals = require_signals();
|
|
1084
|
+
isWin = /^win/i.test(process2.platform);
|
|
1085
|
+
EE = __require("events");
|
|
1086
|
+
if (typeof EE !== "function") {
|
|
1087
|
+
EE = EE.EventEmitter;
|
|
1088
|
+
}
|
|
1089
|
+
if (process2.__signal_exit_emitter__) {
|
|
1090
|
+
emitter = process2.__signal_exit_emitter__;
|
|
1091
|
+
} else {
|
|
1092
|
+
emitter = process2.__signal_exit_emitter__ = new EE();
|
|
1093
|
+
emitter.count = 0;
|
|
1094
|
+
emitter.emitted = {};
|
|
1095
|
+
}
|
|
1096
|
+
if (!emitter.infinite) {
|
|
1097
|
+
emitter.setMaxListeners(Infinity);
|
|
1098
|
+
emitter.infinite = true;
|
|
1099
|
+
}
|
|
1100
|
+
module.exports = function(cb, opts) {
|
|
1101
|
+
if (!processOk(global.process)) {
|
|
1102
|
+
return function() {
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
|
|
1106
|
+
if (loaded === false) {
|
|
1107
|
+
load();
|
|
1108
|
+
}
|
|
1109
|
+
var ev = "exit";
|
|
1110
|
+
if (opts && opts.alwaysLast) {
|
|
1111
|
+
ev = "afterexit";
|
|
1112
|
+
}
|
|
1113
|
+
var remove = function() {
|
|
1114
|
+
emitter.removeListener(ev, cb);
|
|
1115
|
+
if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) {
|
|
1116
|
+
unload();
|
|
1117
|
+
}
|
|
1118
|
+
};
|
|
1119
|
+
emitter.on(ev, cb);
|
|
1120
|
+
return remove;
|
|
1121
|
+
};
|
|
1122
|
+
unload = function unload2() {
|
|
1123
|
+
if (!loaded || !processOk(global.process)) {
|
|
1124
|
+
return;
|
|
1125
|
+
}
|
|
1126
|
+
loaded = false;
|
|
1127
|
+
signals.forEach(function(sig) {
|
|
1128
|
+
try {
|
|
1129
|
+
process2.removeListener(sig, sigListeners[sig]);
|
|
1130
|
+
} catch (er) {
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
process2.emit = originalProcessEmit;
|
|
1134
|
+
process2.reallyExit = originalProcessReallyExit;
|
|
1135
|
+
emitter.count -= 1;
|
|
1136
|
+
};
|
|
1137
|
+
module.exports.unload = unload;
|
|
1138
|
+
emit = function emit2(event, code, signal) {
|
|
1139
|
+
if (emitter.emitted[event]) {
|
|
1140
|
+
return;
|
|
1141
|
+
}
|
|
1142
|
+
emitter.emitted[event] = true;
|
|
1143
|
+
emitter.emit(event, code, signal);
|
|
1144
|
+
};
|
|
1145
|
+
sigListeners = {};
|
|
1146
|
+
signals.forEach(function(sig) {
|
|
1147
|
+
sigListeners[sig] = function listener() {
|
|
1148
|
+
if (!processOk(global.process)) {
|
|
1149
|
+
return;
|
|
1150
|
+
}
|
|
1151
|
+
var listeners = process2.listeners(sig);
|
|
1152
|
+
if (listeners.length === emitter.count) {
|
|
1153
|
+
unload();
|
|
1154
|
+
emit("exit", null, sig);
|
|
1155
|
+
emit("afterexit", null, sig);
|
|
1156
|
+
if (isWin && sig === "SIGHUP") {
|
|
1157
|
+
sig = "SIGINT";
|
|
1158
|
+
}
|
|
1159
|
+
process2.kill(process2.pid, sig);
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
});
|
|
1163
|
+
module.exports.signals = function() {
|
|
1164
|
+
return signals;
|
|
1165
|
+
};
|
|
1166
|
+
loaded = false;
|
|
1167
|
+
load = function load2() {
|
|
1168
|
+
if (loaded || !processOk(global.process)) {
|
|
1169
|
+
return;
|
|
1170
|
+
}
|
|
1171
|
+
loaded = true;
|
|
1172
|
+
emitter.count += 1;
|
|
1173
|
+
signals = signals.filter(function(sig) {
|
|
1174
|
+
try {
|
|
1175
|
+
process2.on(sig, sigListeners[sig]);
|
|
1176
|
+
return true;
|
|
1177
|
+
} catch (er) {
|
|
1178
|
+
return false;
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
process2.emit = processEmit;
|
|
1182
|
+
process2.reallyExit = processReallyExit;
|
|
1183
|
+
};
|
|
1184
|
+
module.exports.load = load;
|
|
1185
|
+
originalProcessReallyExit = process2.reallyExit;
|
|
1186
|
+
processReallyExit = function processReallyExit2(code) {
|
|
1187
|
+
if (!processOk(global.process)) {
|
|
1188
|
+
return;
|
|
1189
|
+
}
|
|
1190
|
+
process2.exitCode = code || /* istanbul ignore next */
|
|
1191
|
+
0;
|
|
1192
|
+
emit("exit", process2.exitCode, null);
|
|
1193
|
+
emit("afterexit", process2.exitCode, null);
|
|
1194
|
+
originalProcessReallyExit.call(process2, process2.exitCode);
|
|
1195
|
+
};
|
|
1196
|
+
originalProcessEmit = process2.emit;
|
|
1197
|
+
processEmit = function processEmit2(ev, arg) {
|
|
1198
|
+
if (ev === "exit" && processOk(global.process)) {
|
|
1199
|
+
if (arg !== void 0) {
|
|
1200
|
+
process2.exitCode = arg;
|
|
1201
|
+
}
|
|
1202
|
+
var ret = originalProcessEmit.apply(this, arguments);
|
|
1203
|
+
emit("exit", process2.exitCode, null);
|
|
1204
|
+
emit("afterexit", process2.exitCode, null);
|
|
1205
|
+
return ret;
|
|
1206
|
+
} else {
|
|
1207
|
+
return originalProcessEmit.apply(this, arguments);
|
|
1208
|
+
}
|
|
1209
|
+
};
|
|
1210
|
+
}
|
|
1211
|
+
var assert;
|
|
1212
|
+
var signals;
|
|
1213
|
+
var isWin;
|
|
1214
|
+
var EE;
|
|
1215
|
+
var emitter;
|
|
1216
|
+
var unload;
|
|
1217
|
+
var emit;
|
|
1218
|
+
var sigListeners;
|
|
1219
|
+
var loaded;
|
|
1220
|
+
var load;
|
|
1221
|
+
var originalProcessReallyExit;
|
|
1222
|
+
var processReallyExit;
|
|
1223
|
+
var originalProcessEmit;
|
|
1224
|
+
var processEmit;
|
|
1225
|
+
}
|
|
1226
|
+
});
|
|
1227
|
+
|
|
1228
|
+
// node_modules/proper-lockfile/lib/mtime-precision.js
|
|
1229
|
+
var require_mtime_precision = __commonJS({
|
|
1230
|
+
"node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
|
|
1231
|
+
"use strict";
|
|
1232
|
+
var cacheSymbol = /* @__PURE__ */ Symbol();
|
|
1233
|
+
function probe(file, fs, callback) {
|
|
1234
|
+
const cachedPrecision = fs[cacheSymbol];
|
|
1235
|
+
if (cachedPrecision) {
|
|
1236
|
+
return fs.stat(file, (err, stat) => {
|
|
1237
|
+
if (err) {
|
|
1238
|
+
return callback(err);
|
|
1239
|
+
}
|
|
1240
|
+
callback(null, stat.mtime, cachedPrecision);
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
|
|
1244
|
+
fs.utimes(file, mtime, mtime, (err) => {
|
|
1245
|
+
if (err) {
|
|
1246
|
+
return callback(err);
|
|
1247
|
+
}
|
|
1248
|
+
fs.stat(file, (err2, stat) => {
|
|
1249
|
+
if (err2) {
|
|
1250
|
+
return callback(err2);
|
|
1251
|
+
}
|
|
1252
|
+
const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
|
|
1253
|
+
Object.defineProperty(fs, cacheSymbol, { value: precision });
|
|
1254
|
+
callback(null, stat.mtime, precision);
|
|
1255
|
+
});
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
function getMtime(precision) {
|
|
1259
|
+
let now = Date.now();
|
|
1260
|
+
if (precision === "s") {
|
|
1261
|
+
now = Math.ceil(now / 1e3) * 1e3;
|
|
1262
|
+
}
|
|
1263
|
+
return new Date(now);
|
|
1264
|
+
}
|
|
1265
|
+
module.exports.probe = probe;
|
|
1266
|
+
module.exports.getMtime = getMtime;
|
|
1267
|
+
}
|
|
1268
|
+
});
|
|
1269
|
+
|
|
1270
|
+
// node_modules/proper-lockfile/lib/lockfile.js
|
|
1271
|
+
var require_lockfile = __commonJS({
|
|
1272
|
+
"node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
|
|
1273
|
+
"use strict";
|
|
1274
|
+
var path = __require("path");
|
|
1275
|
+
var fs = require_graceful_fs();
|
|
1276
|
+
var retry = require_retry2();
|
|
1277
|
+
var onExit = require_signal_exit();
|
|
1278
|
+
var mtimePrecision = require_mtime_precision();
|
|
1279
|
+
var locks = {};
|
|
1280
|
+
function getLockFile(file, options) {
|
|
1281
|
+
return options.lockfilePath || `${file}.lock`;
|
|
1282
|
+
}
|
|
1283
|
+
function resolveCanonicalPath(file, options, callback) {
|
|
1284
|
+
if (!options.realpath) {
|
|
1285
|
+
return callback(null, path.resolve(file));
|
|
1286
|
+
}
|
|
1287
|
+
options.fs.realpath(file, callback);
|
|
1288
|
+
}
|
|
1289
|
+
function acquireLock(file, options, callback) {
|
|
1290
|
+
const lockfilePath = getLockFile(file, options);
|
|
1291
|
+
options.fs.mkdir(lockfilePath, (err) => {
|
|
1292
|
+
if (!err) {
|
|
1293
|
+
return mtimePrecision.probe(lockfilePath, options.fs, (err2, mtime, mtimePrecision2) => {
|
|
1294
|
+
if (err2) {
|
|
1295
|
+
options.fs.rmdir(lockfilePath, () => {
|
|
1296
|
+
});
|
|
1297
|
+
return callback(err2);
|
|
1298
|
+
}
|
|
1299
|
+
callback(null, mtime, mtimePrecision2);
|
|
1300
|
+
});
|
|
1301
|
+
}
|
|
1302
|
+
if (err.code !== "EEXIST") {
|
|
1303
|
+
return callback(err);
|
|
1304
|
+
}
|
|
1305
|
+
if (options.stale <= 0) {
|
|
1306
|
+
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
|
|
1307
|
+
}
|
|
1308
|
+
options.fs.stat(lockfilePath, (err2, stat) => {
|
|
1309
|
+
if (err2) {
|
|
1310
|
+
if (err2.code === "ENOENT") {
|
|
1311
|
+
return acquireLock(file, { ...options, stale: 0 }, callback);
|
|
1312
|
+
}
|
|
1313
|
+
return callback(err2);
|
|
1314
|
+
}
|
|
1315
|
+
if (!isLockStale(stat, options)) {
|
|
1316
|
+
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
|
|
1317
|
+
}
|
|
1318
|
+
removeLock(file, options, (err3) => {
|
|
1319
|
+
if (err3) {
|
|
1320
|
+
return callback(err3);
|
|
1321
|
+
}
|
|
1322
|
+
acquireLock(file, { ...options, stale: 0 }, callback);
|
|
1323
|
+
});
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
}
|
|
1327
|
+
function isLockStale(stat, options) {
|
|
1328
|
+
return stat.mtime.getTime() < Date.now() - options.stale;
|
|
1329
|
+
}
|
|
1330
|
+
function removeLock(file, options, callback) {
|
|
1331
|
+
options.fs.rmdir(getLockFile(file, options), (err) => {
|
|
1332
|
+
if (err && err.code !== "ENOENT") {
|
|
1333
|
+
return callback(err);
|
|
1334
|
+
}
|
|
1335
|
+
callback();
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
function updateLock(file, options) {
|
|
1339
|
+
const lock2 = locks[file];
|
|
1340
|
+
if (lock2.updateTimeout) {
|
|
1341
|
+
return;
|
|
1342
|
+
}
|
|
1343
|
+
lock2.updateDelay = lock2.updateDelay || options.update;
|
|
1344
|
+
lock2.updateTimeout = setTimeout(() => {
|
|
1345
|
+
lock2.updateTimeout = null;
|
|
1346
|
+
options.fs.stat(lock2.lockfilePath, (err, stat) => {
|
|
1347
|
+
const isOverThreshold = lock2.lastUpdate + options.stale < Date.now();
|
|
1348
|
+
if (err) {
|
|
1349
|
+
if (err.code === "ENOENT" || isOverThreshold) {
|
|
1350
|
+
return setLockAsCompromised(file, lock2, Object.assign(err, { code: "ECOMPROMISED" }));
|
|
1351
|
+
}
|
|
1352
|
+
lock2.updateDelay = 1e3;
|
|
1353
|
+
return updateLock(file, options);
|
|
1354
|
+
}
|
|
1355
|
+
const isMtimeOurs = lock2.mtime.getTime() === stat.mtime.getTime();
|
|
1356
|
+
if (!isMtimeOurs) {
|
|
1357
|
+
return setLockAsCompromised(
|
|
1358
|
+
file,
|
|
1359
|
+
lock2,
|
|
1360
|
+
Object.assign(
|
|
1361
|
+
new Error("Unable to update lock within the stale threshold"),
|
|
1362
|
+
{ code: "ECOMPROMISED" }
|
|
1363
|
+
)
|
|
1364
|
+
);
|
|
1365
|
+
}
|
|
1366
|
+
const mtime = mtimePrecision.getMtime(lock2.mtimePrecision);
|
|
1367
|
+
options.fs.utimes(lock2.lockfilePath, mtime, mtime, (err2) => {
|
|
1368
|
+
const isOverThreshold2 = lock2.lastUpdate + options.stale < Date.now();
|
|
1369
|
+
if (lock2.released) {
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
if (err2) {
|
|
1373
|
+
if (err2.code === "ENOENT" || isOverThreshold2) {
|
|
1374
|
+
return setLockAsCompromised(file, lock2, Object.assign(err2, { code: "ECOMPROMISED" }));
|
|
1375
|
+
}
|
|
1376
|
+
lock2.updateDelay = 1e3;
|
|
1377
|
+
return updateLock(file, options);
|
|
1378
|
+
}
|
|
1379
|
+
lock2.mtime = mtime;
|
|
1380
|
+
lock2.lastUpdate = Date.now();
|
|
1381
|
+
lock2.updateDelay = null;
|
|
1382
|
+
updateLock(file, options);
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
}, lock2.updateDelay);
|
|
1386
|
+
if (lock2.updateTimeout.unref) {
|
|
1387
|
+
lock2.updateTimeout.unref();
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
function setLockAsCompromised(file, lock2, err) {
|
|
1391
|
+
lock2.released = true;
|
|
1392
|
+
if (lock2.updateTimeout) {
|
|
1393
|
+
clearTimeout(lock2.updateTimeout);
|
|
1394
|
+
}
|
|
1395
|
+
if (locks[file] === lock2) {
|
|
1396
|
+
delete locks[file];
|
|
1397
|
+
}
|
|
1398
|
+
lock2.options.onCompromised(err);
|
|
1399
|
+
}
|
|
1400
|
+
function lock(file, options, callback) {
|
|
1401
|
+
options = {
|
|
1402
|
+
stale: 1e4,
|
|
1403
|
+
update: null,
|
|
1404
|
+
realpath: true,
|
|
1405
|
+
retries: 0,
|
|
1406
|
+
fs,
|
|
1407
|
+
onCompromised: (err) => {
|
|
1408
|
+
throw err;
|
|
1409
|
+
},
|
|
1410
|
+
...options
|
|
1411
|
+
};
|
|
1412
|
+
options.retries = options.retries || 0;
|
|
1413
|
+
options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
|
|
1414
|
+
options.stale = Math.max(options.stale || 0, 2e3);
|
|
1415
|
+
options.update = options.update == null ? options.stale / 2 : options.update || 0;
|
|
1416
|
+
options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
|
|
1417
|
+
resolveCanonicalPath(file, options, (err, file2) => {
|
|
1418
|
+
if (err) {
|
|
1419
|
+
return callback(err);
|
|
1420
|
+
}
|
|
1421
|
+
const operation = retry.operation(options.retries);
|
|
1422
|
+
operation.attempt(() => {
|
|
1423
|
+
acquireLock(file2, options, (err2, mtime, mtimePrecision2) => {
|
|
1424
|
+
if (operation.retry(err2)) {
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
if (err2) {
|
|
1428
|
+
return callback(operation.mainError());
|
|
1429
|
+
}
|
|
1430
|
+
const lock2 = locks[file2] = {
|
|
1431
|
+
lockfilePath: getLockFile(file2, options),
|
|
1432
|
+
mtime,
|
|
1433
|
+
mtimePrecision: mtimePrecision2,
|
|
1434
|
+
options,
|
|
1435
|
+
lastUpdate: Date.now()
|
|
1436
|
+
};
|
|
1437
|
+
updateLock(file2, options);
|
|
1438
|
+
callback(null, (releasedCallback) => {
|
|
1439
|
+
if (lock2.released) {
|
|
1440
|
+
return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
|
|
1441
|
+
}
|
|
1442
|
+
unlock(file2, { ...options, realpath: false }, releasedCallback);
|
|
1443
|
+
});
|
|
1444
|
+
});
|
|
1445
|
+
});
|
|
1446
|
+
});
|
|
1447
|
+
}
|
|
1448
|
+
function unlock(file, options, callback) {
|
|
1449
|
+
options = {
|
|
1450
|
+
fs,
|
|
1451
|
+
realpath: true,
|
|
1452
|
+
...options
|
|
1453
|
+
};
|
|
1454
|
+
resolveCanonicalPath(file, options, (err, file2) => {
|
|
1455
|
+
if (err) {
|
|
1456
|
+
return callback(err);
|
|
1457
|
+
}
|
|
1458
|
+
const lock2 = locks[file2];
|
|
1459
|
+
if (!lock2) {
|
|
1460
|
+
return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
|
|
1461
|
+
}
|
|
1462
|
+
lock2.updateTimeout && clearTimeout(lock2.updateTimeout);
|
|
1463
|
+
lock2.released = true;
|
|
1464
|
+
delete locks[file2];
|
|
1465
|
+
removeLock(file2, options, callback);
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
function check(file, options, callback) {
|
|
1469
|
+
options = {
|
|
1470
|
+
stale: 1e4,
|
|
1471
|
+
realpath: true,
|
|
1472
|
+
fs,
|
|
1473
|
+
...options
|
|
1474
|
+
};
|
|
1475
|
+
options.stale = Math.max(options.stale || 0, 2e3);
|
|
1476
|
+
resolveCanonicalPath(file, options, (err, file2) => {
|
|
1477
|
+
if (err) {
|
|
1478
|
+
return callback(err);
|
|
1479
|
+
}
|
|
1480
|
+
options.fs.stat(getLockFile(file2, options), (err2, stat) => {
|
|
1481
|
+
if (err2) {
|
|
1482
|
+
return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
|
|
1483
|
+
}
|
|
1484
|
+
return callback(null, !isLockStale(stat, options));
|
|
1485
|
+
});
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1488
|
+
function getLocks() {
|
|
1489
|
+
return locks;
|
|
1490
|
+
}
|
|
1491
|
+
onExit(() => {
|
|
1492
|
+
for (const file in locks) {
|
|
1493
|
+
const options = locks[file].options;
|
|
1494
|
+
try {
|
|
1495
|
+
options.fs.rmdirSync(getLockFile(file, options));
|
|
1496
|
+
} catch (e) {
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
});
|
|
1500
|
+
module.exports.lock = lock;
|
|
1501
|
+
module.exports.unlock = unlock;
|
|
1502
|
+
module.exports.check = check;
|
|
1503
|
+
module.exports.getLocks = getLocks;
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1506
|
+
|
|
1507
|
+
// node_modules/proper-lockfile/lib/adapter.js
|
|
1508
|
+
var require_adapter = __commonJS({
|
|
1509
|
+
"node_modules/proper-lockfile/lib/adapter.js"(exports, module) {
|
|
1510
|
+
"use strict";
|
|
1511
|
+
var fs = require_graceful_fs();
|
|
1512
|
+
function createSyncFs(fs2) {
|
|
1513
|
+
const methods = ["mkdir", "realpath", "stat", "rmdir", "utimes"];
|
|
1514
|
+
const newFs = { ...fs2 };
|
|
1515
|
+
methods.forEach((method) => {
|
|
1516
|
+
newFs[method] = (...args) => {
|
|
1517
|
+
const callback = args.pop();
|
|
1518
|
+
let ret;
|
|
1519
|
+
try {
|
|
1520
|
+
ret = fs2[`${method}Sync`](...args);
|
|
1521
|
+
} catch (err) {
|
|
1522
|
+
return callback(err);
|
|
1523
|
+
}
|
|
1524
|
+
callback(null, ret);
|
|
1525
|
+
};
|
|
1526
|
+
});
|
|
1527
|
+
return newFs;
|
|
1528
|
+
}
|
|
1529
|
+
function toPromise(method) {
|
|
1530
|
+
return (...args) => new Promise((resolve, reject) => {
|
|
1531
|
+
args.push((err, result) => {
|
|
1532
|
+
if (err) {
|
|
1533
|
+
reject(err);
|
|
1534
|
+
} else {
|
|
1535
|
+
resolve(result);
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1538
|
+
method(...args);
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
function toSync(method) {
|
|
1542
|
+
return (...args) => {
|
|
1543
|
+
let err;
|
|
1544
|
+
let result;
|
|
1545
|
+
args.push((_err, _result) => {
|
|
1546
|
+
err = _err;
|
|
1547
|
+
result = _result;
|
|
1548
|
+
});
|
|
1549
|
+
method(...args);
|
|
1550
|
+
if (err) {
|
|
1551
|
+
throw err;
|
|
1552
|
+
}
|
|
1553
|
+
return result;
|
|
1554
|
+
};
|
|
1555
|
+
}
|
|
1556
|
+
function toSyncOptions(options) {
|
|
1557
|
+
options = { ...options };
|
|
1558
|
+
options.fs = createSyncFs(options.fs || fs);
|
|
1559
|
+
if (typeof options.retries === "number" && options.retries > 0 || options.retries && typeof options.retries.retries === "number" && options.retries.retries > 0) {
|
|
1560
|
+
throw Object.assign(new Error("Cannot use retries with the sync api"), { code: "ESYNC" });
|
|
1561
|
+
}
|
|
1562
|
+
return options;
|
|
1563
|
+
}
|
|
1564
|
+
module.exports = {
|
|
1565
|
+
toPromise,
|
|
1566
|
+
toSync,
|
|
1567
|
+
toSyncOptions
|
|
1568
|
+
};
|
|
1569
|
+
}
|
|
1570
|
+
});
|
|
1571
|
+
|
|
1572
|
+
// node_modules/proper-lockfile/index.js
|
|
1573
|
+
var require_proper_lockfile = __commonJS({
|
|
1574
|
+
"node_modules/proper-lockfile/index.js"(exports, module) {
|
|
1575
|
+
"use strict";
|
|
1576
|
+
var lockfile2 = require_lockfile();
|
|
1577
|
+
var { toPromise, toSync, toSyncOptions } = require_adapter();
|
|
1578
|
+
async function lock(file, options) {
|
|
1579
|
+
const release = await toPromise(lockfile2.lock)(file, options);
|
|
1580
|
+
return toPromise(release);
|
|
1581
|
+
}
|
|
1582
|
+
function lockSync(file, options) {
|
|
1583
|
+
const release = toSync(lockfile2.lock)(file, toSyncOptions(options));
|
|
1584
|
+
return toSync(release);
|
|
1585
|
+
}
|
|
1586
|
+
function unlock(file, options) {
|
|
1587
|
+
return toPromise(lockfile2.unlock)(file, options);
|
|
1588
|
+
}
|
|
1589
|
+
function unlockSync(file, options) {
|
|
1590
|
+
return toSync(lockfile2.unlock)(file, toSyncOptions(options));
|
|
1591
|
+
}
|
|
1592
|
+
function check(file, options) {
|
|
1593
|
+
return toPromise(lockfile2.check)(file, options);
|
|
1594
|
+
}
|
|
1595
|
+
function checkSync(file, options) {
|
|
1596
|
+
return toSync(lockfile2.check)(file, toSyncOptions(options));
|
|
1597
|
+
}
|
|
1598
|
+
module.exports = lock;
|
|
1599
|
+
module.exports.lock = lock;
|
|
1600
|
+
module.exports.unlock = unlock;
|
|
1601
|
+
module.exports.lockSync = lockSync;
|
|
1602
|
+
module.exports.unlockSync = unlockSync;
|
|
1603
|
+
module.exports.check = check;
|
|
1604
|
+
module.exports.checkSync = checkSync;
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
26
1607
|
|
|
27
1608
|
// node_modules/typebox/build/system/memory/memory.mjs
|
|
28
1609
|
var memory_exports = {};
|
|
@@ -1045,7 +2626,7 @@ function IsNumber3(value) {
|
|
|
1045
2626
|
}
|
|
1046
2627
|
|
|
1047
2628
|
// node_modules/typebox/build/type/types/symbol.mjs
|
|
1048
|
-
function
|
|
2629
|
+
function Symbol2(options) {
|
|
1049
2630
|
return memory_exports.Create({ "~kind": "Symbol" }, { type: "symbol" }, options);
|
|
1050
2631
|
}
|
|
1051
2632
|
function IsSymbol2(value) {
|
|
@@ -1607,7 +3188,7 @@ function KeywordNeverMapping(input) {
|
|
|
1607
3188
|
return Never();
|
|
1608
3189
|
}
|
|
1609
3190
|
function KeywordSymbolMapping(input) {
|
|
1610
|
-
return
|
|
3191
|
+
return Symbol2();
|
|
1611
3192
|
}
|
|
1612
3193
|
function KeywordVoidMapping(input) {
|
|
1613
3194
|
return Void();
|
|
@@ -3682,7 +5263,7 @@ function KeyOf2(type, options = {}) {
|
|
|
3682
5263
|
|
|
3683
5264
|
// node_modules/typebox/build/type/engine/keyof/from_any.mjs
|
|
3684
5265
|
function FromAny() {
|
|
3685
|
-
return Union([Number2(), String2(),
|
|
5266
|
+
return Union([Number2(), String2(), Symbol2()]);
|
|
3686
5267
|
}
|
|
3687
5268
|
|
|
3688
5269
|
// node_modules/typebox/build/type/engine/keyof/from_array.mjs
|
|
@@ -4414,7 +5995,7 @@ __export(typebox_exports, {
|
|
|
4414
5995
|
ReturnType: () => ReturnType,
|
|
4415
5996
|
Script: () => Script2,
|
|
4416
5997
|
String: () => String2,
|
|
4417
|
-
Symbol: () =>
|
|
5998
|
+
Symbol: () => Symbol2,
|
|
4418
5999
|
TemplateLiteral: () => TemplateLiteral2,
|
|
4419
6000
|
This: () => This,
|
|
4420
6001
|
Tuple: () => Tuple,
|
|
@@ -4545,8 +6126,8 @@ function piMcpTools(mcp) {
|
|
|
4545
6126
|
|
|
4546
6127
|
// src/backend/pi/index.ts
|
|
4547
6128
|
import { randomUUID } from "node:crypto";
|
|
4548
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
4549
|
-
import { join } from "node:path";
|
|
6129
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
6130
|
+
import { join as join2 } from "node:path";
|
|
4550
6131
|
|
|
4551
6132
|
// src/backend/pi/state.ts
|
|
4552
6133
|
var USER_MESSAGE_MAP = "flow-user-messages.json";
|
|
@@ -4555,7 +6136,7 @@ var USER_MESSAGE_MAP = "flow-user-messages.json";
|
|
|
4555
6136
|
import {
|
|
4556
6137
|
createAgentSession as createAgentSession2,
|
|
4557
6138
|
DefaultResourceLoader as DefaultResourceLoader2,
|
|
4558
|
-
getAgentDir as
|
|
6139
|
+
getAgentDir as getAgentDir3,
|
|
4559
6140
|
SessionManager as SessionManager2,
|
|
4560
6141
|
SettingsManager as SettingsManager2
|
|
4561
6142
|
} from "@earendil-works/pi-coding-agent";
|
|
@@ -4565,7 +6146,7 @@ import {
|
|
|
4565
6146
|
createAgentSession,
|
|
4566
6147
|
DefaultPackageManager,
|
|
4567
6148
|
DefaultResourceLoader,
|
|
4568
|
-
getAgentDir,
|
|
6149
|
+
getAgentDir as getAgentDir2,
|
|
4569
6150
|
SessionManager,
|
|
4570
6151
|
SettingsManager,
|
|
4571
6152
|
createReadToolDefinition,
|
|
@@ -4588,6 +6169,42 @@ function piAcceptsWorkflowEffort(model, effort) {
|
|
|
4588
6169
|
return levels.length === 0 ? effort === "off" : levels.includes(effort);
|
|
4589
6170
|
}
|
|
4590
6171
|
|
|
6172
|
+
// src/backend/pi/model-selection.ts
|
|
6173
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
6174
|
+
import { join } from "node:path";
|
|
6175
|
+
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
6176
|
+
|
|
6177
|
+
// src/backend/pi/model-config.ts
|
|
6178
|
+
function parsePiModelConfig(content) {
|
|
6179
|
+
return JSON.parse(content.replace(/^\uFEFF/, "").replace(/"(?:\\.|[^"\\])*"|\/\/[^\n]*/g, (match) => match.startsWith('"') ? match : "").replace(/"(?:\\.|[^"\\])*"|,(\s*[}\]])/g, (match, closing) => closing ?? match));
|
|
6180
|
+
}
|
|
6181
|
+
|
|
6182
|
+
// src/backend/pi/model-selection.ts
|
|
6183
|
+
var legacyAzure = "azure-openai-responses";
|
|
6184
|
+
function findPiModel(available, modelId, allowBareId = false, agentDir = getAgentDir()) {
|
|
6185
|
+
const canonicalId = modelId.startsWith(`${legacyAzure}/`) ? `azure/${modelId.slice(legacyAzure.length + 1)}` : modelId;
|
|
6186
|
+
if (canonicalId.startsWith("azure/")) {
|
|
6187
|
+
for (const name of ["auth.json", "models.json"]) {
|
|
6188
|
+
const path = join(agentDir, name);
|
|
6189
|
+
if (!existsSync(path)) continue;
|
|
6190
|
+
const content = readFileSync(path, "utf8");
|
|
6191
|
+
const data = name === "models.json" ? parsePiModelConfig(content) : JSON.parse(content.replace(/^\uFEFF/, ""));
|
|
6192
|
+
const providers = name === "models.json" ? data.providers : data;
|
|
6193
|
+
if (providers && Object.hasOwn(providers, legacyAzure) && !Object.hasOwn(providers, "azure")) {
|
|
6194
|
+
throw new Error(`Pi 1.6 renamed Provider ${legacyAzure} to azure. Rename its Provider key in ${path} to azure; keep the API name azure-openai-responses unchanged. Flow did not change this file or select another model.`);
|
|
6195
|
+
}
|
|
6196
|
+
}
|
|
6197
|
+
}
|
|
6198
|
+
const qualified = available.find((model) => (model.provider ? `${model.provider}/${model.id}` : model.id) === canonicalId);
|
|
6199
|
+
if (qualified || !allowBareId || canonicalId.startsWith("azure/")) return qualified;
|
|
6200
|
+
const bare = available.filter((model) => model.id === modelId);
|
|
6201
|
+
return bare.length === 1 ? bare[0] : void 0;
|
|
6202
|
+
}
|
|
6203
|
+
function piModelUnavailable(modelId, label = "Unknown model") {
|
|
6204
|
+
const azure = modelId.startsWith(`${legacyAzure}/`) || modelId.startsWith("azure/");
|
|
6205
|
+
return `${label}: ${modelId}. Select an available model explicitly; no replacement was used.${azure ? " Pi 1.6 uses Provider azure. Check the azure Provider keys in Pi auth.json and models.json, and confirm the exact model ID is still available. The API name remains azure-openai-responses." : ""}`;
|
|
6206
|
+
}
|
|
6207
|
+
|
|
4591
6208
|
// src/backend/pi/auto-compaction.ts
|
|
4592
6209
|
function piAutoCompaction(settings2, setting) {
|
|
4593
6210
|
const defaults = settings2.getCompactionSettings();
|
|
@@ -4612,8 +6229,8 @@ function compactionModelExtension(modelId, notice) {
|
|
|
4612
6229
|
return { name: "flow-compaction-model", hidden: true, factory: (pi) => {
|
|
4613
6230
|
pi.on("session_before_compact", async (event, ctx) => {
|
|
4614
6231
|
try {
|
|
4615
|
-
const model = ctx.modelRegistry.getAvailable()
|
|
4616
|
-
if (!model) throw new Error(
|
|
6232
|
+
const model = findPiModel(ctx.modelRegistry.getAvailable(), modelId);
|
|
6233
|
+
if (!model) throw new Error(piModelUnavailable(modelId, "Configured compaction model is unavailable"));
|
|
4617
6234
|
const auth = await ctx.modelRegistry.getApiKeyAndHeaders(model);
|
|
4618
6235
|
if (!auth.ok) throw new Error(auth.error);
|
|
4619
6236
|
const requestModel = auth.baseUrl ? { ...model, baseUrl: auth.baseUrl } : model;
|
|
@@ -4746,7 +6363,7 @@ var PiWork = class {
|
|
|
4746
6363
|
work.state = completion2.state;
|
|
4747
6364
|
work.result = completion2.result;
|
|
4748
6365
|
if (brief.type === "subagent") this.jobs.delete(id);
|
|
4749
|
-
this.emit({ ...brief, state: completion2.state });
|
|
6366
|
+
this.emit({ ...work.brief, state: completion2.state });
|
|
4750
6367
|
if (background && !this.disposed) this.completed(completion2);
|
|
4751
6368
|
return completion2;
|
|
4752
6369
|
});
|
|
@@ -4758,6 +6375,13 @@ var PiWork = class {
|
|
|
4758
6375
|
if (completion.state !== "complete") throw new Error(resultText(completion.result));
|
|
4759
6376
|
return completion.result;
|
|
4760
6377
|
}
|
|
6378
|
+
/** Record the model and Effort a running Subagent resolved to. */
|
|
6379
|
+
refine(id, patch) {
|
|
6380
|
+
const work = this.jobs.get(id);
|
|
6381
|
+
if (!work || work.brief.type !== "subagent") return;
|
|
6382
|
+
work.brief = { ...work.brief, ...patch };
|
|
6383
|
+
this.emit({ ...work.brief, state: "running" });
|
|
6384
|
+
}
|
|
4761
6385
|
waiting(id, waiting) {
|
|
4762
6386
|
const work = this.jobs.get(id);
|
|
4763
6387
|
if (!work || work.brief.type !== "subagent" || !["running", "waiting"].includes(work.state)) return;
|
|
@@ -4940,11 +6564,11 @@ var PiWorkflowSubagent = class {
|
|
|
4940
6564
|
let compacting = false;
|
|
4941
6565
|
try {
|
|
4942
6566
|
controller.signal.throwIfAborted();
|
|
4943
|
-
const model = parent.modelRuntime.getAvailableSnapshot()
|
|
4944
|
-
if (!model) throw new Error(
|
|
6567
|
+
const model = findPiModel(parent.modelRuntime.getAvailableSnapshot(), options.modelId);
|
|
6568
|
+
if (!model) throw new Error(piModelUnavailable(options.modelId, "Unknown workflow model"));
|
|
4945
6569
|
if (!["ask", "auto-accept"].includes(options.permissionMode)) throw new Error("Unsupported workflow permission mode");
|
|
4946
6570
|
const scope = parent.sessionManager.getCwd();
|
|
4947
|
-
const settingsManager = SettingsManager.inMemory({ retry: { enabled: false } });
|
|
6571
|
+
const settingsManager = SettingsManager.inMemory({ retry: { enabled: false }, cacheWarming: "streaming" });
|
|
4948
6572
|
const skillContext = options.skill ? `The leading Skill invocation is expanded as the user prompt. Follow it together with the mapped workflow input below.
|
|
4949
6573
|
|
|
4950
6574
|
Mapped workflow input (JSON):
|
|
@@ -4953,12 +6577,12 @@ ${JSON.stringify(options.input)}
|
|
|
4953
6577
|
Workflow constraints:${options.instructions.slice(options.skill.invocation.length)}` : options.instructions;
|
|
4954
6578
|
const resources = options.skill ? await new DefaultPackageManager({
|
|
4955
6579
|
cwd: scope,
|
|
4956
|
-
agentDir:
|
|
4957
|
-
settingsManager: SettingsManager.create(scope,
|
|
6580
|
+
agentDir: getAgentDir2(),
|
|
6581
|
+
settingsManager: SettingsManager.create(scope, getAgentDir2())
|
|
4958
6582
|
}).resolve(async () => "skip") : void 0;
|
|
4959
6583
|
const resourceLoader = new DefaultResourceLoader({
|
|
4960
6584
|
cwd: scope,
|
|
4961
|
-
agentDir:
|
|
6585
|
+
agentDir: getAgentDir2(),
|
|
4962
6586
|
settingsManager,
|
|
4963
6587
|
noExtensions: true,
|
|
4964
6588
|
noSkills: true,
|
|
@@ -5084,6 +6708,222 @@ ${skillContext}`
|
|
|
5084
6708
|
}
|
|
5085
6709
|
};
|
|
5086
6710
|
|
|
6711
|
+
// src/backend/pi/model-catalog.ts
|
|
6712
|
+
function registerPiNativeProvider(runtime, provider) {
|
|
6713
|
+
const refresh = runtime.refresh;
|
|
6714
|
+
runtime.refresh = async () => ({ aborted: false, errors: /* @__PURE__ */ new Map() });
|
|
6715
|
+
try {
|
|
6716
|
+
runtime.registerNativeProvider(provider);
|
|
6717
|
+
} finally {
|
|
6718
|
+
runtime.refresh = refresh;
|
|
6719
|
+
}
|
|
6720
|
+
}
|
|
6721
|
+
function unregisterPiNativeProvider(runtime, providerId) {
|
|
6722
|
+
const refresh = runtime.refresh;
|
|
6723
|
+
runtime.refresh = async () => ({ aborted: false, errors: /* @__PURE__ */ new Map() });
|
|
6724
|
+
try {
|
|
6725
|
+
runtime.unregisterProvider(providerId);
|
|
6726
|
+
} finally {
|
|
6727
|
+
runtime.refresh = refresh;
|
|
6728
|
+
}
|
|
6729
|
+
}
|
|
6730
|
+
function withPi099RadiusCatalog(provider, cached) {
|
|
6731
|
+
return {
|
|
6732
|
+
...provider,
|
|
6733
|
+
async refreshModels(context) {
|
|
6734
|
+
const legacy = context.stored ? void 0 : cached();
|
|
6735
|
+
if (legacy) {
|
|
6736
|
+
const stored = { models: [...legacy], checkedAt: Date.now() };
|
|
6737
|
+
if (!await context.publish({ persist: stored })) return;
|
|
6738
|
+
context = { ...context, stored };
|
|
6739
|
+
}
|
|
6740
|
+
await provider.refreshModels?.(context);
|
|
6741
|
+
}
|
|
6742
|
+
};
|
|
6743
|
+
}
|
|
6744
|
+
|
|
6745
|
+
// src/backend/pi/canonical-json.ts
|
|
6746
|
+
var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
|
|
6747
|
+
|
|
6748
|
+
// src/backend/pi/model-auth.ts
|
|
6749
|
+
var emptyCredentials = {
|
|
6750
|
+
async read(_providerId, options) {
|
|
6751
|
+
options?.signal?.throwIfAborted();
|
|
6752
|
+
return void 0;
|
|
6753
|
+
},
|
|
6754
|
+
async list(options) {
|
|
6755
|
+
options?.signal?.throwIfAborted();
|
|
6756
|
+
return [];
|
|
6757
|
+
},
|
|
6758
|
+
async modify() {
|
|
6759
|
+
throw new Error("Worker Pi credentials are read-only");
|
|
6760
|
+
},
|
|
6761
|
+
async delete() {
|
|
6762
|
+
throw new Error("Worker Pi credentials are read-only");
|
|
6763
|
+
}
|
|
6764
|
+
};
|
|
6765
|
+
async function createWorkerPiModelRuntime(auth, modelsPath, signal, options = {}) {
|
|
6766
|
+
let metadata = new Map((await auth.snapshot(signal)).map((entry) => [entry.providerId, entry]));
|
|
6767
|
+
const storedKey = /* @__PURE__ */ Symbol("host credential metadata");
|
|
6768
|
+
const credentials = {
|
|
6769
|
+
...emptyCredentials,
|
|
6770
|
+
async read(id, options2) {
|
|
6771
|
+
options2?.signal?.throwIfAborted();
|
|
6772
|
+
const entry = metadata.get(id);
|
|
6773
|
+
if (entry?.check?.type === "api_key") return { type: "api_key", [storedKey]: true };
|
|
6774
|
+
if (entry?.check?.type === "oauth") return {
|
|
6775
|
+
type: "oauth",
|
|
6776
|
+
access: "",
|
|
6777
|
+
refresh: "",
|
|
6778
|
+
expires: Number.MAX_SAFE_INTEGER,
|
|
6779
|
+
...entry.availableModelIds ? { availableModelIds: [...entry.availableModelIds] } : {}
|
|
6780
|
+
};
|
|
6781
|
+
return void 0;
|
|
6782
|
+
}
|
|
6783
|
+
};
|
|
6784
|
+
const { ModelRuntime } = await import("@earendil-works/pi-coding-agent");
|
|
6785
|
+
const { radiusProvider } = await import("@earendil-works/pi-ai/providers/all");
|
|
6786
|
+
const catalog = await ModelRuntime.create({ credentials: emptyCredentials, modelsPath: null, refreshOnCreate: false });
|
|
6787
|
+
const runtime = await ModelRuntime.create({
|
|
6788
|
+
credentials,
|
|
6789
|
+
modelsPath,
|
|
6790
|
+
...options.modelsStorePath ? { modelsStorePath: options.modelsStorePath } : {},
|
|
6791
|
+
refreshOnCreate: false,
|
|
6792
|
+
...signal ? { signal } : {}
|
|
6793
|
+
});
|
|
6794
|
+
const refresh = runtime.refresh.bind(runtime);
|
|
6795
|
+
const builtins = new Map(catalog.getProviders().map((provider) => [provider.id, provider]));
|
|
6796
|
+
const registered = /* @__PURE__ */ new Set();
|
|
6797
|
+
const registeredGateways = /* @__PURE__ */ new Map();
|
|
6798
|
+
const expandKey = async (key, env, signal2) => {
|
|
6799
|
+
if (!key?.includes("$")) return key;
|
|
6800
|
+
const resolver = await ModelRuntime.create({ credentials: emptyCredentials, modelsPath: null, refreshOnCreate: false, signal: signal2 });
|
|
6801
|
+
const refresh2 = resolver.refresh;
|
|
6802
|
+
resolver.refresh = async () => ({ aborted: false, errors: /* @__PURE__ */ new Map() });
|
|
6803
|
+
try {
|
|
6804
|
+
resolver.registerProvider("worker-key-template", { apiKey: key });
|
|
6805
|
+
} finally {
|
|
6806
|
+
resolver.refresh = refresh2;
|
|
6807
|
+
}
|
|
6808
|
+
return (await resolver.getAuth("worker-key-template", { ...env ? { env } : {}, signal: signal2 }))?.auth.apiKey;
|
|
6809
|
+
};
|
|
6810
|
+
const genericApiKey = {
|
|
6811
|
+
name: "API key",
|
|
6812
|
+
async resolve({ credential }) {
|
|
6813
|
+
return credential?.key ? { auth: { apiKey: credential.key }, ...credential.env ? { env: credential.env } : {} } : void 0;
|
|
6814
|
+
}
|
|
6815
|
+
};
|
|
6816
|
+
const brokered = (provider, catalogAuth = provider.id === "radius") => {
|
|
6817
|
+
const id = provider.id;
|
|
6818
|
+
const apiKey = provider.auth.apiKey ?? genericApiKey;
|
|
6819
|
+
const oauth = provider.auth.oauth;
|
|
6820
|
+
return {
|
|
6821
|
+
...provider,
|
|
6822
|
+
auth: {
|
|
6823
|
+
...apiKey ? { apiKey: {
|
|
6824
|
+
...apiKey,
|
|
6825
|
+
async check(input) {
|
|
6826
|
+
input.signal.throwIfAborted();
|
|
6827
|
+
if (input.credential?.[storedKey]) return metadata.get(id)?.check;
|
|
6828
|
+
if (apiKey.check) return apiKey.check(input);
|
|
6829
|
+
const result = await apiKey.resolve(input);
|
|
6830
|
+
return result ? { type: "api_key", ...result.source !== void 0 ? { source: result.source } : {} } : void 0;
|
|
6831
|
+
},
|
|
6832
|
+
async resolve(input) {
|
|
6833
|
+
if (!input.credential?.[storedKey]) return apiKey.resolve(input);
|
|
6834
|
+
const result = await auth.resolve(id, input.signal);
|
|
6835
|
+
if (!result) return void 0;
|
|
6836
|
+
const env = { ...result.env, ...input.credential?.env };
|
|
6837
|
+
const key = await expandKey(result.auth.apiKey, env, input.signal);
|
|
6838
|
+
return apiKey.resolve({
|
|
6839
|
+
...input,
|
|
6840
|
+
credential: { type: "api_key", ...key !== void 0 ? { key } : {}, env },
|
|
6841
|
+
ctx: { ...input.ctx, env: async (name) => env[name] ?? input.ctx.env(name) }
|
|
6842
|
+
});
|
|
6843
|
+
}
|
|
6844
|
+
} } : {},
|
|
6845
|
+
...oauth ? { oauth: {
|
|
6846
|
+
...oauth,
|
|
6847
|
+
async toAuth() {
|
|
6848
|
+
const result = await auth.resolve(id);
|
|
6849
|
+
if (!result) throw new Error("Session Host auth is unavailable");
|
|
6850
|
+
return result.auth;
|
|
6851
|
+
}
|
|
6852
|
+
} } : {}
|
|
6853
|
+
},
|
|
6854
|
+
...provider.refreshModels ? { async refreshModels(context) {
|
|
6855
|
+
if (catalogAuth && context.allowNetwork && context.credential?.type === "oauth") {
|
|
6856
|
+
const result = await auth.resolve(id, context.signal);
|
|
6857
|
+
if (!result) return;
|
|
6858
|
+
return provider.refreshModels({ ...context, credential: {
|
|
6859
|
+
...context.credential,
|
|
6860
|
+
access: result.auth.apiKey ?? "",
|
|
6861
|
+
refresh: ""
|
|
6862
|
+
} });
|
|
6863
|
+
}
|
|
6864
|
+
return provider.refreshModels(context);
|
|
6865
|
+
} } : {}
|
|
6866
|
+
};
|
|
6867
|
+
};
|
|
6868
|
+
const registerProviders = () => {
|
|
6869
|
+
if (!metadata.has("radius") && registered.delete("radius")) {
|
|
6870
|
+
unregisterPiNativeProvider(runtime, "radius");
|
|
6871
|
+
registeredGateways.delete("radius");
|
|
6872
|
+
}
|
|
6873
|
+
const gateways = new Map([...metadata.values()].flatMap((entry) => entry.radiusGateway !== void 0 ? [[entry.providerId, entry.radiusGateway]] : []));
|
|
6874
|
+
const baseUrl = runtime.getProvider("radius")?.baseUrl;
|
|
6875
|
+
if (metadata.has("radius") && !gateways.has("radius") && (!baseUrl || /^https:\/\/radius\.pi\.dev(?:\/v1)?\/?$/u.test(baseUrl) || registeredGateways.has("radius"))) gateways.set("radius", "");
|
|
6876
|
+
for (const [id, gateway] of gateways) {
|
|
6877
|
+
if (registeredGateways.get(id) === gateway) continue;
|
|
6878
|
+
const provider = radiusProvider({ id, ...gateway ? { gateway } : {} });
|
|
6879
|
+
registerPiNativeProvider(runtime, brokered(withPi099RadiusCatalog(provider, () => metadata.get(id)?.cachedModels), true));
|
|
6880
|
+
registeredGateways.set(id, gateway);
|
|
6881
|
+
registered.add(id);
|
|
6882
|
+
}
|
|
6883
|
+
for (const entry of metadata.values()) {
|
|
6884
|
+
const id = entry.providerId;
|
|
6885
|
+
if (registered.has(id)) continue;
|
|
6886
|
+
const provider = builtins.get(id) ?? {
|
|
6887
|
+
id,
|
|
6888
|
+
name: id,
|
|
6889
|
+
getModels: () => [],
|
|
6890
|
+
auth: { apiKey: genericApiKey },
|
|
6891
|
+
stream() {
|
|
6892
|
+
throw new Error("Provider requires configured models and API");
|
|
6893
|
+
},
|
|
6894
|
+
streamSimple() {
|
|
6895
|
+
throw new Error("Provider requires configured models and API");
|
|
6896
|
+
}
|
|
6897
|
+
};
|
|
6898
|
+
registerPiNativeProvider(runtime, brokered(provider));
|
|
6899
|
+
registered.add(id);
|
|
6900
|
+
}
|
|
6901
|
+
};
|
|
6902
|
+
registerProviders();
|
|
6903
|
+
runtime.refresh = async (options2 = {}) => {
|
|
6904
|
+
metadata = new Map((await auth.snapshot(options2.signal)).map((entry) => [entry.providerId, entry]));
|
|
6905
|
+
registerProviders();
|
|
6906
|
+
return refresh(options2);
|
|
6907
|
+
};
|
|
6908
|
+
await refresh({ allowNetwork: false, ...signal ? { signal } : {} });
|
|
6909
|
+
if (options.discovery && process.env["PI_OFFLINE"] === void 0) {
|
|
6910
|
+
const force = options.discovery === "refresh";
|
|
6911
|
+
const providers = runtime.getProviders().filter((provider) => runtime.hasConfiguredAuth(provider.id) && (force || builtins.has(provider.id) && provider.id !== "radius" && !registeredGateways.has(provider.id))).map((provider) => provider.id);
|
|
6912
|
+
const timeout = AbortSignal.timeout(5e3);
|
|
6913
|
+
await runtime.refresh({ allowNetwork: true, force, providers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout });
|
|
6914
|
+
}
|
|
6915
|
+
return runtime;
|
|
6916
|
+
}
|
|
6917
|
+
|
|
6918
|
+
// src/backend/pi/cache-warming.ts
|
|
6919
|
+
function streamingCacheWarming(settings2) {
|
|
6920
|
+
return { name: "flow-streaming-cache-warming", hidden: true, factory: (pi) => {
|
|
6921
|
+
pi.on("cache_warming_decision", (_event, ctx) => {
|
|
6922
|
+
if (settings2.getGlobalSettings().cacheWarming !== "idle" && ctx.isIdle()) return { action: "stop" };
|
|
6923
|
+
});
|
|
6924
|
+
} };
|
|
6925
|
+
}
|
|
6926
|
+
|
|
5087
6927
|
// src/backend/pi/subagents.ts
|
|
5088
6928
|
import { defineTool as defineTool3 } from "@earendil-works/pi-coding-agent";
|
|
5089
6929
|
var SUBAGENT_TOOL = "subagent";
|
|
@@ -5195,7 +7035,7 @@ var PiSession = class {
|
|
|
5195
7035
|
this.unsubscribe();
|
|
5196
7036
|
current.dispose();
|
|
5197
7037
|
this.session = await this.recreate(current);
|
|
5198
|
-
this.unsubscribe = this.
|
|
7038
|
+
this.unsubscribe = this.bindSession();
|
|
5199
7039
|
}
|
|
5200
7040
|
standingAuthorisations;
|
|
5201
7041
|
agentPermissions;
|
|
@@ -5246,7 +7086,15 @@ var PiSession = class {
|
|
|
5246
7086
|
if (this.agentPermissions) this.answerPermission = async (callId, decision) => this.agentPermissions.answer(callId, decision);
|
|
5247
7087
|
if (enquiries) this.answerEnquiry = async (askId, answers) => enquiries.answer(askId, answers);
|
|
5248
7088
|
this.capabilities = capabilitiesOf(session, support.enquiries !== void 0, support.subagents ?? false, !this.workflowBuilder);
|
|
5249
|
-
this.unsubscribe =
|
|
7089
|
+
this.unsubscribe = this.bindSession();
|
|
7090
|
+
}
|
|
7091
|
+
bindSession() {
|
|
7092
|
+
const stream = this.session.agent?.streamFunction;
|
|
7093
|
+
if (stream) this.session.agent.streamFunction = (...args) => {
|
|
7094
|
+
if (this.disposed) throw new Error("Backend Session stopped");
|
|
7095
|
+
return stream(...args);
|
|
7096
|
+
};
|
|
7097
|
+
return this.session.subscribe((event) => this.translate(event));
|
|
5250
7098
|
}
|
|
5251
7099
|
startWorkflowSubagent(options) {
|
|
5252
7100
|
if (this.disposed) throw new Error("Backend Session stopped");
|
|
@@ -5269,6 +7117,7 @@ var PiSession = class {
|
|
|
5269
7117
|
return this.sessionDir;
|
|
5270
7118
|
}
|
|
5271
7119
|
async prompt(text, attachments, messageId) {
|
|
7120
|
+
if (this.disposed) return;
|
|
5272
7121
|
if (messageId && this.sessionDir) this.unmappedMessageIds.push(messageId);
|
|
5273
7122
|
this.turnId = `turn-${++this.messageSeq}`;
|
|
5274
7123
|
this.emit({ type: "turn_started", turnId: this.turnId });
|
|
@@ -5289,10 +7138,8 @@ var PiSession = class {
|
|
|
5289
7138
|
}
|
|
5290
7139
|
async setModel(modelId) {
|
|
5291
7140
|
const available = await this.session.modelRuntime.getAvailable();
|
|
5292
|
-
const
|
|
5293
|
-
|
|
5294
|
-
const model = qualified ?? (legacy.length === 1 ? legacy[0] : void 0);
|
|
5295
|
-
if (!model) throw new Error(`Unknown model: ${modelId}`);
|
|
7141
|
+
const model = findPiModel(available, modelId, true);
|
|
7142
|
+
if (!model) throw new Error(piModelUnavailable(modelId));
|
|
5296
7143
|
await this.session.setModel(model);
|
|
5297
7144
|
this.applyAutoCompaction?.(this.session.model);
|
|
5298
7145
|
this.capabilities = capabilitiesOf(this.session, this.enquiries !== void 0, this.capabilities.subagents, !this.workflowBuilder);
|
|
@@ -5447,7 +7294,7 @@ var PiSession = class {
|
|
|
5447
7294
|
queueMicrotask(() => {
|
|
5448
7295
|
const entry = this.session.sessionManager.getBranch().findLast((candidate) => candidate.type === "message" && candidate.message === message);
|
|
5449
7296
|
if (!entry || !this.sessionDir) return;
|
|
5450
|
-
writeFileSync(
|
|
7297
|
+
writeFileSync(join2(this.sessionDir, USER_MESSAGE_MAP), JSON.stringify({ ...readUserMessageMap(this.sessionDir), [messageId]: entry.id }), { mode: 384 });
|
|
5451
7298
|
});
|
|
5452
7299
|
}
|
|
5453
7300
|
translate(event) {
|
|
@@ -5490,7 +7337,7 @@ var PiSession = class {
|
|
|
5490
7337
|
return;
|
|
5491
7338
|
}
|
|
5492
7339
|
case "agent_settled":
|
|
5493
|
-
this.finishTurn(this.aborting ? "aborted" : this.turnReason);
|
|
7340
|
+
this.finishTurn(event.aborted || this.aborting ? "aborted" : this.turnReason);
|
|
5494
7341
|
return;
|
|
5495
7342
|
case "auto_retry_start":
|
|
5496
7343
|
this.emit({
|
|
@@ -5563,9 +7410,13 @@ var PiBackend = class {
|
|
|
5563
7410
|
this.options = options;
|
|
5564
7411
|
}
|
|
5565
7412
|
async create(options) {
|
|
5566
|
-
const agentDir =
|
|
7413
|
+
const agentDir = getAgentDir3();
|
|
7414
|
+
const modelRuntime = options.piAuth ? await createWorkerPiModelRuntime(options.piAuth, join2(agentDir, "models.json"), options.signal, {
|
|
7415
|
+
...options.stateDir ? { modelsStorePath: join2(options.stateDir, "models-store.json") } : {},
|
|
7416
|
+
discovery: options.refreshModels ? "refresh" : "automatic"
|
|
7417
|
+
}) : void 0;
|
|
5567
7418
|
const builder = options.workflowBuilder;
|
|
5568
|
-
const settingsManager = builder ? SettingsManager2.inMemory() : SettingsManager2.create(options.scope, agentDir);
|
|
7419
|
+
const settingsManager = builder ? SettingsManager2.inMemory({ cacheWarming: "streaming" }) : SettingsManager2.create(options.scope, agentDir);
|
|
5569
7420
|
const agentPermissions = builder || options.tools === "none" ? void 0 : new PiAgentPermissions(options.permissionMode ?? "always", options.standingAuthorisations ?? [], options.emit);
|
|
5570
7421
|
const resourceLoader = new DefaultResourceLoader2({
|
|
5571
7422
|
cwd: options.scope,
|
|
@@ -5581,6 +7432,7 @@ var PiBackend = class {
|
|
|
5581
7432
|
systemPromptOverride: () => builder.instructions
|
|
5582
7433
|
} : {
|
|
5583
7434
|
extensionFactories: [
|
|
7435
|
+
streamingCacheWarming(settingsManager),
|
|
5584
7436
|
...agentPermissions ? [agentPermissions.extension()] : [],
|
|
5585
7437
|
...options.compactionModelId ? [compactionModelExtension(
|
|
5586
7438
|
options.compactionModelId,
|
|
@@ -5622,6 +7474,7 @@ var PiBackend = class {
|
|
|
5622
7474
|
agentDir,
|
|
5623
7475
|
resourceLoader,
|
|
5624
7476
|
settingsManager,
|
|
7477
|
+
...modelRuntime ? { modelRuntime } : {},
|
|
5625
7478
|
customTools: [...customTools, ...mcpTools],
|
|
5626
7479
|
tools: [...tools, ...mcpTools.map((tool) => tool.name)],
|
|
5627
7480
|
...current ? { sessionManager: current.sessionManager, modelRuntime: current.modelRuntime, thinkingLevel: current.thinkingLevel, ...current.model ? { model: current.model } : {} } : sessionManager ? { sessionManager } : {},
|
|
@@ -5644,9 +7497,10 @@ var PiBackend = class {
|
|
|
5644
7497
|
}
|
|
5645
7498
|
const autoCompaction = structuredClone(options.autoCompaction);
|
|
5646
7499
|
const piSession = new PiSession(session, options.emit, sessionDir, { workflowBuilder: !!builder, ...mcp ? { mcp } : {}, work, subagents, standingAuthorisations: options.standingAuthorisations ?? [], ...agentPermissions ? { agentPermissions } : {}, autoCompaction: piAutoCompaction(settingsManager, autoCompaction), ...autoCompaction ? { workflowAutoCompaction: autoCompaction } : {}, ...options.compactionModelId ? { workflowCompactionModelId: options.compactionModelId } : {}, ...enquiries ? { enquiries } : {}, ...mcp ? { recreate: async (current) => session = (await start(current)).session } : {} });
|
|
5647
|
-
|
|
7500
|
+
const modelId = options.modelId ?? (settingsManager.getDefaultProvider() === "azure-openai-responses" && settingsManager.getDefaultModel() ? `azure-openai-responses/${settingsManager.getDefaultModel()}` : void 0);
|
|
7501
|
+
if (modelId) {
|
|
5648
7502
|
try {
|
|
5649
|
-
await piSession.setModel(
|
|
7503
|
+
await piSession.setModel(modelId);
|
|
5650
7504
|
} catch (error) {
|
|
5651
7505
|
await piSession.dispose();
|
|
5652
7506
|
throw error;
|
|
@@ -5672,8 +7526,8 @@ var PiBackend = class {
|
|
|
5672
7526
|
};
|
|
5673
7527
|
async function runSubagent(parent, scope, agentDir, work, id, input, signal, emit, mcp, compactionModelId, agentPermissions) {
|
|
5674
7528
|
const available = parent.modelRuntime.getAvailableSnapshot();
|
|
5675
|
-
const model = input.model ? available
|
|
5676
|
-
if (!model) throw new Error(
|
|
7529
|
+
const model = input.model ? findPiModel(available, input.model) : parent.model;
|
|
7530
|
+
if (!model) throw new Error(`${piModelUnavailable(input.model ?? "(inherited)")} Available: ${available.map((model2) => describeModel(model2).id).join(", ")}`);
|
|
5677
7531
|
const effort = input.effort ?? parent.thinkingLevel;
|
|
5678
7532
|
const tools = [.../* @__PURE__ */ new Set([...parent.getActiveToolNames(), ...piMcpTools(mcp).map((tool) => tool.name)])].filter((name) => name !== ASK_TOOL && name !== SUBAGENT_TOOL && !name.startsWith("workflow_") && !name.startsWith("session_"));
|
|
5679
7533
|
const settingsManager = SettingsManager2.create(scope, agentDir);
|
|
@@ -5684,6 +7538,7 @@ async function runSubagent(parent, scope, agentDir, work, id, input, signal, emi
|
|
|
5684
7538
|
settingsManager,
|
|
5685
7539
|
noExtensions: true,
|
|
5686
7540
|
extensionFactories: [
|
|
7541
|
+
streamingCacheWarming(settingsManager),
|
|
5687
7542
|
...agentPermissions ? [agentPermissions.extension(producer)] : [],
|
|
5688
7543
|
...compactionModelId ? [compactionModelExtension(
|
|
5689
7544
|
compactionModelId,
|
|
@@ -5745,6 +7600,7 @@ async function runSubagent(parent, scope, agentDir, work, id, input, signal, emi
|
|
|
5745
7600
|
try {
|
|
5746
7601
|
signal.throwIfAborted();
|
|
5747
7602
|
await adapter.setEffort(effort);
|
|
7603
|
+
work.refine(id, { model: describeModel(model).id, effort: child.thinkingLevel });
|
|
5748
7604
|
signal.throwIfAborted();
|
|
5749
7605
|
emit({ type: "subagent_instruction", id: `${id}:brief`, text: input.prompt, producer });
|
|
5750
7606
|
await adapter.prompt(input.prompt);
|
|
@@ -5758,8 +7614,8 @@ async function runSubagent(parent, scope, agentDir, work, id, input, signal, emi
|
|
|
5758
7614
|
}
|
|
5759
7615
|
}
|
|
5760
7616
|
function readUserMessageMap(sessionDir) {
|
|
5761
|
-
const path =
|
|
5762
|
-
return
|
|
7617
|
+
const path = join2(sessionDir, USER_MESSAGE_MAP);
|
|
7618
|
+
return existsSync2(path) ? JSON.parse(readFileSync2(path, "utf8")) : {};
|
|
5763
7619
|
}
|
|
5764
7620
|
function capabilitiesOf(session, enquiries, subagents, permissions = true) {
|
|
5765
7621
|
const models = session.modelRuntime.getAvailableSnapshot().map(describeModel);
|