@saturn-universe/projections 0.1.2-dev.6 → 0.1.2-dev.8

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.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { projectBatch, projectBatchWithChanges, createCoreProjections } from './project.js';
1
+ export { projectBatch, projectBatchWithChanges, createCoreProjections, sessionHasActiveRun, } from './project.js';
2
2
  export type { ProjectionChanges } from './project.js';
3
3
  export { coreProjectionName, coreProjectionVersion, initialProjection } from './state.js';
4
4
  export type { ExecutionFact, ModelFact, ProjectionCollection, ProjectionIndexes, ProjectionState, } from './state.js';
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { projectBatch, projectBatchWithChanges, createCoreProjections } from './project.js';
1
+ export { projectBatch, projectBatchWithChanges, createCoreProjections, sessionHasActiveRun, } from './project.js';
2
2
  export { coreProjectionName, coreProjectionVersion, initialProjection } from './state.js';
3
3
  export { initialSurface, reduceSurface } from './surface.js';
package/dist/project.d.ts CHANGED
@@ -18,3 +18,4 @@ export declare function createCoreProjections(hash: Hash): {
18
18
  initial: typeof initialProjection;
19
19
  reduce: (state: ProjectionState, events: readonly RuntimeEvent[]) => ProjectionState;
20
20
  };
21
+ export declare function sessionHasActiveRun(s: ProjectionState, sessionId: string): boolean;
package/dist/project.js CHANGED
@@ -1,4 +1,4 @@
1
- import { acceptsModelResponse, canonicalJson, earlierDeadline, isLimited, isTerminalRunEventType, isTerminalRunStatus, ownerAllowsRoute, resolveSubagentWallTimeMs, settledModelTokens, streamKey, RuntimeError, transitionRun, } from '@saturn-universe/core';
1
+ import { acceptsModelResponse, canonicalJson, contextExtensionRefPattern, earlierDeadline, isLimited, isTerminalRunEventType, isTerminalRunStatus, ownerAllowsRoute, resolveSubagentWallTimeMs, settledModelTokens, streamKey, RuntimeError, transitionRun, } from '@saturn-universe/core';
2
2
  import { initialSurface, reduceSurface } from './surface.js';
3
3
  import { coreProjectionName, coreProjectionVersion, emptyIndexes, initialProjection, projectionCollections, } from './state.js';
4
4
  import { attachTeamMember, finishTeam, isDegradedWorkerTurn, planTeam, projectTeamMessage, projectTeamStopRequest, projectTeamTurn, } from './team.js';
@@ -297,6 +297,7 @@ function applyEvent(s, e, hash) {
297
297
  case 'agent.created':
298
298
  case 'session.created':
299
299
  case 'session.agent.bound':
300
+ case 'session.mode.selected':
300
301
  case 'session.archived':
301
302
  case 'agent_session.created':
302
303
  case 'agent_session.archived':
@@ -409,6 +410,9 @@ function reduceWorkspaceEvent(s, e, r) {
409
410
  }
410
411
  return r;
411
412
  }
413
+ export function sessionHasActiveRun(s, sessionId) {
414
+ return someRuns(s, s.indexes.runIdsBySession[sessionId], (run) => !isTerminalRunStatus(run.status));
415
+ }
412
416
  function reduceSessionEvent(s, e, r) {
413
417
  switch (e.type) {
414
418
  case 'agent.created':
@@ -427,6 +431,16 @@ function reduceSessionEvent(s, e, r) {
427
431
  add(s.bindings, `${b.sessionId}:${b.agentSessionId}`, b);
428
432
  break;
429
433
  }
434
+ case 'session.mode.selected': {
435
+ const { sessionId } = e.scope;
436
+ const session = s.sessions[sessionId];
437
+ if (session.status !== 'open' || !contextExtensionRefPattern.test(e.payload.modeRef))
438
+ invalid('invalid session mode selection');
439
+ if (sessionHasActiveRun(s, sessionId))
440
+ invalid('session has active work');
441
+ s.sessions[sessionId] = { ...session, modeRef: e.payload.modeRef };
442
+ break;
443
+ }
430
444
  case 'session.archived': {
431
445
  const id = e.scope.sessionId;
432
446
  if (s.sessions[id].status !== 'open')
@@ -508,6 +522,9 @@ function reduceRunEvent(s, e, r) {
508
522
  invalid('stream has unresolved calls');
509
523
  if (m.role === 'main' && s.indexes.mainMembershipByRun[m.runId] !== undefined)
510
524
  invalid('duplicate run main');
525
+ const selectedModeRef = s.sessions[e.scope.sessionId]?.modeRef;
526
+ if (m.role === 'main' && selectedModeRef && m.config.modeRef !== selectedModeRef)
527
+ invalid('Run Mode does not match the session selection');
511
528
  if (m.config.checkpoint) {
512
529
  const { sourceRunId, originalInputId } = m.config.checkpoint;
513
530
  const source = s.memberships[`${sourceRunId}:${m.agentSessionId}`];
package/dist/team.js CHANGED
@@ -103,9 +103,7 @@ export function planTeam(s, e, run) {
103
103
  ? teamConcurrency(team)
104
104
  : (current?.concurrency ?? teamConcurrency(team));
105
105
  const mergedConcurrency = asyncCoordinator && current ? Math.max(current.concurrency, incomingConcurrency) : incomingConcurrency;
106
- const cappedConcurrency = mainMembership.config.teamMaxConcurrency !== undefined
107
- ? Math.min(mergedConcurrency, mainMembership.config.teamMaxConcurrency)
108
- : mergedConcurrency;
106
+ const cappedConcurrency = resolveEffectiveTeamConcurrency(mainMembership.config.teamDefaultConcurrency !== undefined ? team.concurrency : mergedConcurrency, mainMembership.config);
109
107
  s.teams[runId] = {
110
108
  runId,
111
109
  concurrency: Math.max(1, cappedConcurrency),
@@ -141,7 +139,9 @@ export function attachTeamMember(s, m) {
141
139
  invalid('invalid team root');
142
140
  s.teams[m.runId] = {
143
141
  runId: m.runId,
144
- concurrency: teamConcurrency(config),
142
+ concurrency: m.config.teamDefaultConcurrency === undefined
143
+ ? teamConcurrency(config)
144
+ : resolveEffectiveTeamConcurrency(config.concurrency, m.config),
145
145
  members: [{ id: teamRootId, parent: null, agentSessionId: m.agentSessionId, status: 'waiting' }],
146
146
  tasks: config.members.map(({ id, task }) => ({ memberId: id, task, status: 'waiting' })),
147
147
  inbox: [],
@@ -197,9 +197,12 @@ export function attachTeamMember(s, m) {
197
197
  const tasksMatch = asyncCoordinator
198
198
  ? expectedTasks.every((expected) => currentTasks.some((cur) => cur.memberId === expected.memberId && cur.task === expected.task))
199
199
  : canonicalJson(expectedTasks) === canonicalJson(currentTasks);
200
+ const concurrency = rootConfig.teamDefaultConcurrency === undefined
201
+ ? teamConcurrency(config)
202
+ : resolveEffectiveTeamConcurrency(config.concurrency, rootConfig);
200
203
  const concurrencyValid = asyncCoordinator
201
- ? teamConcurrency(config) <= current.concurrency
202
- : teamConcurrency(config) === current.concurrency;
204
+ ? concurrency <= current.concurrency
205
+ : concurrency === current.concurrency;
203
206
  if (!worker ||
204
207
  !concurrencyValid ||
205
208
  !tasksMatch ||
@@ -255,7 +258,10 @@ export function projectTeamTurn(s, turn, e) {
255
258
  ? s.memberships[`${turn.runId}:${mainAgentSessionId}`]?.config
256
259
  : undefined;
257
260
  const asyncCoordinator = mainConfig ? isAsyncCoordinatorConfig(mainConfig) : false;
258
- const effectiveConcurrency = resolveEffectiveTeamConcurrency(team.concurrency, mainConfig, asyncCoordinator);
261
+ // Older event logs may contain starts above the recorded team concurrency.
262
+ const effectiveConcurrency = asyncCoordinator && mainConfig?.teamDefaultConcurrency === undefined
263
+ ? (mainConfig?.teamMaxConcurrency ?? team.concurrency)
264
+ : resolveEffectiveTeamConcurrency(team.concurrency, mainConfig);
259
265
  if (e.type === 'turn.started' || e.type === 'turn.resumed') {
260
266
  if (asyncCoordinator) {
261
267
  if (member.id !== teamRootId &&
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@saturn-universe/projections",
3
- "version": "0.1.2-dev.6",
3
+ "version": "0.1.2-dev.8",
4
4
  "license": "AGPL-3.0-only",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"
8
8
  ],
9
9
  "dependencies": {
10
- "@saturn-universe/core": "0.1.2-dev.6"
10
+ "@saturn-universe/core": "0.1.2-dev.8"
11
11
  },
12
12
  "exports": {
13
13
  ".": {