@mitralab.io/sdk-core 0.3.1 → 0.3.2

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
@@ -4386,7 +4386,8 @@ function providerUsageOf(payload) {
4386
4386
  if (!payload) return null;
4387
4387
  try {
4388
4388
  const { harness, observedAt, status, windows } = expectCredentialUsage(payload, "providerUsage");
4389
- return { harness, observedAt, status, windows };
4389
+ const provider = typeof payload.provider === "string" && payload.provider ? payload.provider : null;
4390
+ return { harness, observedAt, status, windows, ...provider ? { provider } : {} };
4390
4391
  } catch {
4391
4392
  return null;
4392
4393
  }
@@ -4930,19 +4931,19 @@ var CoreAgentTaskSession = class {
4930
4931
  this.dispatch = dispatch;
4931
4932
  }
4932
4933
  async dispatchSend(prompt, options, clientMessageId, handedOver, waiter) {
4933
- if (this.openingPromise && !await this.openingPromise) {
4934
+ if (this.openingPromise && !await this.openingPromise && !this.isClosed()) {
4934
4935
  throw new Error("Agent task session could not be opened.");
4935
4936
  }
4936
- if (this.isClosed()) return false;
4937
+ if (this.isClosed() && !this._taskId) return false;
4937
4938
  await this.ensureTask();
4938
4939
  const input = messageInput(prompt, options);
4939
- if (this.isClosed()) {
4940
- await this.handOver(input, clientMessageId).catch(() => void 0);
4941
- return false;
4942
- }
4943
- await this.ensureChannel();
4944
- if (this.isClosed()) return false;
4940
+ if (this.isClosed()) return this.handOverAfterClose(input, clientMessageId, waiter);
4941
+ await this.ensureChannel().catch((error) => {
4942
+ if (!this.isClosed()) throw error;
4943
+ });
4944
+ if (this.isClosed()) return this.handOverAfterClose(input, clientMessageId, waiter);
4945
4945
  await this.captureTurnBaseline();
4946
+ if (this.isClosed()) return this.handOverAfterClose(input, clientMessageId, waiter);
4946
4947
  this._content = "";
4947
4948
  this.recoveryUsed = false;
4948
4949
  this.recoveredTerminalReason = void 0;
@@ -4960,6 +4961,17 @@ var CoreAgentTaskSession = class {
4960
4961
  this.acceptOnce(clientMessageId);
4961
4962
  return true;
4962
4963
  }
4964
+ // A prompt whose task exists is never dropped by close; the task outlives the session. Apps
4965
+ // close the creating session inside taskCreated and reopen by task id, so the input still goes
4966
+ // out over REST. Only a prompt that never reached `handOver` comes here: the Copilot does not
4967
+ // dedupe POST /inputs by `clientMessageId`, and a second copy would run a second turn. No
4968
+ // channel, status, or event for a closed session, and a failure has no listener left to hear it.
4969
+ // `close()` rejects only the waiter of a turn already open; this one has none yet.
4970
+ async handOverAfterClose(input, clientMessageId, waiter) {
4971
+ await this.handOver(input, clientMessageId).catch(() => void 0);
4972
+ waiter?.reject(new Error("Agent task session is closed."));
4973
+ return false;
4974
+ }
4963
4975
  // A message sent while a turn runs, or is being opened, goes out at once: the box takes it into
4964
4976
  // that turn (the provider's own steering), queues it for a turn of its own, or gives it one when
4965
4977
  // that turn already ended. Nothing waits in this session. On the direct channel it goes with an
@@ -5237,11 +5249,13 @@ var CoreAgentTaskSession = class {
5237
5249
  }
5238
5250
  const turnRunning = this._status === "streaming" || this._status === "cancelled";
5239
5251
  const id = clientMessageId === void 0 ? {} : { clientMessageId };
5240
- const rest = input.type !== "message" ? input : steering && turnRunning ? { type: "message", content: input.content, ...id } : {
5252
+ const mode = input.type === "message" && input.mode ? { mode: input.mode } : {};
5253
+ const rest = input.type !== "message" ? input : steering && turnRunning ? { type: "message", content: input.content, ...mode, ...id } : {
5241
5254
  type: "message",
5242
5255
  content: input.content,
5243
5256
  ...input.agentType ? { agentType: input.agentType } : {},
5244
5257
  ...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {},
5258
+ ...mode,
5245
5259
  ...id
5246
5260
  };
5247
5261
  await this.dependencies.tasks.sendInput(this._taskId, rest);
package/dist/index.d.cts CHANGED
@@ -1101,8 +1101,8 @@ type AgentTaskInput = {
1101
1101
  reasoningEffort?: string;
1102
1102
  /**
1103
1103
  * With a turn running, as T3's composer: `queue` puts the message in T3's queue behind it and
1104
- * `steer` takes it into the running turn. A box given none lets T3 decide. The Copilot does
1105
- * not take the field.
1104
+ * `steer` takes it into the running turn. A box given none lets T3 decide. The Copilot passes
1105
+ * it to the box and steers a message sent without one.
1106
1106
  */
1107
1107
  mode?: "queue" | "steer";
1108
1108
  /**
@@ -2537,7 +2537,13 @@ interface AgentTaskSessionEventMap {
2537
2537
  raw: AgentTaskEvent;
2538
2538
  }
2539
2539
  /** The same shape `agentCredentials.usage` answers with. */
2540
- type AgentProviderUsage = CredentialUsage;
2540
+ type AgentProviderUsage = CredentialUsage & {
2541
+ /**
2542
+ * The provider the reading is of, as `agentCredentials.providers()` names it in
2543
+ * `AgentReadyProvider.provider`. Absent from a box that does not send it.
2544
+ */
2545
+ provider?: CopilotProvider;
2546
+ };
2541
2547
  interface AgentTaskSession {
2542
2548
  readonly taskId: string | null;
2543
2549
  readonly task: AgentTask | null;
package/dist/index.d.ts CHANGED
@@ -1101,8 +1101,8 @@ type AgentTaskInput = {
1101
1101
  reasoningEffort?: string;
1102
1102
  /**
1103
1103
  * With a turn running, as T3's composer: `queue` puts the message in T3's queue behind it and
1104
- * `steer` takes it into the running turn. A box given none lets T3 decide. The Copilot does
1105
- * not take the field.
1104
+ * `steer` takes it into the running turn. A box given none lets T3 decide. The Copilot passes
1105
+ * it to the box and steers a message sent without one.
1106
1106
  */
1107
1107
  mode?: "queue" | "steer";
1108
1108
  /**
@@ -2537,7 +2537,13 @@ interface AgentTaskSessionEventMap {
2537
2537
  raw: AgentTaskEvent;
2538
2538
  }
2539
2539
  /** The same shape `agentCredentials.usage` answers with. */
2540
- type AgentProviderUsage = CredentialUsage;
2540
+ type AgentProviderUsage = CredentialUsage & {
2541
+ /**
2542
+ * The provider the reading is of, as `agentCredentials.providers()` names it in
2543
+ * `AgentReadyProvider.provider`. Absent from a box that does not send it.
2544
+ */
2545
+ provider?: CopilotProvider;
2546
+ };
2541
2547
  interface AgentTaskSession {
2542
2548
  readonly taskId: string | null;
2543
2549
  readonly task: AgentTask | null;
package/dist/index.js CHANGED
@@ -4314,7 +4314,8 @@ function providerUsageOf(payload) {
4314
4314
  if (!payload) return null;
4315
4315
  try {
4316
4316
  const { harness, observedAt, status, windows } = expectCredentialUsage(payload, "providerUsage");
4317
- return { harness, observedAt, status, windows };
4317
+ const provider = typeof payload.provider === "string" && payload.provider ? payload.provider : null;
4318
+ return { harness, observedAt, status, windows, ...provider ? { provider } : {} };
4318
4319
  } catch {
4319
4320
  return null;
4320
4321
  }
@@ -4858,19 +4859,19 @@ var CoreAgentTaskSession = class {
4858
4859
  this.dispatch = dispatch;
4859
4860
  }
4860
4861
  async dispatchSend(prompt, options, clientMessageId, handedOver, waiter) {
4861
- if (this.openingPromise && !await this.openingPromise) {
4862
+ if (this.openingPromise && !await this.openingPromise && !this.isClosed()) {
4862
4863
  throw new Error("Agent task session could not be opened.");
4863
4864
  }
4864
- if (this.isClosed()) return false;
4865
+ if (this.isClosed() && !this._taskId) return false;
4865
4866
  await this.ensureTask();
4866
4867
  const input = messageInput(prompt, options);
4867
- if (this.isClosed()) {
4868
- await this.handOver(input, clientMessageId).catch(() => void 0);
4869
- return false;
4870
- }
4871
- await this.ensureChannel();
4872
- if (this.isClosed()) return false;
4868
+ if (this.isClosed()) return this.handOverAfterClose(input, clientMessageId, waiter);
4869
+ await this.ensureChannel().catch((error) => {
4870
+ if (!this.isClosed()) throw error;
4871
+ });
4872
+ if (this.isClosed()) return this.handOverAfterClose(input, clientMessageId, waiter);
4873
4873
  await this.captureTurnBaseline();
4874
+ if (this.isClosed()) return this.handOverAfterClose(input, clientMessageId, waiter);
4874
4875
  this._content = "";
4875
4876
  this.recoveryUsed = false;
4876
4877
  this.recoveredTerminalReason = void 0;
@@ -4888,6 +4889,17 @@ var CoreAgentTaskSession = class {
4888
4889
  this.acceptOnce(clientMessageId);
4889
4890
  return true;
4890
4891
  }
4892
+ // A prompt whose task exists is never dropped by close; the task outlives the session. Apps
4893
+ // close the creating session inside taskCreated and reopen by task id, so the input still goes
4894
+ // out over REST. Only a prompt that never reached `handOver` comes here: the Copilot does not
4895
+ // dedupe POST /inputs by `clientMessageId`, and a second copy would run a second turn. No
4896
+ // channel, status, or event for a closed session, and a failure has no listener left to hear it.
4897
+ // `close()` rejects only the waiter of a turn already open; this one has none yet.
4898
+ async handOverAfterClose(input, clientMessageId, waiter) {
4899
+ await this.handOver(input, clientMessageId).catch(() => void 0);
4900
+ waiter?.reject(new Error("Agent task session is closed."));
4901
+ return false;
4902
+ }
4891
4903
  // A message sent while a turn runs, or is being opened, goes out at once: the box takes it into
4892
4904
  // that turn (the provider's own steering), queues it for a turn of its own, or gives it one when
4893
4905
  // that turn already ended. Nothing waits in this session. On the direct channel it goes with an
@@ -5165,11 +5177,13 @@ var CoreAgentTaskSession = class {
5165
5177
  }
5166
5178
  const turnRunning = this._status === "streaming" || this._status === "cancelled";
5167
5179
  const id = clientMessageId === void 0 ? {} : { clientMessageId };
5168
- const rest = input.type !== "message" ? input : steering && turnRunning ? { type: "message", content: input.content, ...id } : {
5180
+ const mode = input.type === "message" && input.mode ? { mode: input.mode } : {};
5181
+ const rest = input.type !== "message" ? input : steering && turnRunning ? { type: "message", content: input.content, ...mode, ...id } : {
5169
5182
  type: "message",
5170
5183
  content: input.content,
5171
5184
  ...input.agentType ? { agentType: input.agentType } : {},
5172
5185
  ...input.reasoningEffort ? { reasoningEffort: input.reasoningEffort } : {},
5186
+ ...mode,
5173
5187
  ...id
5174
5188
  };
5175
5189
  await this.dependencies.tasks.sendInput(this._taskId, rest);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mitralab.io/sdk-core",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "description": "Environment-neutral contracts and modules shared by Mitra JavaScript SDKs",
5
5
  "type": "module",
6
6
  "sideEffects": false,