@drisp/protocol 0.8.3 → 0.8.4

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/v2.d.ts CHANGED
@@ -29,7 +29,7 @@ declare function attemptCost(attempt: {
29
29
 
30
30
  declare const protocolVersion: {
31
31
  readonly major: 2;
32
- readonly minor: 2;
32
+ readonly minor: 3;
33
33
  };
34
34
  declare const conversationContinuationCapability = "conversation_continuation";
35
35
  declare const abandonedConversationContinuationCapability = "abandoned_conversation_continuation";
@@ -41,6 +41,12 @@ declare const workflowInstallCapability = "workflow_install_v1";
41
41
  * token to the agent as `DRISP_RUN_TOKEN`. A start with `delegation` is never sent to a runner without it.
42
42
  */
43
43
  declare const runDelegationCapability = "run_delegation_v1";
44
+ /**
45
+ * The runner takes grants marked `reportUsage` (protocol minor 3, root ADR-0011) and, for those only, reports the
46
+ * Run's usage: on `run.attention` and `run.finished`, and as `run.usage` while it executes. A Hub that does not know
47
+ * these fields never marks a grant, so it never receives them.
48
+ */
49
+ declare const runUsageCapability = "run_usage_v1";
44
50
  /** The prefix of every delegation token; the Hub keeps only its digest. */
45
51
  declare const delegationTokenPrefix = "drisp_dlg_";
46
52
  /** A `run.artifact` history record's `name`, and the most its `json` may take serialized. */
@@ -168,6 +174,15 @@ declare const runCloseReasonSchema: z.ZodEnum<{
168
174
  legacy_force_failed: "legacy_force_failed";
169
175
  }>;
170
176
  type RunCloseReason = z.infer<typeof runCloseReasonSchema>;
177
+ /**
178
+ * A Run's cumulative usage (root ADR-0011): `counted` is its tokens without cache reads (`total − cacheRead`), the unit
179
+ * the Run cap counts on every harness, and `cacheRead` the cache reads left out of it.
180
+ */
181
+ declare const runUsageSchema: z.ZodObject<{
182
+ counted: z.ZodNumber;
183
+ cacheRead: z.ZodNumber;
184
+ }, z.core.$strict>;
185
+ type RunUsage = z.infer<typeof runUsageSchema>;
171
186
  declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
172
187
  kind: z.ZodLiteral<"workflows.changed">;
173
188
  workflows: z.ZodArray<z.ZodObject<{
@@ -227,6 +242,10 @@ declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
227
242
  emittedAt: z.ZodISODateTime;
228
243
  kind: z.ZodLiteral<"run.resumed">;
229
244
  }, z.core.$strict>, z.ZodObject<{
245
+ usage: z.ZodOptional<z.ZodObject<{
246
+ counted: z.ZodNumber;
247
+ cacheRead: z.ZodNumber;
248
+ }, z.core.$strict>>;
230
249
  interruption: z.ZodObject<{
231
250
  interruptionId: z.ZodString;
232
251
  revision: z.ZodNumber;
@@ -263,6 +282,10 @@ declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
263
282
  emittedAt: z.ZodISODateTime;
264
283
  kind: z.ZodLiteral<"run.attention">;
265
284
  }, z.core.$strict>, z.ZodObject<{
285
+ usage: z.ZodOptional<z.ZodObject<{
286
+ counted: z.ZodNumber;
287
+ cacheRead: z.ZodNumber;
288
+ }, z.core.$strict>>;
266
289
  status: z.ZodEnum<{
267
290
  completed: "completed";
268
291
  failed: "failed";
@@ -281,6 +304,12 @@ declare const controlRecordSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
281
304
  executionRevision: z.ZodNumber;
282
305
  emittedAt: z.ZodISODateTime;
283
306
  kind: z.ZodLiteral<"run.finished">;
307
+ }, z.core.$strict>, z.ZodObject<{
308
+ counted: z.ZodNumber;
309
+ cacheRead: z.ZodNumber;
310
+ kind: z.ZodLiteral<"run.usage">;
311
+ runId: z.ZodString;
312
+ attemptId: z.ZodString;
284
313
  }, z.core.$strict>, z.ZodObject<{
285
314
  kind: z.ZodLiteral<"command.applied">;
286
315
  runId: z.ZodString;
@@ -531,6 +560,7 @@ declare const grantSchema: z.ZodObject<{
531
560
  runId: z.ZodString;
532
561
  tokenCap: z.ZodNumber;
533
562
  }, z.core.$strict>>;
563
+ reportUsage: z.ZodOptional<z.ZodLiteral<true>>;
534
564
  }, z.core.$strict>;
535
565
  declare const historyRecordSchema: z.ZodObject<{
536
566
  eventId: z.ZodString;
@@ -645,6 +675,10 @@ declare const runnerFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
645
675
  emittedAt: z.ZodISODateTime;
646
676
  kind: z.ZodLiteral<"run.resumed">;
647
677
  }, z.core.$strict>, z.ZodObject<{
678
+ usage: z.ZodOptional<z.ZodObject<{
679
+ counted: z.ZodNumber;
680
+ cacheRead: z.ZodNumber;
681
+ }, z.core.$strict>>;
648
682
  interruption: z.ZodObject<{
649
683
  interruptionId: z.ZodString;
650
684
  revision: z.ZodNumber;
@@ -681,6 +715,10 @@ declare const runnerFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
681
715
  emittedAt: z.ZodISODateTime;
682
716
  kind: z.ZodLiteral<"run.attention">;
683
717
  }, z.core.$strict>, z.ZodObject<{
718
+ usage: z.ZodOptional<z.ZodObject<{
719
+ counted: z.ZodNumber;
720
+ cacheRead: z.ZodNumber;
721
+ }, z.core.$strict>>;
684
722
  status: z.ZodEnum<{
685
723
  completed: "completed";
686
724
  failed: "failed";
@@ -699,6 +737,12 @@ declare const runnerFrameSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
699
737
  executionRevision: z.ZodNumber;
700
738
  emittedAt: z.ZodISODateTime;
701
739
  kind: z.ZodLiteral<"run.finished">;
740
+ }, z.core.$strict>, z.ZodObject<{
741
+ counted: z.ZodNumber;
742
+ cacheRead: z.ZodNumber;
743
+ kind: z.ZodLiteral<"run.usage">;
744
+ runId: z.ZodString;
745
+ attemptId: z.ZodString;
702
746
  }, z.core.$strict>, z.ZodObject<{
703
747
  kind: z.ZodLiteral<"command.applied">;
704
748
  runId: z.ZodString;
@@ -779,6 +823,10 @@ declare const runViewSchema: z.ZodObject<{
779
823
  delegation: z.ZodOptional<z.ZodObject<{
780
824
  maxChildren: z.ZodNumber;
781
825
  tokenBudget: z.ZodNumber;
826
+ }, z.core.$strip>>;
827
+ usage: z.ZodOptional<z.ZodObject<{
828
+ counted: z.ZodNumber;
829
+ cacheRead: z.ZodNumber;
782
830
  }, z.core.$strict>>;
783
831
  workflow: z.ZodOptional<z.ZodObject<{
784
832
  name: z.ZodString;
@@ -1068,6 +1116,7 @@ declare const checkpointSchema: z.ZodObject<{
1068
1116
  runId: z.ZodString;
1069
1117
  tokenCap: z.ZodNumber;
1070
1118
  }, z.core.$strict>>;
1119
+ reportUsage: z.ZodOptional<z.ZodLiteral<true>>;
1071
1120
  }, z.core.$strict>;
1072
1121
  gitHead: z.ZodString;
1073
1122
  gitBase: z.ZodOptional<z.ZodString>;
@@ -1427,4 +1476,4 @@ type ConnectPendingResponse = z.infer<typeof connectPendingResponseSchema>;
1427
1476
  type TeamDefault = z.infer<typeof teamDefaultSchema>;
1428
1477
  type RunsGoTo = z.infer<typeof runsGoToSchema>;
1429
1478
 
1430
- export { type Audience, type BuildCloseReason, type Checkpoint, type Command, type ConnectAlreadyConnected, type ConnectPendingResponse, type ConnectRedeemRequest, type ConnectRedeemResponse, type ConnectStartRequest, type ConnectStartResponse, type ControlRecord, type Delegation, type ExecutionFact, type Grant, type Harness, type HarnessReadiness, type HistoryRecord, type InstalledWorkflow, type RepositoryBinding, type RepositorySource, type RunCloseReason, type RunParent, type RunView, type RunnerAdoptRequest, type RunnerDisconnectPreview, type RunnerDisconnectResponse, type RunnerFrame, type RunnerList, type RunnerListEntry, type RunnerReadiness, type RunsGoTo, SIZE_CLASS_CAPS, SIZE_CLASS_FORECASTS, type Scope, type SizeClass, type TeamDefault, type WorkflowIdentity, type WorkflowInstallReference, type WorkflowReference, abandonedConversationContinuationCapability, attemptCost, audienceSchema, buildCloseReasonSchema, canonicalJson, checkpointPathSchema, checkpointSchema, classOfCap, clientFrameSchema, commandSchema, connectAlreadyConnectedSchema, connectApproveRequestSchema, connectCodeAlphabet, connectCodeRequestSchema, connectCodeResponseSchema, connectCodeSchema, connectDenyRequestSchema, connectPendingResponseSchema, connectPollRequestSchema, connectRedeemRequestSchema, connectRedeemResponseSchema, connectStartRequestSchema, connectStartResponseSchema, controlRecordSchema, conversationContinuationCapability, delegationSchema, delegationTokenPrefix, forecastOfCap, grantSchema, harnessReadinessSchema, harnessSchema, historyRecordSchema, hubEpochRequestSchema, installReference, installedWorkflowsSchema, interruptionSchema, permissionAnswerSchema, protocolVersion, readableHistory, readinessFixCommand, repositoryAccessCapability, repositoryBindingSchema, repositoryRefSchema, repositorySourceSchema, repositoryWorkingDirectorySchema, runArtifactMaxBytes, runArtifactNameSchema, runCloseReasonSchema, runDelegationCapability, runKeySchema, runParentIntentSchema, runParentSchema, runSpecSchema, runViewSchema, runnerAdoptRequestSchema, runnerDisconnectPreviewSchema, runnerDisconnectRequestSchema, runnerDisconnectResponseSchema, runnerFrameSchema, runnerListEntrySchema, runnerListSchema, runnerReadinessSchema, runnerUpdateCommand, runnerUpdateRequestSchema, runsGoToSchema, sameWorkflow, scopeSchema, secretEnvironmentSchema, sequence, teamDefaultRequestSchema, teamDefaultSchema, workflowIdentitySchema, workflowInstallCapability, workflowName, workflowReferenceSchema, workflowSourceSchema };
1479
+ export { type Audience, type BuildCloseReason, type Checkpoint, type Command, type ConnectAlreadyConnected, type ConnectPendingResponse, type ConnectRedeemRequest, type ConnectRedeemResponse, type ConnectStartRequest, type ConnectStartResponse, type ControlRecord, type Delegation, type ExecutionFact, type Grant, type Harness, type HarnessReadiness, type HistoryRecord, type InstalledWorkflow, type RepositoryBinding, type RepositorySource, type RunCloseReason, type RunParent, type RunUsage, type RunView, type RunnerAdoptRequest, type RunnerDisconnectPreview, type RunnerDisconnectResponse, type RunnerFrame, type RunnerList, type RunnerListEntry, type RunnerReadiness, type RunsGoTo, SIZE_CLASS_CAPS, SIZE_CLASS_FORECASTS, type Scope, type SizeClass, type TeamDefault, type WorkflowIdentity, type WorkflowInstallReference, type WorkflowReference, abandonedConversationContinuationCapability, attemptCost, audienceSchema, buildCloseReasonSchema, canonicalJson, checkpointPathSchema, checkpointSchema, classOfCap, clientFrameSchema, commandSchema, connectAlreadyConnectedSchema, connectApproveRequestSchema, connectCodeAlphabet, connectCodeRequestSchema, connectCodeResponseSchema, connectCodeSchema, connectDenyRequestSchema, connectPendingResponseSchema, connectPollRequestSchema, connectRedeemRequestSchema, connectRedeemResponseSchema, connectStartRequestSchema, connectStartResponseSchema, controlRecordSchema, conversationContinuationCapability, delegationSchema, delegationTokenPrefix, forecastOfCap, grantSchema, harnessReadinessSchema, harnessSchema, historyRecordSchema, hubEpochRequestSchema, installReference, installedWorkflowsSchema, interruptionSchema, permissionAnswerSchema, protocolVersion, readableHistory, readinessFixCommand, repositoryAccessCapability, repositoryBindingSchema, repositoryRefSchema, repositorySourceSchema, repositoryWorkingDirectorySchema, runArtifactMaxBytes, runArtifactNameSchema, runCloseReasonSchema, runDelegationCapability, runKeySchema, runParentIntentSchema, runParentSchema, runSpecSchema, runUsageCapability, runUsageSchema, runViewSchema, runnerAdoptRequestSchema, runnerDisconnectPreviewSchema, runnerDisconnectRequestSchema, runnerDisconnectResponseSchema, runnerFrameSchema, runnerListEntrySchema, runnerListSchema, runnerReadinessSchema, runnerUpdateCommand, runnerUpdateRequestSchema, runsGoToSchema, sameWorkflow, scopeSchema, secretEnvironmentSchema, sequence, teamDefaultRequestSchema, teamDefaultSchema, workflowIdentitySchema, workflowInstallCapability, workflowName, workflowReferenceSchema, workflowSourceSchema };
package/dist/v2.js CHANGED
@@ -73,12 +73,13 @@ function attemptCost(attempt) {
73
73
  }
74
74
 
75
75
  // src/v2.ts
76
- var protocolVersion = { major: 2, minor: 2 };
76
+ var protocolVersion = { major: 2, minor: 3 };
77
77
  var conversationContinuationCapability = "conversation_continuation";
78
78
  var abandonedConversationContinuationCapability = "abandoned_conversation_continuation";
79
79
  var repositoryAccessCapability = "repository_checkout_v1";
80
80
  var workflowInstallCapability = "workflow_install_v1";
81
81
  var runDelegationCapability = "run_delegation_v1";
82
+ var runUsageCapability = "run_usage_v1";
82
83
  var delegationTokenPrefix = "drisp_dlg_";
83
84
  var runArtifactNameSchema = z.string().regex(/^[a-z][a-z0-9_]{0,63}$/);
84
85
  var runArtifactMaxBytes = 64 * 1024;
@@ -158,6 +159,8 @@ var factIdentity = {
158
159
  executionRevision: positive,
159
160
  emittedAt: timestamp
160
161
  };
162
+ var runUsageSchema = z.strictObject({ counted: sequence, cacheRead: sequence });
163
+ var reportedUsage = { usage: runUsageSchema.optional() };
161
164
  var controlRecordSchema = z.discriminatedUnion("kind", [
162
165
  /** Instance-scoped, not tied to a Run: the full replacement inventory of installed Workflows. */
163
166
  z.strictObject({ kind: z.literal("workflows.changed"), workflows: installedWorkflowsSchema }),
@@ -188,7 +191,8 @@ var controlRecordSchema = z.discriminatedUnion("kind", [
188
191
  z.strictObject({ kind: z.literal("local_checkpoint"), checkpointId: id }),
189
192
  z.strictObject({ kind: z.literal("portable_checkpoint"), checkpointId: id }),
190
193
  z.strictObject({ kind: z.literal("repair_required"), detail: z.string().max(4096) })
191
- ])
194
+ ]),
195
+ ...reportedUsage
192
196
  }),
193
197
  z.strictObject({
194
198
  kind: z.literal("run.finished"),
@@ -201,8 +205,14 @@ var controlRecordSchema = z.discriminatedUnion("kind", [
201
205
  * Why a Build Run failed, as its close reason (docs/specs/build-orchestrator.md). Sent only for a grant with
202
206
  * `parent` or `delegationToken`, which only a Hub that knows this field issues.
203
207
  */
204
- reason: buildCloseReasonSchema.optional()
208
+ reason: buildCloseReasonSchema.optional(),
209
+ ...reportedUsage
205
210
  }),
211
+ /**
212
+ * The usage of a Run while it executes, for a grant marked `reportUsage`. Not an execution fact: it carries no
213
+ * execution revision, so it never advances, parks or closes the Run, and never wakes its parent.
214
+ */
215
+ z.strictObject({ kind: z.literal("run.usage"), runId: id, attemptId: id, ...runUsageSchema.shape }),
206
216
  z.strictObject({ kind: z.literal("command.applied"), runId: id, attemptId: id, commandId: id }),
207
217
  z.strictObject({
208
218
  kind: z.literal("command.rejected"),
@@ -341,7 +351,9 @@ var grantSchema = z.strictObject({
341
351
  /** This attempt's delegation token: only for a Run started with `delegation`, only to a `run_delegation_v1` Runner. */
342
352
  delegationToken: z.string().min(32).max(256).optional(),
343
353
  /** Copied from the start intent of a delegated child. */
344
- parent: runParentSchema.optional()
354
+ parent: runParentSchema.optional(),
355
+ /** The runner reports this attempt's usage: set only for a `run_usage_v1` Runner. */
356
+ reportUsage: z.literal(true).optional()
345
357
  });
346
358
  var historyRecordSchema = z.strictObject({
347
359
  eventId: id,
@@ -402,7 +414,13 @@ var runViewSchema = z.object({
402
414
  label: z.string().max(160).optional(),
403
415
  key: runKeySchema.optional(),
404
416
  parent: runParentSchema.optional(),
405
- delegation: delegationSchema.optional(),
417
+ /**
418
+ * Not strict, unlike the start intent's: a Hub keeps more on the Run's delegation (`initialTokenBudget`) than it
419
+ * shows, and a client never refuses a view for a field it does not read.
420
+ */
421
+ delegation: z.object(delegationSchema.shape).optional(),
422
+ /** The largest cumulative usage the Run's Runner reported; absent until one does (an older Runner never does). */
423
+ usage: runUsageSchema.optional(),
406
424
  /** Resolved by the runner at start; absent until the Run starts and for runners that predate reporting. */
407
425
  workflow: workflowIdentitySchema.optional(),
408
426
  execution: z.object({
@@ -679,6 +697,8 @@ export {
679
697
  runParentIntentSchema,
680
698
  runParentSchema,
681
699
  runSpecSchema,
700
+ runUsageCapability,
701
+ runUsageSchema,
682
702
  runViewSchema,
683
703
  runnerAdoptRequestSchema,
684
704
  runnerDisconnectPreviewSchema,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drisp/protocol",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "Wire contract between a drisp runner and the hub: zod schemas, inferred types, and JSON Schema for the instance-socket frames, Run, Turn, Interruption, and the event stream",
5
5
  "repository": {
6
6
  "type": "git",
@@ -357,6 +357,10 @@
357
357
  "tokenCap"
358
358
  ],
359
359
  "additionalProperties": false
360
+ },
361
+ "reportUsage": {
362
+ "type": "boolean",
363
+ "const": true
360
364
  }
361
365
  },
362
366
  "required": [
@@ -308,6 +308,10 @@
308
308
  "tokenCap"
309
309
  ],
310
310
  "additionalProperties": false
311
+ },
312
+ "reportUsage": {
313
+ "type": "boolean",
314
+ "const": true
311
315
  }
312
316
  },
313
317
  "required": [
@@ -112,6 +112,26 @@
112
112
  ],
113
113
  "additionalProperties": false
114
114
  },
115
+ "usage": {
116
+ "type": "object",
117
+ "properties": {
118
+ "counted": {
119
+ "type": "integer",
120
+ "minimum": 0,
121
+ "maximum": 9007199254740991
122
+ },
123
+ "cacheRead": {
124
+ "type": "integer",
125
+ "minimum": 0,
126
+ "maximum": 9007199254740991
127
+ }
128
+ },
129
+ "required": [
130
+ "counted",
131
+ "cacheRead"
132
+ ],
133
+ "additionalProperties": false
134
+ },
115
135
  "workflow": {
116
136
  "type": "object",
117
137
  "properties": {
@@ -720,6 +720,26 @@
720
720
  "additionalProperties": false
721
721
  }
722
722
  ]
723
+ },
724
+ "usage": {
725
+ "type": "object",
726
+ "properties": {
727
+ "counted": {
728
+ "type": "integer",
729
+ "minimum": 0,
730
+ "maximum": 9007199254740991
731
+ },
732
+ "cacheRead": {
733
+ "type": "integer",
734
+ "minimum": 0,
735
+ "maximum": 9007199254740991
736
+ }
737
+ },
738
+ "required": [
739
+ "counted",
740
+ "cacheRead"
741
+ ],
742
+ "additionalProperties": false
723
743
  }
724
744
  },
725
745
  "required": [
@@ -787,6 +807,26 @@
787
807
  "build_not_approved",
788
808
  "approval_question_missing"
789
809
  ]
810
+ },
811
+ "usage": {
812
+ "type": "object",
813
+ "properties": {
814
+ "counted": {
815
+ "type": "integer",
816
+ "minimum": 0,
817
+ "maximum": 9007199254740991
818
+ },
819
+ "cacheRead": {
820
+ "type": "integer",
821
+ "minimum": 0,
822
+ "maximum": 9007199254740991
823
+ }
824
+ },
825
+ "required": [
826
+ "counted",
827
+ "cacheRead"
828
+ ],
829
+ "additionalProperties": false
790
830
  }
791
831
  },
792
832
  "required": [
@@ -800,6 +840,43 @@
800
840
  ],
801
841
  "additionalProperties": false
802
842
  },
843
+ {
844
+ "type": "object",
845
+ "properties": {
846
+ "kind": {
847
+ "type": "string",
848
+ "const": "run.usage"
849
+ },
850
+ "runId": {
851
+ "type": "string",
852
+ "minLength": 1,
853
+ "maxLength": 160
854
+ },
855
+ "attemptId": {
856
+ "type": "string",
857
+ "minLength": 1,
858
+ "maxLength": 160
859
+ },
860
+ "counted": {
861
+ "type": "integer",
862
+ "minimum": 0,
863
+ "maximum": 9007199254740991
864
+ },
865
+ "cacheRead": {
866
+ "type": "integer",
867
+ "minimum": 0,
868
+ "maximum": 9007199254740991
869
+ }
870
+ },
871
+ "required": [
872
+ "kind",
873
+ "runId",
874
+ "attemptId",
875
+ "counted",
876
+ "cacheRead"
877
+ ],
878
+ "additionalProperties": false
879
+ },
803
880
  {
804
881
  "type": "object",
805
882
  "properties": {