@byok-sdk/cloud 0.13.0 → 0.14.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.
@@ -14,12 +14,46 @@ export declare const ActivityAppendRequestSchema: z.ZodObject<{
14
14
  tool: z.ZodString;
15
15
  input: z.ZodOptional<z.ZodUnknown>;
16
16
  toolCallId: z.ZodOptional<z.ZodString>;
17
+ spill: z.ZodOptional<z.ZodObject<{
18
+ field: z.ZodEnum<{
19
+ input: "input";
20
+ output: "output";
21
+ }>;
22
+ totalBytes: z.ZodNumber;
23
+ omittedBytes: z.ZodNumber;
24
+ contentType: z.ZodLiteral<"application/json">;
25
+ blob: z.ZodOptional<z.ZodObject<{
26
+ blobId: z.ZodString;
27
+ contentHash: z.ZodString;
28
+ size: z.ZodNumber;
29
+ contentType: z.ZodString;
30
+ url: z.ZodOptional<z.ZodString>;
31
+ }, z.core.$strip>>;
32
+ unstoredReason: z.ZodOptional<z.ZodString>;
33
+ }, z.core.$strict>>;
17
34
  }, z.core.$strip>, z.ZodObject<{
18
35
  type: z.ZodLiteral<"tool_result">;
19
36
  tool: z.ZodString;
20
37
  output: z.ZodOptional<z.ZodUnknown>;
21
38
  toolCallId: z.ZodOptional<z.ZodString>;
22
39
  isError: z.ZodOptional<z.ZodBoolean>;
40
+ spill: z.ZodOptional<z.ZodObject<{
41
+ field: z.ZodEnum<{
42
+ input: "input";
43
+ output: "output";
44
+ }>;
45
+ totalBytes: z.ZodNumber;
46
+ omittedBytes: z.ZodNumber;
47
+ contentType: z.ZodLiteral<"application/json">;
48
+ blob: z.ZodOptional<z.ZodObject<{
49
+ blobId: z.ZodString;
50
+ contentHash: z.ZodString;
51
+ size: z.ZodNumber;
52
+ contentType: z.ZodString;
53
+ url: z.ZodOptional<z.ZodString>;
54
+ }, z.core.$strip>>;
55
+ unstoredReason: z.ZodOptional<z.ZodString>;
56
+ }, z.core.$strict>>;
23
57
  }, z.core.$strip>, z.ZodObject<{
24
58
  type: z.ZodLiteral<"artifact">;
25
59
  name: z.ZodString;
@@ -59,12 +93,46 @@ export declare const TimelineEventSchema: z.ZodObject<{
59
93
  tool: z.ZodString;
60
94
  input: z.ZodOptional<z.ZodUnknown>;
61
95
  toolCallId: z.ZodOptional<z.ZodString>;
96
+ spill: z.ZodOptional<z.ZodObject<{
97
+ field: z.ZodEnum<{
98
+ input: "input";
99
+ output: "output";
100
+ }>;
101
+ totalBytes: z.ZodNumber;
102
+ omittedBytes: z.ZodNumber;
103
+ contentType: z.ZodLiteral<"application/json">;
104
+ blob: z.ZodOptional<z.ZodObject<{
105
+ blobId: z.ZodString;
106
+ contentHash: z.ZodString;
107
+ size: z.ZodNumber;
108
+ contentType: z.ZodString;
109
+ url: z.ZodOptional<z.ZodString>;
110
+ }, z.core.$strip>>;
111
+ unstoredReason: z.ZodOptional<z.ZodString>;
112
+ }, z.core.$strict>>;
62
113
  }, z.core.$strip>, z.ZodObject<{
63
114
  type: z.ZodLiteral<"tool_result">;
64
115
  tool: z.ZodString;
65
116
  output: z.ZodOptional<z.ZodUnknown>;
66
117
  toolCallId: z.ZodOptional<z.ZodString>;
67
118
  isError: z.ZodOptional<z.ZodBoolean>;
119
+ spill: z.ZodOptional<z.ZodObject<{
120
+ field: z.ZodEnum<{
121
+ input: "input";
122
+ output: "output";
123
+ }>;
124
+ totalBytes: z.ZodNumber;
125
+ omittedBytes: z.ZodNumber;
126
+ contentType: z.ZodLiteral<"application/json">;
127
+ blob: z.ZodOptional<z.ZodObject<{
128
+ blobId: z.ZodString;
129
+ contentHash: z.ZodString;
130
+ size: z.ZodNumber;
131
+ contentType: z.ZodString;
132
+ url: z.ZodOptional<z.ZodString>;
133
+ }, z.core.$strip>>;
134
+ unstoredReason: z.ZodOptional<z.ZodString>;
135
+ }, z.core.$strict>>;
68
136
  }, z.core.$strip>, z.ZodObject<{
69
137
  type: z.ZodLiteral<"artifact">;
70
138
  name: z.ZodString;
package/dist/inbound.d.ts CHANGED
@@ -13,13 +13,12 @@
13
13
  * authenticated long-poll `conn.hello` capability snapshot handled below.
14
14
  * A server -> daemon type arriving inbound, or anything unrecognized, is
15
15
  * rejected before it is dispatched or counted accepted.
16
- * 2. **ownership** — an envelope for a task already owned by a DIFFERENT
17
- * device is dropped, never force-failed: force-failing on an authz mismatch
16
+ * 2. **ownership** — an envelope must name an existing task targeted at this
17
+ * exact device, and a task already owned by a DIFFERENT device is dropped,
18
+ * never force-failed: force-failing on an authz mismatch
18
19
  * would let an attacker who merely guesses a `taskId` kill the real owner's
19
- * task. A task with no owner yet, or that this tenant does not have at all,
20
- * is not rejected here — the store's own no-op-on-missing behavior covers
21
- * the latter, and it covers it per tenant, so a guessed id from another
22
- * tenant writes nothing anywhere.
20
+ * task. Unknown task ids are rejected before any task-scoped projection or
21
+ * dedup fact can be written.
23
22
  * 3. **apply/recover** — every lifecycle side effect is idempotent under the
24
23
  * envelope's own durable identity. A retry after a partial failure resumes
25
24
  * this step rather than being hidden by transport admission.
package/dist/index.js CHANGED
@@ -1453,12 +1453,12 @@ async function applyInboundGate(stores, deviceId, envelope, activityBounds, agen
1453
1453
  const taskId = envelope.task_id;
1454
1454
  if (taskId === void 0) return "rejected";
1455
1455
  const attempt = await stores.tasks.get(taskId);
1456
- if (attempt?.agentRef !== void 0 && attempt.deviceId !== deviceId) return "rejected";
1456
+ if (attempt === void 0 || attempt.deviceId !== deviceId) return "rejected";
1457
1457
  if (attempt?.ownerDeviceId !== void 0 && attempt.ownerDeviceId !== deviceId) return "rejected";
1458
+ if (envelope.type === "task.claim" && envelope.payload.deviceId !== deviceId) return "rejected";
1458
1459
  if (attempt?.agentRef !== void 0 && agentRefEchoRequired(envelope) && !sameAgentRef(attempt.agentRef, inboundAgentRef(envelope))) {
1459
1460
  return "rejected";
1460
1461
  }
1461
- if (terminalStatus(envelope) !== void 0 && attempt === void 0) return "rejected";
1462
1462
  if (envelope.type === "task.progress" && envelope.payload.events.length > 0) {
1463
1463
  try {
1464
1464
  validateActivityBatch(
@@ -1587,13 +1587,11 @@ async function recordTerminal(stores, taskId, envelope) {
1587
1587
  }
1588
1588
  const attempt = await stores.tasks.get(taskId);
1589
1589
  if (attempt?.cancellation !== void 0) {
1590
- if (winner.status === "cancelled") {
1591
- await stores.tasks.recordStatus({
1592
- taskId,
1593
- status: "cancelled",
1594
- ...attempt.agentRef === void 0 ? {} : { agentRef: attempt.agentRef }
1595
- });
1596
- }
1590
+ await stores.tasks.recordStatus({
1591
+ taskId,
1592
+ status: "cancelled",
1593
+ ...attempt.agentRef === void 0 ? {} : { agentRef: attempt.agentRef }
1594
+ });
1597
1595
  return;
1598
1596
  }
1599
1597
  const recordedAttempt = await stores.tasks.recordStatus({
@@ -1602,7 +1600,16 @@ async function recordTerminal(stores, taskId, envelope) {
1602
1600
  ...attempt?.agentRef === void 0 ? {} : { agentRef: attempt.agentRef },
1603
1601
  ...winner.cause === void 0 ? {} : { terminalCause: winner.cause }
1604
1602
  });
1605
- if (recordedAttempt?.status !== winner.status || recordedAttempt.cancellation !== void 0) return;
1603
+ if (recordedAttempt?.cancellation !== void 0 || recordedAttempt?.status !== winner.status) {
1604
+ if (recordedAttempt?.cancellation !== void 0) {
1605
+ await stores.tasks.recordStatus({
1606
+ taskId,
1607
+ status: "cancelled",
1608
+ ...recordedAttempt.agentRef === void 0 ? {} : { agentRef: recordedAttempt.agentRef }
1609
+ });
1610
+ }
1611
+ return;
1612
+ }
1606
1613
  await projectTerminalToReview(stores.board, taskId);
1607
1614
  }
1608
1615
  function terminalStatus(envelope) {
@@ -2905,10 +2912,10 @@ function createByokCloud(options) {
2905
2912
  }
2906
2913
  const offerReceiptKey = `task-offer:${messageId}`;
2907
2914
  const deliveryReceiptKey = `task-offer-delivered:${messageId}`;
2908
- if (agentRef !== void 0 && reservation?.created === false && await stores.receipts.get(deliveryReceiptKey) !== void 0) {
2915
+ if (await stores.receipts.get(deliveryReceiptKey) !== void 0) {
2909
2916
  throw new ByokCloudError(
2910
- "agent_task_already_exists",
2911
- `Task ${taskId} already has a durable Agent attempt and cannot be enqueued again.`
2917
+ agentRef === void 0 ? "coordination_input_invalid" : "agent_task_already_exists",
2918
+ `Task ${taskId} already has a durable delivered attempt and cannot be enqueued again.`
2912
2919
  );
2913
2920
  }
2914
2921
  const proposed = buildEnvelope(taskId, 0, messageId);
@@ -2955,14 +2962,12 @@ function createByokCloud(options) {
2955
2962
  `Task ${taskId} already has a different executable offer body.`
2956
2963
  );
2957
2964
  }
2958
- if (agentRef !== void 0) {
2959
- const delivered = await stores.receipts.record({ key: deliveryReceiptKey, body: messageId });
2960
- if (reservation?.created === false && !delivered.created) {
2961
- throw new ByokCloudError(
2962
- "agent_task_already_exists",
2963
- `Task ${taskId} already has a durable Agent attempt and cannot be enqueued again.`
2964
- );
2965
- }
2965
+ const delivered = await stores.receipts.record({ key: deliveryReceiptKey, body: messageId });
2966
+ if (agentRef !== void 0 && reservation?.created === false && !delivered.created) {
2967
+ throw new ByokCloudError(
2968
+ "agent_task_already_exists",
2969
+ `Task ${taskId} already has a durable Agent attempt and cannot be enqueued again.`
2970
+ );
2966
2971
  }
2967
2972
  return { taskId, seq: message.seq, envelope, attempt: openedBeforeAppend };
2968
2973
  }
@@ -4355,7 +4360,7 @@ var InMemoryTaskAttemptStore = class {
4355
4360
  return this.#state.mutate(key, () => {
4356
4361
  const existing = this.#state.attempts.get(key);
4357
4362
  if (existing === void 0) return void 0;
4358
- if (existing.ownerDeviceId !== void 0 || existing.cancellation !== void 0 || existing.status !== "offered") return existing;
4363
+ if (existing.deviceId !== input.deviceId || existing.ownerDeviceId !== void 0 || existing.cancellation !== void 0 || existing.status !== "offered") return existing;
4359
4364
  const claimed = {
4360
4365
  ...existing,
4361
4366
  ownerDeviceId: input.deviceId,