@dxos/compute 0.16.0 → 0.17.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.
Files changed (136) hide show
  1. package/dist/lib/AiMetering.mjs +1 -0
  2. package/dist/lib/Hook.mjs +1 -0
  3. package/dist/lib/Operation.mjs +3 -3
  4. package/dist/lib/Process.mjs +2 -2
  5. package/dist/lib/Trace.mjs +1 -1
  6. package/dist/lib/chunk-AgentIdentity.mjs +1 -1
  7. package/dist/lib/chunk-AgentService.mjs.map +1 -1
  8. package/dist/lib/chunk-AiMetering.mjs +77 -0
  9. package/dist/lib/chunk-AiMetering.mjs.map +1 -0
  10. package/dist/lib/chunk-Cancellation.mjs +1 -1
  11. package/dist/lib/chunk-Hook.mjs +78 -0
  12. package/dist/lib/chunk-Hook.mjs.map +1 -0
  13. package/dist/lib/chunk-Instructions.mjs +1 -1
  14. package/dist/lib/chunk-Operation.mjs +169 -5
  15. package/dist/lib/chunk-Operation.mjs.map +1 -1
  16. package/dist/lib/chunk-OperationHandlerSet.mjs +1 -1
  17. package/dist/lib/chunk-OperationRegistry.mjs +1 -1
  18. package/dist/lib/chunk-OperationRegistry.mjs.map +1 -1
  19. package/dist/lib/chunk-Process.mjs +18 -10
  20. package/dist/lib/chunk-Process.mjs.map +1 -1
  21. package/dist/lib/chunk-Project.mjs +52 -24
  22. package/dist/lib/chunk-Project.mjs.map +1 -1
  23. package/dist/lib/chunk-Reducer.mjs +827 -0
  24. package/dist/lib/chunk-Reducer.mjs.map +1 -0
  25. package/dist/lib/chunk-Routine.mjs +1 -1
  26. package/dist/lib/chunk-Runnable.mjs +1 -1
  27. package/dist/lib/chunk-ServiceResolver.mjs +1 -1
  28. package/dist/lib/chunk-Skill.mjs +10 -47
  29. package/dist/lib/chunk-Skill.mjs.map +1 -1
  30. package/dist/lib/chunk-Spec.mjs +49 -0
  31. package/dist/lib/chunk-Spec.mjs.map +1 -0
  32. package/dist/lib/chunk-SpecReview.mjs +98 -0
  33. package/dist/lib/chunk-SpecReview.mjs.map +1 -0
  34. package/dist/lib/chunk-SqlService.mjs.map +1 -1
  35. package/dist/lib/chunk-StorageService.mjs +1 -1
  36. package/dist/lib/chunk-Template.mjs +2 -2
  37. package/dist/lib/chunk-Trace.mjs +97 -13
  38. package/dist/lib/chunk-Trace.mjs.map +1 -1
  39. package/dist/lib/chunk-Trajectory.mjs +326 -0
  40. package/dist/lib/chunk-Trajectory.mjs.map +1 -0
  41. package/dist/lib/chunk-Transcript.mjs +84 -0
  42. package/dist/lib/chunk-Transcript.mjs.map +1 -0
  43. package/dist/lib/chunk-definitions.mjs +1 -1
  44. package/dist/lib/errors.mjs +3 -1
  45. package/dist/lib/errors.mjs.map +1 -1
  46. package/dist/lib/index.mjs +14 -8
  47. package/dist/lib/testing.mjs +2 -2
  48. package/dist/lib/trajectory/Reducer.mjs +1 -0
  49. package/dist/lib/trajectory/Trajectory.mjs +1 -0
  50. package/dist/lib/trajectory/Transcript.mjs +1 -0
  51. package/dist/lib/types/Project.mjs +1 -1
  52. package/dist/lib/types/Skill.mjs +1 -1
  53. package/dist/lib/types/Spec.mjs +1 -0
  54. package/dist/lib/types/SpecReview.mjs +1 -0
  55. package/dist/types/src/AgentService.d.ts +9 -0
  56. package/dist/types/src/AgentService.d.ts.map +1 -1
  57. package/dist/types/src/AiMetering.d.ts +23 -0
  58. package/dist/types/src/AiMetering.d.ts.map +1 -0
  59. package/dist/types/src/AiMetering.test.d.ts +2 -0
  60. package/dist/types/src/AiMetering.test.d.ts.map +1 -0
  61. package/dist/types/src/Hook.d.ts +84 -0
  62. package/dist/types/src/Hook.d.ts.map +1 -0
  63. package/dist/types/src/Hook.test.d.ts +2 -0
  64. package/dist/types/src/Hook.test.d.ts.map +1 -0
  65. package/dist/types/src/Operation.d.ts +276 -2
  66. package/dist/types/src/Operation.d.ts.map +1 -1
  67. package/dist/types/src/Process.d.ts +26 -4
  68. package/dist/types/src/Process.d.ts.map +1 -1
  69. package/dist/types/src/Script.test.d.ts +2 -0
  70. package/dist/types/src/Script.test.d.ts.map +1 -0
  71. package/dist/types/src/Trace.d.ts +103 -1
  72. package/dist/types/src/Trace.d.ts.map +1 -1
  73. package/dist/types/src/errors.d.ts +30 -0
  74. package/dist/types/src/errors.d.ts.map +1 -1
  75. package/dist/types/src/index.d.ts +3 -1
  76. package/dist/types/src/index.d.ts.map +1 -1
  77. package/dist/types/src/trajectory/Reducer.d.ts +191 -0
  78. package/dist/types/src/trajectory/Reducer.d.ts.map +1 -0
  79. package/dist/types/src/trajectory/Reducer.test.d.ts +2 -0
  80. package/dist/types/src/trajectory/Reducer.test.d.ts.map +1 -0
  81. package/dist/types/src/trajectory/Trajectory.d.ts +3211 -0
  82. package/dist/types/src/trajectory/Trajectory.d.ts.map +1 -0
  83. package/dist/types/src/trajectory/Trajectory.test.d.ts +2 -0
  84. package/dist/types/src/trajectory/Trajectory.test.d.ts.map +1 -0
  85. package/dist/types/src/trajectory/Transcript.d.ts +40 -0
  86. package/dist/types/src/trajectory/Transcript.d.ts.map +1 -0
  87. package/dist/types/src/trajectory/index.d.ts +4 -0
  88. package/dist/types/src/trajectory/index.d.ts.map +1 -0
  89. package/dist/types/src/trajectory/light-threads.test.d.ts +2 -0
  90. package/dist/types/src/trajectory/light-threads.test.d.ts.map +1 -0
  91. package/dist/types/src/trajectory/samples.test.d.ts +2 -0
  92. package/dist/types/src/trajectory/samples.test.d.ts.map +1 -0
  93. package/dist/types/src/types/Project.d.ts +11 -12
  94. package/dist/types/src/types/Project.d.ts.map +1 -1
  95. package/dist/types/src/types/Skill.d.ts +6 -51
  96. package/dist/types/src/types/Skill.d.ts.map +1 -1
  97. package/dist/types/src/types/Spec.d.ts +26 -0
  98. package/dist/types/src/types/Spec.d.ts.map +1 -0
  99. package/dist/types/src/types/SpecReview.d.ts +76 -0
  100. package/dist/types/src/types/SpecReview.d.ts.map +1 -0
  101. package/dist/types/src/types/index.d.ts +2 -0
  102. package/dist/types/src/types/index.d.ts.map +1 -1
  103. package/dist/types/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +59 -26
  105. package/src/AgentService.ts +9 -0
  106. package/src/AiMetering.test.ts +89 -0
  107. package/src/AiMetering.ts +93 -0
  108. package/src/Hook.test.ts +75 -0
  109. package/src/Hook.ts +154 -0
  110. package/src/Operation.test.ts +23 -0
  111. package/src/Operation.ts +334 -0
  112. package/src/Process.ts +33 -6
  113. package/src/Script.test.ts +74 -0
  114. package/src/Trace.ts +97 -4
  115. package/src/errors.ts +3 -0
  116. package/src/index.ts +3 -1
  117. package/src/trajectory/Reducer.test.ts +575 -0
  118. package/src/trajectory/Reducer.ts +1026 -0
  119. package/src/trajectory/Trajectory.test.ts +114 -0
  120. package/src/trajectory/Trajectory.ts +440 -0
  121. package/src/trajectory/Transcript.ts +113 -0
  122. package/src/trajectory/index.ts +7 -0
  123. package/src/trajectory/light-threads.test.ts +310 -0
  124. package/src/trajectory/samples.test.ts +285 -0
  125. package/src/types/Project.test.ts +2 -1
  126. package/src/types/Project.ts +43 -27
  127. package/src/types/Skill.ts +6 -61
  128. package/src/types/Spec.ts +68 -0
  129. package/src/types/SpecReview.ts +98 -0
  130. package/src/types/index.ts +2 -0
  131. package/dist/lib/McpServer.mjs +0 -1
  132. package/dist/lib/chunk-McpServer.mjs +0 -124
  133. package/dist/lib/chunk-McpServer.mjs.map +0 -1
  134. package/dist/types/src/McpServer.d.ts +0 -113
  135. package/dist/types/src/McpServer.d.ts.map +0 -1
  136. package/src/McpServer.ts +0 -142
package/src/Trace.ts CHANGED
@@ -21,9 +21,26 @@ import * as Trigger from './types/Trigger.ts';
21
21
  * Exposed to processes and operations to record events to the trace.
22
22
  */
23
23
  export interface Writer {
24
- write<T>(eventType: EventType<T>, payload: NoInfer<T>): void;
24
+ /** `meta` carries what only the writing fiber knows, such as its {@link CurrentThread}. */
25
+ write<T>(eventType: EventType<T>, payload: NoInfer<T>, meta?: FiberMeta): void;
25
26
  }
26
27
 
28
+ /**
29
+ * Meta a {@link Writer} cannot know from its process alone.
30
+ */
31
+ export type FiberMeta = Pick<Meta, 'thread'>;
32
+
33
+ /**
34
+ * Lane of the agent turn the current fiber runs (its light thread, or the prompt a turn on main answers), stamped
35
+ * on its events as {@link Meta.thread}
36
+ * and on the processes it spawns as {@link Meta.parentThread}: one process runs several turns at once,
37
+ * and the pid alone cannot tell their events apart.
38
+ */
39
+ export const CurrentThread: Context.Reference<string | undefined> = Context.Reference<string | undefined>(
40
+ '@dxos/compute/Trace/CurrentThread',
41
+ { defaultValue: () => undefined },
42
+ );
43
+
27
44
  /**
28
45
  * Service that writes events to the trace.
29
46
  * Exposed to processes and operations to record events to the trace.
@@ -37,7 +54,8 @@ export function write<T>(eventType: EventType<T>, payload: NoInfer<T>): Effect.E
37
54
  return Effect.gen(function* () {
38
55
  log('trace write', { key: eventType.key, isEphemeral: eventType.isEphemeral });
39
56
  const writer = yield* TraceService;
40
- writer.write(eventType, payload);
57
+ const thread = yield* CurrentThread;
58
+ writer.write(eventType, payload, thread === undefined ? undefined : { thread });
41
59
  });
42
60
  }
43
61
 
@@ -106,6 +124,15 @@ export const CommonRuntimeName = {
106
124
  export const Meta = Schema.Struct({
107
125
  pid: Schema.optional(Schema.String), // NOTE: Not Process.ID to avoid circular dependency.
108
126
  parentPid: Schema.optional(Schema.String),
127
+
128
+ /**
129
+ * Pid of the first invocation of the run this message belongs to.
130
+ * A run that calls `Operation.runAgain()` continues in a new invocation with its own `pid`; each
131
+ * continuation carries the first invocation's `pid` here so consumers can show the run as one unit.
132
+ * Absent on the first invocation, whose own `pid` is the run's id.
133
+ */
134
+ runId: Schema.optional(Schema.String),
135
+
109
136
  processName: Schema.optional(Schema.String),
110
137
 
111
138
  /**
@@ -133,6 +160,16 @@ export const Meta = Schema.Struct({
133
160
  * Extensible name informing which runtime executed the code that produced the event.
134
161
  */
135
162
  runtimeName: Schema.optional(RuntimeName),
163
+
164
+ /**
165
+ * Lane of the process's turn that produced the event (see {@link CurrentThread}).
166
+ */
167
+ thread: Schema.optional(Schema.String),
168
+
169
+ /**
170
+ * Light thread of the parent process's turn that spawned this process.
171
+ */
172
+ parentThread: Schema.optional(Schema.String),
136
173
  });
137
174
  export type Meta = Schema.Schema.Type<typeof Meta>;
138
175
 
@@ -308,10 +345,13 @@ export const matchesFilter = (message: Pick<MessageData, 'meta' | 'events'>, fil
308
345
  const encodeMetaForWire = (meta: Meta): Meta => ({
309
346
  pid: meta.pid,
310
347
  parentPid: meta.parentPid,
348
+ runId: meta.runId,
311
349
  processName: meta.processName,
312
350
  space: meta.space,
313
351
  toolCallId: meta.toolCallId,
314
352
  runtimeName: meta.runtimeName,
353
+ thread: meta.thread,
354
+ parentThread: meta.parentThread,
315
355
  });
316
356
 
317
357
  /**
@@ -437,10 +477,10 @@ export const testTraceService = (
437
477
  const sink = yield* TraceSink;
438
478
  const clock = opts.clock ?? Date.now;
439
479
  return {
440
- write: (event, data) => {
480
+ write: (event, data, fiberMeta) => {
441
481
  sink.write(
442
482
  Obj.make(Message, {
443
- meta: opts.meta ?? {},
483
+ meta: { ...opts.meta, ...fiberMeta },
444
484
  isEphemeral: event.isEphemeral,
445
485
  events: [{ type: event.key, timestamp: clock(), data }],
446
486
  }),
@@ -616,6 +656,18 @@ export const StatusUpdate = EventType('status.update', {
616
656
  isEphemeral: true,
617
657
  });
618
658
 
659
+ /** {@link StatusUpdate} message that ends a run's progress: the meter completes and is removed. */
660
+ export const StatusComplete = 'progress.complete';
661
+
662
+ /** {@link StatusUpdate} message that ends a sync's progress as failed; the meter stays visible. */
663
+ export const StatusFailed = 'Sync failed';
664
+
665
+ /** {@link StatusUpdate} message that ends any other run's progress as failed; the meter stays visible. */
666
+ export const StatusError = 'Failed';
667
+
668
+ /** {@link StatusUpdate} message that ends a run's progress as cancelled: the meter is removed. */
669
+ export const StatusCancelled = 'Cancelled';
670
+
619
671
  /**
620
672
  * Emit the current human-readable execution status to the trace.
621
673
  */
@@ -666,6 +718,21 @@ export const AgentRequestEnd = EventType('assistant.agentRequestEnd', {
666
718
  isEphemeral: false,
667
719
  });
668
720
 
721
+ /**
722
+ * The end-request hooks a request runs, resolved when it begins (see `Hook.resolve`): which ran by their plugin's
723
+ * default, which a setting turned on but whose skill is unbound, and which plugins a setting turned on that this
724
+ * host lacks. Written only when one of those is non-empty.
725
+ */
726
+ export const AgentHooksResolved = EventType('assistant.agentHooksResolved', {
727
+ schema: Schema.Struct({
728
+ run: Schema.Array(Schema.String),
729
+ byDefault: Schema.Array(Schema.String),
730
+ inactive: Schema.Array(Schema.String),
731
+ missing: Schema.Array(Schema.String),
732
+ }),
733
+ isEphemeral: false,
734
+ });
735
+
669
736
  /**
670
737
  * Emitted by the supervisor when a delegated task is handed to a sub-agent process; the only durable
671
738
  * record of the task ↔ pid pairing, since nothing is stamped on the task itself.
@@ -696,6 +763,32 @@ export const DelegationCompleted = EventType('assistant.delegationCompleted', {
696
763
  isEphemeral: false,
697
764
  });
698
765
 
766
+ /**
767
+ * One language-model call's token usage, written by the metered `AiService` (see `AiMetering`).
768
+ * Durable so a run's cost can be read back from its trace; dollars are applied at read time from the
769
+ * model catalog's prices, which change.
770
+ */
771
+ export const ModelCall = EventType('ai.modelCall', {
772
+ schema: Schema.Struct({
773
+ /** Catalog id of the model (a DXN string). */
774
+ modelId: Schema.optional(Schema.String),
775
+ /** The provider's name for the model. */
776
+ model: Schema.String,
777
+ provider: Schema.optional(Schema.String),
778
+ /** The pipeline or agent stage that made the call. */
779
+ stage: Schema.optional(Schema.String),
780
+ spanName: Schema.optional(Schema.String),
781
+ inputTokens: Schema.Number,
782
+ outputTokens: Schema.Number,
783
+ cacheReadTokens: Schema.Number,
784
+ cacheWriteTokens: Schema.Number,
785
+ /** Epoch milliseconds. */
786
+ start: Schema.Number,
787
+ end: Schema.Number,
788
+ }),
789
+ isEphemeral: false,
790
+ });
791
+
699
792
  /**
700
793
  * Emitted when an MCP server connection fails for a request turn.
701
794
  * Ephemeral so that misconfigured/unreachable servers don't pollute the durable feed,
package/src/errors.ts CHANGED
@@ -60,6 +60,9 @@ export class InvalidOperationInputError extends BaseError.extend(
60
60
  'Operation input did not match schema',
61
61
  ) {}
62
62
 
63
+ /** An operation declared requirements that the invoking process's guard did not admit, or the process holds no guard. */
64
+ export class OperationDeniedError extends BaseError.extend('OperationDeniedError', 'Operation denied') {}
65
+
63
66
  export class InvalidOperationOutputError extends BaseError.extend(
64
67
  'InvalidOperationOutput',
65
68
  'Operation output did not match schema',
package/src/index.ts CHANGED
@@ -2,16 +2,18 @@
2
2
  // Copyright 2026 DXOS.org
3
3
  //
4
4
 
5
+ export * from './trajectory/index.ts';
5
6
  export * from './types/index.ts';
6
7
 
7
8
  export * as AgentIdentity from './AgentIdentity.ts';
9
+ export * as AiMetering from './AiMetering.ts';
8
10
  export * as AgentService from './AgentService.ts';
9
11
  export * as Cancellation from './Cancellation.ts';
10
12
  export * as Credential from './Credential.ts';
11
13
  export * as FunctionsAiError from './FunctionsAiError.ts';
12
14
  export * as Header from './Header.ts';
15
+ export * as Hook from './Hook.ts';
13
16
  export * as LayerSpec from './LayerSpec.ts';
14
- export * as McpServer from './McpServer.ts';
15
17
  export * as Operation from './Operation.ts';
16
18
  export * as OperationHandlerSet from './OperationHandlerSet.ts';
17
19
  export * as OperationRegistry from './OperationRegistry.ts';