@monoclaw/machine 1.0.24 → 1.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -2495,7 +2495,9 @@ var HostFrame = z5.discriminatedUnion("t", [
2495
2495
  * How many voice and tool jobs this machine holds at once, running and waiting (1.0.24; bug 091). The server never
2496
2496
  * sends more than this and queues the rest itself; absent from an older program, it assumes three.
2497
2497
  */
2498
- jobSlots: z5.number().int().positive().optional()
2498
+ jobSlots: z5.number().int().positive().optional(),
2499
+ /** The jobs this machine still runs or holds a result for (1.0.25; bug 096): the server takes or drops each. */
2500
+ heldJobs: z5.array(z5.object({ jobId: z5.string(), done: z5.boolean() })).optional()
2499
2501
  }),
2500
2502
  z5.object({ t: z5.literal("heartbeat"), at: z5.string() }),
2501
2503
  z5.object({ t: z5.literal("providers"), providers: z5.array(HostProviderReport), providerAccounts: z5.array(ProviderAccountReport).optional() }),
@@ -2594,6 +2596,10 @@ var RouterFrame = z5.discriminatedUnion("t", [
2594
2596
  * Do one piece of work with a module and a connection, with the owner's options. Answered with `job.result`. A
2595
2597
  * text-to-speech job is one chapter; the server sends a message's chapters one after another.
2596
2598
  */
2599
+ /** Send the held job's result (now if done, else when it ends); its uploads are accepted again (1.0.25; bug 096). */
2600
+ z5.object({ t: z5.literal("job.take"), jobId: z5.string() }),
2601
+ /** Forget the held job: nothing wants its result any more (1.0.25; bug 096). */
2602
+ z5.object({ t: z5.literal("job.drop"), jobId: z5.string() }),
2597
2603
  z5.object({ t: z5.literal("job.run"), jobId: z5.string(), module: ModuleId, connectionId: z5.string(), options: z5.record(z5.string(), z5.union([z5.string(), z5.number(), z5.boolean()])).default({}), input: JobInput }),
2598
2604
  /**
2599
2605
  * The answer to a `tool.call`, a `tool.use` or a `tools.find`: the tool's text for the agent, and the files it made, which the agent's host saves in
@@ -5118,7 +5124,7 @@ function guessMime(name) {
5118
5124
  }
5119
5125
 
5120
5126
  // src/version.ts
5121
- var APP_VERSION = true ? "1.0.24" : fromPackage();
5127
+ var APP_VERSION = true ? "1.0.25" : fromPackage();
5122
5128
 
5123
5129
  // src/diag.ts
5124
5130
  var MAX_HELD = 200;
@@ -5180,7 +5186,7 @@ var TIMING = {
5180
5186
  /** `modules` frames are coalesced: progress ticks twice a second, the server needs far fewer. */
5181
5187
  modulesDebounceMs: 400
5182
5188
  };
5183
- var HostClient = class {
5189
+ var HostClient = class _HostClient {
5184
5190
  constructor(cfg, providers2, opts = {}) {
5185
5191
  this.cfg = cfg;
5186
5192
  this.config = new ConfigStore(cfg);
@@ -5227,6 +5233,29 @@ var HostClient = class {
5227
5233
  stopped = false;
5228
5234
  heartbeat = null;
5229
5235
  outbox = /* @__PURE__ */ new Map();
5236
+ /**
5237
+ * The jobs this machine still runs or holds a result for (bug 096): a job entered when it arrives, its result frame
5238
+ * kept when it ends (the uploads' ids, no bytes), until the service takes it (`job.take`), drops it (`job.drop`), ten
5239
+ * minutes pass, or fifty are held. Said in `hello`, so a service back from a restart takes what it was waiting for.
5240
+ */
5241
+ held = /* @__PURE__ */ new Map();
5242
+ heldJobMs = 10 * 6e4;
5243
+ static HELD_JOBS_MAX = 50;
5244
+ pruneHeld() {
5245
+ const cutoff = Date.now() - this.heldJobMs;
5246
+ for (const [id, h] of this.held) if (h.at < cutoff) this.held.delete(id);
5247
+ while (this.held.size > _HostClient.HELD_JOBS_MAX) this.held.delete(this.held.keys().next().value);
5248
+ }
5249
+ /** A job ended: its result is kept until taken or dropped (a job dropped meanwhile is not kept). */
5250
+ keepHeld(jobId, result) {
5251
+ const h = this.held.get(jobId);
5252
+ if (h) h.result = result;
5253
+ }
5254
+ /** For tests: the held jobs as hello says them. */
5255
+ heldJobs() {
5256
+ this.pruneHeld();
5257
+ return [...this.held.entries()].map(([jobId, h]) => ({ jobId, done: h.result !== null }));
5258
+ }
5230
5259
  uploadUrl = "";
5231
5260
  reports = [];
5232
5261
  sessions;
@@ -5373,7 +5402,8 @@ var HostClient = class {
5373
5402
  publicKey: this.cfg.publicKey,
5374
5403
  roots: this.cfg.roots.map(realRoot),
5375
5404
  openSessions: this.sessions.openGroupIds(),
5376
- jobSlots: VOICE_JOB_SLOTS
5405
+ jobSlots: VOICE_JOB_SLOTS,
5406
+ heldJobs: this.heldJobs()
5377
5407
  });
5378
5408
  for (const f of this.outbox.values()) this.send(f);
5379
5409
  if (this.heartbeat) clearInterval(this.heartbeat);
@@ -5558,6 +5588,18 @@ var HostClient = class {
5558
5588
  case "job.run":
5559
5589
  void this.runJob(frame);
5560
5590
  return;
5591
+ case "job.take": {
5592
+ const h = this.held.get(frame.jobId);
5593
+ if (h?.result) {
5594
+ this.send(h.result);
5595
+ this.held.delete(frame.jobId);
5596
+ log("info", `job ${frame.jobId.slice(0, 10)}: held result taken by the service`);
5597
+ } else if (!h) log("warn", `job ${frame.jobId.slice(0, 10)}: the service asked for a result this machine does not hold`);
5598
+ return;
5599
+ }
5600
+ case "job.drop":
5601
+ if (this.held.delete(frame.jobId)) log("info", `job ${frame.jobId.slice(0, 10)}: held result dropped at the service's word`);
5602
+ return;
5561
5603
  case "provider_account.expect": {
5562
5604
  const m = this.registry.module(frame.module);
5563
5605
  if (!m || !this.registry.isInstalled(frame.module)) {
@@ -5688,6 +5730,8 @@ var HostClient = class {
5688
5730
  let audioFile = "";
5689
5731
  const jobFiles = [];
5690
5732
  log("info", `job ${frame.jobId.slice(0, 10)} ${frame.module} ${frame.input.capability}: received`);
5733
+ this.pruneHeld();
5734
+ this.held.set(frame.jobId, { at: started, result: null });
5691
5735
  const facts = { module: frame.module, capability: frame.input.capability, jobId: frame.jobId.slice(0, 10) };
5692
5736
  let phase = "run";
5693
5737
  const hung = setTimeout(() => {
@@ -5736,7 +5780,9 @@ var HostClient = class {
5736
5780
  const uploadId = await uploadJobOutput(this.uploadUrl, credential, origin, { jobId: frame.jobId, index, bytes: f.bytes, mime: f.mime, name: f.name });
5737
5781
  outputs.push({ uploadId, mime: f.mime, name: f.name, ...f.durationMs !== void 0 ? { durationMs: f.durationMs } : {}, ...f.width ? { width: f.width } : {}, ...f.height ? { height: f.height } : {} });
5738
5782
  }
5739
- this.send({ t: "job.result", jobId: frame.jobId, outputs, ...out.text !== void 0 ? { text: out.text } : {}, ...out.language ? { language: out.language } : {}, ...out.usage ? { usage: out.usage } : {} });
5783
+ const result = { t: "job.result", jobId: frame.jobId, outputs, ...out.text !== void 0 ? { text: out.text } : {}, ...out.language ? { language: out.language } : {}, ...out.usage ? { usage: out.usage } : {} };
5784
+ this.keepHeld(frame.jobId, result);
5785
+ this.send(result);
5740
5786
  log("info", `job ${frame.jobId.slice(0, 10)} ${frame.module} ${frame.input.capability}: ${outputs.length} output(s) in ${Date.now() - started} ms (made in ${made - started}, uploaded in ${Date.now() - made})`);
5741
5787
  if (Date.now() - started > 3e4) this.diag.report({ kind: "job.slow", level: "warn", message: `${frame.module} ${frame.input.capability} took ${Math.round((Date.now() - started) / 1e3)} s`, data: { ...facts, ms: Date.now() - started, madeMs: made - started, uploadMs: Date.now() - made } });
5742
5788
  } catch (e) {
@@ -5746,7 +5792,9 @@ var HostClient = class {
5746
5792
  const message = phase !== "run" && /fetch failed/i.test(raw) ? `${phase} failed${code ? `: ${code}` : ""}` : raw;
5747
5793
  log("warn", `job ${frame.jobId.slice(0, 10)} ${frame.module} ${frame.input.capability} failed (${phase}): ${message}`);
5748
5794
  this.diag.report({ kind: "job.failed", level: "error", message, data: { ...facts, ms: Date.now() - started, phase, ...code ? { cause: code } : {} } });
5749
- this.send({ t: "job.result", jobId: frame.jobId, outputs: [], error: message });
5795
+ const result = { t: "job.result", jobId: frame.jobId, outputs: [], error: message };
5796
+ this.keepHeld(frame.jobId, result);
5797
+ this.send(result);
5750
5798
  } finally {
5751
5799
  clearTimeout(hung);
5752
5800
  if (audioFile) fs16.rmSync(audioFile, { force: true });
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@monoclaw/machine",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@monoclaw/machine",
9
- "version": "1.0.24",
9
+ "version": "1.0.25",
10
10
  "license": "UNLICENSED",
11
11
  "dependencies": {
12
12
  "@anthropic-ai/claude-agent-sdk": "0.3.302",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoclaw/machine",
3
- "version": "1.0.24",
3
+ "version": "1.0.25",
4
4
  "description": "Monoclaw host app: runs agents on your machine and connects them to your Monoclaw account (command.monoclaw.ai).",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {