@mitralab.io/sdk-core 0.2.11-beta.0 → 0.2.12-beta.0

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/index.cjs CHANGED
@@ -4103,6 +4103,8 @@ var CoreAgentTaskSession = class {
4103
4103
  openingPromise = null;
4104
4104
  createPromise = null;
4105
4105
  dispatching = false;
4106
+ // Resolves true once the box admitted the prompt in flight; false when it never became a turn.
4107
+ dispatch = null;
4106
4108
  recoveryUsed = false;
4107
4109
  // Turns the server already ended. A box flushes the text it had buffered for a stopped turn
4108
4110
  // after the interrupted terminal (dev, 2026-09-14); that text must not open a turn of its own.
@@ -4169,6 +4171,7 @@ var CoreAgentTaskSession = class {
4169
4171
  return waiter.promise;
4170
4172
  }
4171
4173
  async cancel() {
4174
+ if (this.dispatch && !await this.dispatch) return;
4172
4175
  if (this._status !== "streaming" && this._status !== "cancelled") return;
4173
4176
  try {
4174
4177
  await this.sendInput({ type: "interrupt" });
@@ -4275,21 +4278,24 @@ var CoreAgentTaskSession = class {
4275
4278
  }
4276
4279
  startDispatch(prompt, options, waiter) {
4277
4280
  this.dispatching = true;
4278
- void this.dispatchSend(prompt, options, waiter).catch((error) => {
4281
+ const dispatch = this.dispatchSend(prompt, options, waiter).catch((error) => {
4279
4282
  waiter?.reject(error);
4280
4283
  this.emitError("Failed to send Agent prompt", error);
4281
4284
  if (this._status === "streaming") this.setStatus("idle");
4282
4285
  this.flushQueue();
4286
+ return false;
4283
4287
  }).finally(() => {
4284
4288
  this.dispatching = false;
4289
+ if (this.dispatch === dispatch) this.dispatch = null;
4285
4290
  if (this._status === "idle") this.flushQueue();
4286
4291
  });
4292
+ this.dispatch = dispatch;
4287
4293
  }
4288
4294
  async dispatchSend(prompt, options, waiter) {
4289
4295
  if (this.openingPromise && !await this.openingPromise) {
4290
4296
  throw new Error("Agent task session could not be opened.");
4291
4297
  }
4292
- if (this.isClosed() || waiter?.settled) return;
4298
+ if (this.isClosed() || waiter?.settled) return false;
4293
4299
  await this.ensureTask();
4294
4300
  const input = {
4295
4301
  type: "message",
@@ -4299,11 +4305,11 @@ var CoreAgentTaskSession = class {
4299
4305
  };
4300
4306
  if (this.isClosed()) {
4301
4307
  await this.sendInput(input).catch(() => void 0);
4302
- return;
4308
+ return false;
4303
4309
  }
4304
- if (waiter?.settled) return;
4310
+ if (waiter?.settled) return false;
4305
4311
  await this.ensureChannel();
4306
- if (this.isClosed() || waiter?.settled) return;
4312
+ if (this.isClosed() || waiter?.settled) return false;
4307
4313
  await this.captureTurnBaseline();
4308
4314
  this._content = "";
4309
4315
  this.recoveryUsed = false;
@@ -4313,7 +4319,9 @@ var CoreAgentTaskSession = class {
4313
4319
  this.activeWaiter = waiter;
4314
4320
  this.setStatus("streaming");
4315
4321
  this.emit("turnStart", {});
4316
- if (await this.sendInput(input)) this.emit("accepted", {});
4322
+ if (!await this.sendInput(input)) return false;
4323
+ this.emit("accepted", {});
4324
+ return true;
4317
4325
  }
4318
4326
  async ensureTask() {
4319
4327
  if (this._taskId) return;
package/dist/index.js CHANGED
@@ -4031,6 +4031,8 @@ var CoreAgentTaskSession = class {
4031
4031
  openingPromise = null;
4032
4032
  createPromise = null;
4033
4033
  dispatching = false;
4034
+ // Resolves true once the box admitted the prompt in flight; false when it never became a turn.
4035
+ dispatch = null;
4034
4036
  recoveryUsed = false;
4035
4037
  // Turns the server already ended. A box flushes the text it had buffered for a stopped turn
4036
4038
  // after the interrupted terminal (dev, 2026-09-14); that text must not open a turn of its own.
@@ -4097,6 +4099,7 @@ var CoreAgentTaskSession = class {
4097
4099
  return waiter.promise;
4098
4100
  }
4099
4101
  async cancel() {
4102
+ if (this.dispatch && !await this.dispatch) return;
4100
4103
  if (this._status !== "streaming" && this._status !== "cancelled") return;
4101
4104
  try {
4102
4105
  await this.sendInput({ type: "interrupt" });
@@ -4203,21 +4206,24 @@ var CoreAgentTaskSession = class {
4203
4206
  }
4204
4207
  startDispatch(prompt, options, waiter) {
4205
4208
  this.dispatching = true;
4206
- void this.dispatchSend(prompt, options, waiter).catch((error) => {
4209
+ const dispatch = this.dispatchSend(prompt, options, waiter).catch((error) => {
4207
4210
  waiter?.reject(error);
4208
4211
  this.emitError("Failed to send Agent prompt", error);
4209
4212
  if (this._status === "streaming") this.setStatus("idle");
4210
4213
  this.flushQueue();
4214
+ return false;
4211
4215
  }).finally(() => {
4212
4216
  this.dispatching = false;
4217
+ if (this.dispatch === dispatch) this.dispatch = null;
4213
4218
  if (this._status === "idle") this.flushQueue();
4214
4219
  });
4220
+ this.dispatch = dispatch;
4215
4221
  }
4216
4222
  async dispatchSend(prompt, options, waiter) {
4217
4223
  if (this.openingPromise && !await this.openingPromise) {
4218
4224
  throw new Error("Agent task session could not be opened.");
4219
4225
  }
4220
- if (this.isClosed() || waiter?.settled) return;
4226
+ if (this.isClosed() || waiter?.settled) return false;
4221
4227
  await this.ensureTask();
4222
4228
  const input = {
4223
4229
  type: "message",
@@ -4227,11 +4233,11 @@ var CoreAgentTaskSession = class {
4227
4233
  };
4228
4234
  if (this.isClosed()) {
4229
4235
  await this.sendInput(input).catch(() => void 0);
4230
- return;
4236
+ return false;
4231
4237
  }
4232
- if (waiter?.settled) return;
4238
+ if (waiter?.settled) return false;
4233
4239
  await this.ensureChannel();
4234
- if (this.isClosed() || waiter?.settled) return;
4240
+ if (this.isClosed() || waiter?.settled) return false;
4235
4241
  await this.captureTurnBaseline();
4236
4242
  this._content = "";
4237
4243
  this.recoveryUsed = false;
@@ -4241,7 +4247,9 @@ var CoreAgentTaskSession = class {
4241
4247
  this.activeWaiter = waiter;
4242
4248
  this.setStatus("streaming");
4243
4249
  this.emit("turnStart", {});
4244
- if (await this.sendInput(input)) this.emit("accepted", {});
4250
+ if (!await this.sendInput(input)) return false;
4251
+ this.emit("accepted", {});
4252
+ return true;
4245
4253
  }
4246
4254
  async ensureTask() {
4247
4255
  if (this._taskId) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/sdk-core",
3
- "version": "0.2.11-beta.0",
3
+ "version": "0.2.12-beta.0",
4
4
  "description": "Environment-neutral contracts and modules shared by Mitra JavaScript SDKs",
5
5
  "type": "module",
6
6
  "sideEffects": false,