@canonmsg/core 0.14.0 → 0.15.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.
@@ -1,4 +1,21 @@
1
1
  import { mergeWorkSessionContexts, } from './work-session.js';
2
+ function listDescriptorControls(runtime) {
3
+ const descriptor = runtime?.runtimeDescriptor;
4
+ return [
5
+ ...(descriptor?.coreControls ?? []),
6
+ ...(descriptor?.runtimeControls ?? []),
7
+ ];
8
+ }
9
+ function descriptorOptions(runtime, controlId) {
10
+ return [...(listDescriptorControls(runtime)
11
+ .find((control) => control.id === controlId)
12
+ ?.options ?? [])];
13
+ }
14
+ function descriptorDefaultValue(runtime, controlId) {
15
+ const control = listDescriptorControls(runtime)
16
+ .find((candidate) => candidate.id === controlId);
17
+ return control?.defaultValue ?? control?.options?.[0]?.value ?? undefined;
18
+ }
2
19
  function buildWorkSessionSummary(workSession, workSessions) {
3
20
  const merged = mergeWorkSessionContexts(workSession, workSessions);
4
21
  const primary = merged[0];
@@ -14,13 +31,12 @@ function buildWorkSessionSummary(workSession, workSessions) {
14
31
  };
15
32
  }
16
33
  export function buildAgentSessionSnapshot(input) {
17
- const modelOptions = input.sessionState?.availableModels
18
- ?? input.sessionConfig?.availableModels
19
- ?? input.runtime?.availableModels
20
- ?? [];
21
- const workspaceOptions = input.sessionConfig?.workspaceOptions
22
- ?? input.runtime?.availableWorkspaces
23
- ?? [];
34
+ const modelOptions = descriptorOptions(input.runtime, 'model');
35
+ const workspaceOptions = descriptorOptions(input.runtime, 'workspace')
36
+ .map((option) => ({ id: option.value, label: option.label }));
37
+ const availableExecutionModes = descriptorOptions(input.runtime, 'executionMode')
38
+ .map((option) => option.value)
39
+ .filter((value) => value === 'worktree' || value === 'locked');
24
40
  return {
25
41
  conversationId: input.conversationId,
26
42
  agentId: input.agentId,
@@ -32,36 +48,30 @@ export function buildAgentSessionSnapshot(input) {
32
48
  ?? input.runtime?.hostMode),
33
49
  model: input.sessionState?.model
34
50
  ?? input.sessionConfig?.model
35
- ?? input.runtime?.defaultModel
36
- ?? modelOptions[0]?.value,
51
+ ?? descriptorDefaultValue(input.runtime, 'model'),
37
52
  modelOptions,
38
53
  permissionMode: input.sessionState?.permissionMode
39
54
  ?? input.sessionConfig?.permissionMode
40
- ?? input.runtime?.defaultPermissionMode,
41
- permissionModeOptions: input.runtime?.availablePermissionModes ?? [],
55
+ ?? descriptorDefaultValue(input.runtime, 'permissionMode'),
56
+ permissionModeOptions: descriptorOptions(input.runtime, 'permissionMode'),
42
57
  effort: input.sessionState?.effort ?? input.sessionConfig?.effort,
43
58
  runtimeControlValues: input.sessionState?.runtimeControlValues
44
59
  ?? input.sessionConfig?.runtimeControlValues,
45
60
  workspaceId: input.sessionConfig?.workspaceId
46
- ?? input.runtime?.defaultWorkspaceId
47
- ?? workspaceOptions[0]?.id,
61
+ ?? descriptorDefaultValue(input.runtime, 'workspace'),
48
62
  workspaceOptions,
49
63
  executionMode: input.sessionState?.executionMode
50
64
  ?? input.sessionConfig?.executionMode,
51
- availableExecutionModes: input.sessionConfig?.availableExecutionModes
52
- ?? input.runtime?.availableExecutionModes
53
- ?? [],
65
+ availableExecutionModes,
54
66
  executionBranch: input.sessionState?.executionBranch,
55
67
  resolvedWorkspaceLabel: undefined,
56
68
  resolvedCwd: input.sessionState?.cwd,
57
69
  worktreePath: input.sessionState?.worktreePath,
58
70
  executionFallbackReason: input.sessionState?.executionFallbackReason,
59
- state: input.sessionState?.state,
60
71
  turnState: input.turnState?.state,
61
72
  supportsQueue: input.turnState?.capabilities?.supportsQueue,
62
73
  queueDepth: input.turnState?.queueDepth ?? 0,
63
- waitingForInput: input.turnState?.state === 'waiting_input'
64
- || input.sessionState?.state === 'requires_action',
74
+ waitingForInput: input.turnState?.state === 'waiting_input',
65
75
  contextUsage: input.sessionState?.contextUsage,
66
76
  lastError: input.sessionState?.lastError,
67
77
  lastHeartbeatAt: input.lastHeartbeatAt
@@ -22,16 +22,11 @@ export interface SessionStatePayload {
22
22
  hostMode?: boolean;
23
23
  clientType?: string;
24
24
  isActive: boolean;
25
- state?: 'idle' | 'running' | 'requires_action';
26
25
  contextUsage?: {
27
26
  percentage: number;
28
27
  totalTokens: number;
29
28
  maxTokens: number;
30
29
  };
31
- availableModels?: Array<{
32
- value: string;
33
- label: string;
34
- }>;
35
30
  updatedAt: {
36
31
  '.sv': 'timestamp';
37
32
  };
@@ -80,7 +75,7 @@ export interface AgentSessionSnapshotPatch {
80
75
  resolvedCwd?: string | null;
81
76
  worktreePath?: string | null;
82
77
  executionFallbackReason?: string | null;
83
- state?: 'idle' | 'running' | 'requires_action' | null;
78
+ state?: null;
84
79
  turnState?: TurnLifecycleState | null;
85
80
  supportsQueue?: boolean | null;
86
81
  queueDepth?: number;
package/dist/rtdb-rest.js CHANGED
@@ -144,7 +144,6 @@ function createRTDBClientHandle(client, options) {
144
144
  ...(state.runtimeControlValues !== undefined
145
145
  ? { runtimeControlValues: state.runtimeControlValues }
146
146
  : {}),
147
- ...(state.availableModels !== undefined ? { modelOptions: state.availableModels } : {}),
148
147
  ...(state.cwd !== undefined ? { resolvedCwd: state.cwd } : {}),
149
148
  ...(state.executionMode !== undefined ? { executionMode: state.executionMode } : {}),
150
149
  ...(state.executionBranch !== undefined ? { executionBranch: state.executionBranch } : {}),
@@ -152,8 +151,8 @@ function createRTDBClientHandle(client, options) {
152
151
  ...(state.executionFallbackReason !== undefined
153
152
  ? { executionFallbackReason: state.executionFallbackReason }
154
153
  : {}),
155
- ...(state.state !== undefined ? { state: state.state } : {}),
156
- waitingForInput: state.state === 'requires_action',
154
+ state: null,
155
+ waitingForInput: false,
157
156
  ...(state.contextUsage !== undefined ? { contextUsage: state.contextUsage } : {}),
158
157
  ...(state.lastError !== undefined ? { lastError: state.lastError } : {}),
159
158
  lastHeartbeatAt: { '.sv': 'timestamp' },
@@ -167,7 +166,7 @@ function createRTDBClientHandle(client, options) {
167
166
  updatedAt: { '.sv': 'timestamp' },
168
167
  });
169
168
  await patch(buildAgentSessionPath(conversationId, agentId), {
170
- state: 'idle',
169
+ state: null,
171
170
  waitingForInput: false,
172
171
  lastError: null,
173
172
  executionBranch: null,
package/dist/types.d.ts CHANGED
@@ -482,7 +482,6 @@ export interface SessionState {
482
482
  /** True when the agent is running under the host wrapper (host.ts) which can apply control signals */
483
483
  hostMode?: boolean;
484
484
  isActive: boolean;
485
- state?: 'idle' | 'running' | 'requires_action';
486
485
  contextUsage?: {
487
486
  percentage: number;
488
487
  totalTokens: number;
@@ -585,7 +584,6 @@ export interface AgentSessionSnapshot {
585
584
  resolvedCwd?: string | null;
586
585
  worktreePath?: string | null;
587
586
  executionFallbackReason?: string | null;
588
- state?: SessionState['state'];
589
587
  turnState?: TurnLifecycleState;
590
588
  supportsQueue?: boolean;
591
589
  queueDepth: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonmsg/core",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Canon core — shared types, REST client, SSE stream, and registration for Canon messaging",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",