@peer-agent/protocol 0.1.0-rc.34 → 0.1.0-rc.36
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/delegation.d.ts +8 -0
- package/dist/delegation.js +1 -0
- package/dist/evidence-inspection.d.ts +14 -1
- package/dist/goal.d.ts +1 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.js +6 -2
- package/dist/intent-coordination.d.ts +2 -0
- package/dist/interactive-result.d.ts +363 -0
- package/dist/interactive-result.js +215 -0
- package/dist/interactive-verification.d.ts +41 -0
- package/dist/interactive-verification.js +65 -0
- package/dist/remote-access.d.ts +15 -0
- package/dist/remote-access.js +1 -1
- package/dist/resource-edit.js +2 -2
- package/dist/resource-feedback-transport.d.ts +25 -0
- package/dist/resource-feedback-transport.js +93 -0
- package/dist/resource-feedback.d.ts +8 -1
- package/dist/resource-feedback.js +33 -2
- package/dist/resource-window.d.ts +80 -1
- package/dist/resource-window.js +130 -1
- package/dist/runtime-session-facts.d.ts +58 -0
- package/dist/runtime-session-facts.js +55 -0
- package/dist/session-control.d.ts +2 -0
- package/dist/session-control.js +14 -0
- package/dist/work-coordination.d.ts +15 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { BotDocumentReference, LocalDocumentReadResult } from './document-reference.ts';
|
|
2
2
|
import type { EvidenceDeliveryBinding } from './evidence-inspection.ts';
|
|
3
|
+
import { type InteractiveOwner, type InteractiveResultReference } from './interactive-result.ts';
|
|
3
4
|
/** Read-only presentation. None of these fields grant access or identify a browser guest/writer. */
|
|
4
5
|
export type ResourceWindowResource = ({
|
|
5
6
|
readonly kind: 'document';
|
|
@@ -20,6 +21,9 @@ export type ResourceWindowResource = ({
|
|
|
20
21
|
readonly fromRef: string;
|
|
21
22
|
readonly toRef?: string;
|
|
22
23
|
readonly comparison?: 'working' | 'staged';
|
|
24
|
+
} | {
|
|
25
|
+
readonly kind: 'interactive';
|
|
26
|
+
readonly reference: InteractiveResultReference;
|
|
23
27
|
};
|
|
24
28
|
export interface ResourceWindowNavigation {
|
|
25
29
|
readonly top: number;
|
|
@@ -52,17 +56,20 @@ export interface ResourceWindowIdentity {
|
|
|
52
56
|
export interface ResourceWindowContext extends ResourceWindowIdentity {
|
|
53
57
|
readonly owner: ResourceWindowOwner;
|
|
54
58
|
readonly resource: ResourceWindowResource;
|
|
59
|
+
/** Factual presentation title resolved by the host; never an access grant. */
|
|
60
|
+
readonly title?: string;
|
|
55
61
|
readonly sourceTabId?: string;
|
|
56
62
|
readonly navigation?: ResourceWindowNavigation;
|
|
57
63
|
readonly sourceNavigation?: ResourceWindowNavigation;
|
|
58
64
|
readonly navigationVersion?: number;
|
|
59
65
|
readonly phase: 'prepared' | 'attached' | 'ready';
|
|
60
66
|
}
|
|
61
|
-
export type ResourceWindowStatus = 'invalid_request' | 'scope_denied' | 'permission_denied' | 'not_found' | 'workspace_unavailable' | 'revision_unavailable' | 'source_unavailable' | 'source_changed' | 'storage_unavailable' | 'limit_reached' | 'stale_view' | 'not_ready' | 'cancelled' | 'disposed';
|
|
67
|
+
export type ResourceWindowStatus = 'invalid_request' | 'scope_denied' | 'permission_denied' | 'not_found' | 'workspace_unavailable' | 'revision_unavailable' | 'source_unavailable' | 'source_changed' | 'storage_unavailable' | 'limit_reached' | 'stale_view' | 'not_ready' | 'cancelled' | 'disposed' | 'content_cleaned' | 'incompatible_result' | 'result_unavailable';
|
|
62
68
|
export type ResourceWindowResult = {
|
|
63
69
|
readonly ok: true;
|
|
64
70
|
readonly context: ResourceWindowContext;
|
|
65
71
|
readonly persisted?: boolean;
|
|
72
|
+
readonly checkpointStatus?: 'owner_replaced';
|
|
66
73
|
readonly returnStatus?: 'returned' | 'source_tab_closed';
|
|
67
74
|
} | {
|
|
68
75
|
readonly ok: false;
|
|
@@ -94,12 +101,77 @@ export interface ResourceWindowHistoryEntry {
|
|
|
94
101
|
readonly owner: ResourceWindowOwner;
|
|
95
102
|
readonly request: ResourceWindowOpenRequest;
|
|
96
103
|
readonly savedAt: string;
|
|
104
|
+
readonly title?: string;
|
|
97
105
|
}
|
|
98
106
|
export interface ResourceWindowHistoryResult {
|
|
99
107
|
readonly ok: boolean;
|
|
100
108
|
readonly status: 'ok' | 'scope_denied' | 'storage_unavailable';
|
|
101
109
|
readonly entries: readonly ResourceWindowHistoryEntry[];
|
|
102
110
|
}
|
|
111
|
+
export interface ResourceLayoutSnapshot {
|
|
112
|
+
readonly formatVersion: 2;
|
|
113
|
+
readonly revision: number;
|
|
114
|
+
readonly order: readonly string[];
|
|
115
|
+
readonly recent: readonly string[];
|
|
116
|
+
readonly interactive: ResourceInteractiveSession;
|
|
117
|
+
readonly updatedAt: string;
|
|
118
|
+
}
|
|
119
|
+
export interface ResourceInteractiveTab {
|
|
120
|
+
readonly id: string;
|
|
121
|
+
readonly reference: InteractiveResultReference;
|
|
122
|
+
readonly title?: string;
|
|
123
|
+
readonly navigation?: Pick<ResourceWindowNavigation, 'top' | 'left'>;
|
|
124
|
+
}
|
|
125
|
+
/** Domain presentation references only; values, raw drafts and writer truth stay in the state store. */
|
|
126
|
+
export interface ResourceInteractiveSession {
|
|
127
|
+
readonly tabs: readonly ResourceInteractiveTab[];
|
|
128
|
+
readonly activeTabId: string | null;
|
|
129
|
+
}
|
|
130
|
+
export type ResourceRecentReference = {
|
|
131
|
+
readonly kind: 'document';
|
|
132
|
+
readonly path: string;
|
|
133
|
+
readonly relativeTo?: string;
|
|
134
|
+
readonly task?: BotDocumentReference['task'];
|
|
135
|
+
readonly revision?: BotDocumentReference['revision'];
|
|
136
|
+
} | {
|
|
137
|
+
readonly kind: 'comparison';
|
|
138
|
+
readonly path: string;
|
|
139
|
+
readonly relativeTo?: string;
|
|
140
|
+
readonly task?: BotDocumentReference['task'];
|
|
141
|
+
readonly comparison: {
|
|
142
|
+
readonly fromRef: string;
|
|
143
|
+
readonly toRef?: string;
|
|
144
|
+
readonly comparison?: 'working' | 'staged';
|
|
145
|
+
};
|
|
146
|
+
} | {
|
|
147
|
+
readonly kind: 'browser';
|
|
148
|
+
readonly url: string;
|
|
149
|
+
} | {
|
|
150
|
+
readonly kind: 'interactive';
|
|
151
|
+
readonly reference: InteractiveResultReference;
|
|
152
|
+
readonly title?: string;
|
|
153
|
+
};
|
|
154
|
+
export interface ResourcePresentationApi {
|
|
155
|
+
readLayout(request: {
|
|
156
|
+
readonly owner: InteractiveOwner;
|
|
157
|
+
}): Promise<{
|
|
158
|
+
readonly ok: true;
|
|
159
|
+
readonly snapshot: ResourceLayoutSnapshot | null;
|
|
160
|
+
} | {
|
|
161
|
+
readonly ok: false;
|
|
162
|
+
readonly code: string;
|
|
163
|
+
}>;
|
|
164
|
+
writeLayout(request: {
|
|
165
|
+
readonly owner: InteractiveOwner;
|
|
166
|
+
readonly expectedRevision: number;
|
|
167
|
+
} & Pick<ResourceLayoutSnapshot, 'order' | 'recent' | 'interactive'>): Promise<{
|
|
168
|
+
readonly ok: true;
|
|
169
|
+
readonly snapshot: ResourceLayoutSnapshot;
|
|
170
|
+
} | {
|
|
171
|
+
readonly ok: false;
|
|
172
|
+
readonly code: string;
|
|
173
|
+
}>;
|
|
174
|
+
}
|
|
103
175
|
/** The host supplies owner, task, revision and allowed root from its lease, never from this request. */
|
|
104
176
|
export interface ResourceWindowReadRequest {
|
|
105
177
|
readonly identity: ResourceWindowIdentity;
|
|
@@ -136,3 +208,10 @@ export interface ResourceWindowReadResult {
|
|
|
136
208
|
export declare function normalizeResourceWindowNavigation(raw: unknown, kind: ResourceWindowResource['kind']): ResourceWindowNavigation | undefined;
|
|
137
209
|
export declare function normalizeResourceWindowRequest(raw: unknown): ResourceWindowOpenRequest | undefined;
|
|
138
210
|
export declare function normalizeResourceWindowOwner(raw: unknown): ResourceWindowOwner | undefined;
|
|
211
|
+
export declare function resourceWindowWorkspaceId(resource: ResourceWindowResource): string;
|
|
212
|
+
export declare function resourceWindowTask(resource: ResourceWindowResource): BotDocumentReference['task'] | undefined;
|
|
213
|
+
export declare function interactiveReferenceKey(reference: InteractiveResultReference): string;
|
|
214
|
+
export declare function normalizeResourceInteractiveSession(raw: unknown): ResourceInteractiveSession | undefined;
|
|
215
|
+
export declare function normalizeResourceRecentReference(raw: unknown): ResourceRecentReference | undefined;
|
|
216
|
+
export declare function normalizeResourceLayout(raw: unknown): Pick<ResourceLayoutSnapshot, 'order' | 'recent' | 'interactive'> | undefined;
|
|
217
|
+
export declare function normalizeResourceLayoutSnapshot(raw: unknown): ResourceLayoutSnapshot | undefined;
|
package/dist/resource-window.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { interactiveToken, normalizeInteractiveReference } from "./interactive-result.js";
|
|
1
2
|
const object = (value) => !!value && typeof value === 'object' && !Array.isArray(value);
|
|
2
3
|
const keys = (value, allowed) => Object.keys(value).every(key => allowed.includes(key));
|
|
3
4
|
const token = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(value) && !value.includes('..');
|
|
@@ -34,6 +35,12 @@ function reference(raw) {
|
|
|
34
35
|
function resource(raw) {
|
|
35
36
|
if (!object(raw))
|
|
36
37
|
return;
|
|
38
|
+
if (raw.kind === 'interactive') {
|
|
39
|
+
if (!keys(raw, ['kind', 'reference']))
|
|
40
|
+
return;
|
|
41
|
+
const fixed = normalizeInteractiveReference(raw.reference);
|
|
42
|
+
return fixed ? { kind: 'interactive', reference: fixed } : undefined;
|
|
43
|
+
}
|
|
37
44
|
const ref = reference(raw.reference);
|
|
38
45
|
if (!ref)
|
|
39
46
|
return;
|
|
@@ -75,7 +82,7 @@ function resource(raw) {
|
|
|
75
82
|
}
|
|
76
83
|
/** Only bounded hints for this kind of view; never accept a body, permission, browser instance or draft. */
|
|
77
84
|
export function normalizeResourceWindowNavigation(raw, kind) {
|
|
78
|
-
if (!object(raw) || !keys(raw, kind === 'directory' ? ['top', 'left', 'selected', 'expanded', 'filter'] : kind === 'comparison' ? ['top', 'left', 'selected', 'positions'] : ['top', 'left', 'mode', 'positions']) || !point(raw.top) || !point(raw.left))
|
|
85
|
+
if (!object(raw) || !keys(raw, kind === 'interactive' ? ['top', 'left'] : kind === 'directory' ? ['top', 'left', 'selected', 'expanded', 'filter'] : kind === 'comparison' ? ['top', 'left', 'selected', 'positions'] : ['top', 'left', 'mode', 'positions']) || !point(raw.top) || !point(raw.left))
|
|
79
86
|
return;
|
|
80
87
|
if (raw.selected !== undefined && !text(raw.selected, 8192) || raw.filter !== undefined && (typeof raw.filter !== 'string' || raw.filter.length > 256 || /[\u0000-\u001f]/.test(raw.filter))
|
|
81
88
|
|| raw.expanded !== undefined && (!Array.isArray(raw.expanded) || raw.expanded.length > 64 || !raw.expanded.every(value => text(value, 8192))))
|
|
@@ -114,3 +121,125 @@ export function normalizeResourceWindowOwner(raw) {
|
|
|
114
121
|
return { workspaceId: raw.workspaceId, conversationId: raw.conversationId,
|
|
115
122
|
...(object(raw.task) ? { task: { sessionId: raw.task.sessionId, planId: raw.task.planId } } : {}) };
|
|
116
123
|
}
|
|
124
|
+
export function resourceWindowWorkspaceId(resource) {
|
|
125
|
+
return resource.kind === 'interactive' ? resource.reference.owner.workspaceId : resource.reference.workspaceId;
|
|
126
|
+
}
|
|
127
|
+
export function resourceWindowTask(resource) {
|
|
128
|
+
return resource.kind === 'interactive' ? undefined : resource.reference.task;
|
|
129
|
+
}
|
|
130
|
+
export function interactiveReferenceKey(reference) {
|
|
131
|
+
return JSON.stringify([reference.owner.workspaceId, reference.owner.conversationId, reference.resultId, reference.contentVersion]);
|
|
132
|
+
}
|
|
133
|
+
const titleHint = (value) => typeof value === 'string' && !!value.trim() && value.length <= 160 && !value.includes('\0');
|
|
134
|
+
export function normalizeResourceInteractiveSession(raw) {
|
|
135
|
+
if (!object(raw) || !keys(raw, ['tabs', 'activeTabId']) || !Array.isArray(raw.tabs) || raw.tabs.length > 32
|
|
136
|
+
|| raw.activeTabId !== null && !interactiveToken(raw.activeTabId))
|
|
137
|
+
return;
|
|
138
|
+
const tabs = [];
|
|
139
|
+
const ids = new Set(), references = new Set();
|
|
140
|
+
for (const item of raw.tabs) {
|
|
141
|
+
if (!object(item) || !keys(item, ['id', 'reference', 'title', 'navigation']) || !interactiveToken(item.id) || item.title !== undefined && !titleHint(item.title))
|
|
142
|
+
return;
|
|
143
|
+
const reference = normalizeInteractiveReference(item.reference);
|
|
144
|
+
const navigation = item.navigation === undefined ? undefined : normalizeResourceWindowNavigation(item.navigation, 'interactive');
|
|
145
|
+
if (!reference || item.navigation !== undefined && !navigation || ids.has(item.id) || references.has(interactiveReferenceKey(reference)))
|
|
146
|
+
return;
|
|
147
|
+
ids.add(item.id);
|
|
148
|
+
references.add(interactiveReferenceKey(reference));
|
|
149
|
+
tabs.push({ id: item.id, reference, ...(item.title !== undefined ? { title: item.title } : {}), ...(navigation ? { navigation } : {}) });
|
|
150
|
+
}
|
|
151
|
+
if (raw.activeTabId !== null && !ids.has(raw.activeTabId))
|
|
152
|
+
return;
|
|
153
|
+
return { tabs, activeTabId: raw.activeTabId };
|
|
154
|
+
}
|
|
155
|
+
export function normalizeResourceRecentReference(raw) {
|
|
156
|
+
if (!object(raw))
|
|
157
|
+
return;
|
|
158
|
+
if (raw.kind === 'interactive') {
|
|
159
|
+
if (!keys(raw, ['kind', 'reference', 'title']) || raw.title !== undefined && !titleHint(raw.title))
|
|
160
|
+
return;
|
|
161
|
+
const reference = normalizeInteractiveReference(raw.reference);
|
|
162
|
+
return reference ? { kind: 'interactive', reference, ...(raw.title !== undefined ? { title: raw.title } : {}) } : undefined;
|
|
163
|
+
}
|
|
164
|
+
if (raw.kind === 'browser') {
|
|
165
|
+
if (!keys(raw, ['kind', 'url']) || !text(raw.url, 8192))
|
|
166
|
+
return;
|
|
167
|
+
try {
|
|
168
|
+
const url = new URL(raw.url);
|
|
169
|
+
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password)
|
|
170
|
+
return;
|
|
171
|
+
return { kind: 'browser', url: url.href };
|
|
172
|
+
}
|
|
173
|
+
catch {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (!['document', 'comparison'].includes(String(raw.kind)) || !keys(raw, raw.kind === 'document' ? ['kind', 'path', 'relativeTo', 'task', 'revision'] : ['kind', 'path', 'relativeTo', 'task', 'comparison']))
|
|
178
|
+
return;
|
|
179
|
+
// A recent descriptor is a hint scoped by its containing owner. It never supplies a workspace or an access grant.
|
|
180
|
+
const ref = { workspaceId: 'presentation', path: raw.path, ...(raw.relativeTo !== undefined ? { relativeTo: raw.relativeTo } : {}),
|
|
181
|
+
...(raw.task !== undefined ? { task: raw.task } : {}), ...(raw.revision !== undefined ? { revision: raw.revision } : {}) };
|
|
182
|
+
if (raw.kind === 'document') {
|
|
183
|
+
const request = normalizeResourceWindowRequest({ resource: { kind: 'document', reference: ref, mode: 'preview' } });
|
|
184
|
+
if (request?.resource.kind !== 'document')
|
|
185
|
+
return;
|
|
186
|
+
const fixed = request.resource.reference;
|
|
187
|
+
return { kind: 'document', path: fixed.path, ...(fixed.relativeTo ? { relativeTo: fixed.relativeTo } : {}), ...(fixed.task ? { task: fixed.task } : {}), ...(fixed.revision ? { revision: fixed.revision } : {}) };
|
|
188
|
+
}
|
|
189
|
+
if (!object(raw.comparison) || !keys(raw.comparison, ['fromRef', 'toRef', 'comparison']))
|
|
190
|
+
return;
|
|
191
|
+
const request = normalizeResourceWindowRequest({ resource: { kind: 'comparison', reference: ref, ...raw.comparison } });
|
|
192
|
+
if (request?.resource.kind !== 'comparison')
|
|
193
|
+
return;
|
|
194
|
+
const fixed = request.resource;
|
|
195
|
+
return { kind: 'comparison', path: fixed.reference.path, ...(fixed.reference.relativeTo ? { relativeTo: fixed.reference.relativeTo } : {}), ...(fixed.reference.task ? { task: fixed.reference.task } : {}),
|
|
196
|
+
comparison: { fromRef: fixed.fromRef, ...(fixed.toRef ? { toRef: fixed.toRef } : {}), ...(fixed.comparison ? { comparison: fixed.comparison } : {}) } };
|
|
197
|
+
}
|
|
198
|
+
export function normalizeResourceLayout(raw) {
|
|
199
|
+
if (!object(raw) || !keys(raw, ['order', 'recent', 'interactive']))
|
|
200
|
+
return;
|
|
201
|
+
const interactive = normalizeResourceInteractiveSession(raw.interactive);
|
|
202
|
+
if (!interactive)
|
|
203
|
+
return;
|
|
204
|
+
const list = (value, limit) => Array.isArray(value) && value.length <= limit
|
|
205
|
+
&& value.every(key => typeof key === 'string' && key.length <= 8192 && !/[\u0000-\u001f]/.test(key)
|
|
206
|
+
&& (key === 'launcher' || /^(?:document|browser|conversation|interactive):.+$/.test(key) || key === 'comparison:workspace')) && new Set(value).size === value.length;
|
|
207
|
+
if (!list(raw.order, 200) || !Array.isArray(raw.recent) || raw.recent.length > 16 || new TextEncoder().encode(JSON.stringify(raw)).byteLength > 256 * 1024)
|
|
208
|
+
return;
|
|
209
|
+
const mapped = new Set(interactive.tabs.map(tab => `interactive:${tab.id}`));
|
|
210
|
+
if (raw.order.some(key => key.startsWith('interactive:') && !mapped.has(key))
|
|
211
|
+
|| interactive.activeTabId !== null && !raw.order.includes(`interactive:${interactive.activeTabId}`))
|
|
212
|
+
return;
|
|
213
|
+
const recent = [];
|
|
214
|
+
for (const item of raw.recent) {
|
|
215
|
+
if (typeof item !== 'string' || item.length > 8192)
|
|
216
|
+
return;
|
|
217
|
+
if (list([item], 1)) {
|
|
218
|
+
recent.push(item);
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
try {
|
|
222
|
+
const ref = normalizeResourceRecentReference(JSON.parse(item));
|
|
223
|
+
if (!ref)
|
|
224
|
+
return;
|
|
225
|
+
const descriptor = JSON.stringify(ref);
|
|
226
|
+
if (descriptor.length > 8192)
|
|
227
|
+
return;
|
|
228
|
+
recent.push(descriptor);
|
|
229
|
+
}
|
|
230
|
+
catch {
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (new Set(recent).size !== recent.length)
|
|
235
|
+
return;
|
|
236
|
+
const layout = { order: [...raw.order], recent, interactive };
|
|
237
|
+
return new TextEncoder().encode(JSON.stringify(layout)).byteLength <= 256 * 1024 ? layout : undefined;
|
|
238
|
+
}
|
|
239
|
+
export function normalizeResourceLayoutSnapshot(raw) {
|
|
240
|
+
if (!object(raw) || !keys(raw, ['formatVersion', 'revision', 'order', 'recent', 'interactive', 'updatedAt']) || raw.formatVersion !== 2
|
|
241
|
+
|| !Number.isSafeInteger(raw.revision) || Number(raw.revision) < 1 || typeof raw.updatedAt !== 'string' || raw.updatedAt.length > 40 || !Number.isFinite(Date.parse(raw.updatedAt)))
|
|
242
|
+
return;
|
|
243
|
+
const layout = normalizeResourceLayout({ order: raw.order, recent: raw.recent, interactive: raw.interactive });
|
|
244
|
+
return layout ? { formatVersion: 2, ...layout, revision: raw.revision, updatedAt: raw.updatedAt } : undefined;
|
|
245
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type WorkSessionStatus } from './delegation.ts';
|
|
2
|
+
import { type ExecutionOwnership, type FollowUpOwner } from './task-overview.ts';
|
|
3
|
+
export type RuntimeHandling = 'model' | 'host' | 'user' | 'none';
|
|
4
|
+
/** A checked view of existing session facts, never a second lifecycle or execution receipt. */
|
|
5
|
+
export interface RuntimeSessionFacts {
|
|
6
|
+
readonly sessionId: string;
|
|
7
|
+
readonly status: WorkSessionStatus | 'unknown';
|
|
8
|
+
readonly valid: boolean;
|
|
9
|
+
readonly executionOwnership: ExecutionOwnership;
|
|
10
|
+
readonly owner: FollowUpOwner;
|
|
11
|
+
readonly reason: string;
|
|
12
|
+
readonly handling: RuntimeHandling;
|
|
13
|
+
readonly pendingManaged: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function runtimeSessionFacts(value: unknown): RuntimeSessionFacts;
|
|
16
|
+
/** Missing/invalid facts remain obligations; a valid public terminal does not invent live ownership. */
|
|
17
|
+
export declare function hasPendingRuntimeSessions(sessions: readonly unknown[], expectedIds?: readonly string[]): boolean;
|
|
18
|
+
export interface RuntimeSessionOwnership {
|
|
19
|
+
readonly repairSessionIds: readonly string[];
|
|
20
|
+
readonly hostSessionIds: readonly string[];
|
|
21
|
+
readonly waitingSessionIds: readonly string[];
|
|
22
|
+
readonly needsUser: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function runtimeSessionOwnership(sessions: readonly unknown[]): RuntimeSessionOwnership;
|
|
25
|
+
export interface ResourceWaitScope {
|
|
26
|
+
readonly workspaceId: string;
|
|
27
|
+
readonly parentConversationId: string;
|
|
28
|
+
readonly workId: string;
|
|
29
|
+
readonly sessionIds: readonly string[];
|
|
30
|
+
readonly executionBindings?: Readonly<Record<string, {
|
|
31
|
+
readonly executionEpoch: string;
|
|
32
|
+
readonly goalRevision: number;
|
|
33
|
+
}>>;
|
|
34
|
+
}
|
|
35
|
+
export interface ResourceWaitReference {
|
|
36
|
+
readonly kind: 'resource';
|
|
37
|
+
readonly id: string;
|
|
38
|
+
readonly revision: string;
|
|
39
|
+
}
|
|
40
|
+
export interface ResourceWaitFact {
|
|
41
|
+
readonly sessionId: string;
|
|
42
|
+
readonly wait: ResourceWaitReference;
|
|
43
|
+
readonly reason: string;
|
|
44
|
+
}
|
|
45
|
+
export type ResourceWaitInspection = {
|
|
46
|
+
readonly state: 'waiting';
|
|
47
|
+
readonly current: ResourceWaitFact;
|
|
48
|
+
} | {
|
|
49
|
+
readonly state: 'ready';
|
|
50
|
+
readonly sessionId: string;
|
|
51
|
+
} | {
|
|
52
|
+
readonly state: 'stale' | 'unavailable';
|
|
53
|
+
readonly reason: string;
|
|
54
|
+
};
|
|
55
|
+
export interface ResourceWaitPort {
|
|
56
|
+
readonly read: (scope: ResourceWaitScope) => readonly ResourceWaitFact[];
|
|
57
|
+
readonly inspect: (scope: ResourceWaitScope, wait: ResourceWaitReference) => ResourceWaitInspection;
|
|
58
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { WORK_SESSION_STATUSES } from "./delegation.js";
|
|
2
|
+
import { decideFollowUp } from "./task-overview.js";
|
|
3
|
+
const record = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : {};
|
|
4
|
+
const text = (value) => typeof value === 'string' ? value : '';
|
|
5
|
+
const statuses = new Set(WORK_SESSION_STATUSES);
|
|
6
|
+
const ownerships = new Set(['live', 'ended', 'unknown']);
|
|
7
|
+
const owners = new Set(['bot', 'user', 'none']);
|
|
8
|
+
const reasons = new Set(['settled', 'superseded', 'stop_confirmed', 'user_withdrawn',
|
|
9
|
+
'stop_unconfirmed', 'human_request', 'awaiting_human_gate', 'technical_block', 'awaiting_acceptance_technical',
|
|
10
|
+
'verification_failed', 'live_execution', 'paused', 'unknown_facts']);
|
|
11
|
+
const hostReasons = new Set(['live_execution', 'stop_unconfirmed', 'unknown_facts']);
|
|
12
|
+
export function runtimeSessionFacts(value) {
|
|
13
|
+
const row = record(value), origin = record(row.origin), cancellation = record(origin.cancellation);
|
|
14
|
+
const sessionId = text(row.sessionId), rawStatus = text(row.status);
|
|
15
|
+
const status = statuses.has(rawStatus) ? rawStatus : 'unknown';
|
|
16
|
+
const executionOwnership = ownerships.has(row.executionOwnership)
|
|
17
|
+
? row.executionOwnership : 'unknown';
|
|
18
|
+
const declared = row.followUp === undefined ? null : record(row.followUp);
|
|
19
|
+
const valid = Boolean(sessionId) && status !== 'unknown'
|
|
20
|
+
&& (row.executionOwnership === undefined || ownerships.has(row.executionOwnership))
|
|
21
|
+
&& (!declared || owners.has(declared.owner) && reasons.has(declared.reason))
|
|
22
|
+
&& ['resultConfirmationRequired', 'completionReviewRequired'].every(key => row[key] === undefined || typeof row[key] === 'boolean')
|
|
23
|
+
&& (row.needsUser === undefined || typeof row.needsUser === 'boolean' || Array.isArray(row.needsUser));
|
|
24
|
+
const human = row.resultConfirmationRequired === true || row.completionReviewRequired === true
|
|
25
|
+
|| row.needsUser === true || Array.isArray(row.needsUser) && row.needsUser.length > 0;
|
|
26
|
+
const fallback = status === 'unknown' ? null : decideFollowUp({ status }, {
|
|
27
|
+
accepted: status === 'accepted', humanGate: row.resultConfirmationRequired === true,
|
|
28
|
+
...(typeof cancellation.phase === 'string' ? { cancellationPhase: cancellation.phase } : {}),
|
|
29
|
+
...(cancellation.disposition === 'user_withdrawn' ? { cancellationDisposition: 'user_withdrawn' } : {}),
|
|
30
|
+
}, executionOwnership);
|
|
31
|
+
const owner = declared && owners.has(declared.owner) ? declared.owner : fallback?.owner || 'bot';
|
|
32
|
+
const reason = text(declared?.reason) || fallback?.reason || 'unknown_facts';
|
|
33
|
+
const stopping = ['stopping', 'awaiting_outcome'].includes(status)
|
|
34
|
+
|| status === 'cancelled' && owner !== 'none';
|
|
35
|
+
const handling = !valid ? 'host' : human || owner === 'user' ? 'user'
|
|
36
|
+
: executionOwnership === 'live' || stopping || owner === 'bot' && hostReasons.has(reason) ? 'host'
|
|
37
|
+
: owner === 'none' ? 'none' : 'model';
|
|
38
|
+
return { sessionId, status, valid, executionOwnership, owner, reason, handling,
|
|
39
|
+
pendingManaged: handling === 'host' || handling === 'user' || !['accepted', 'cancelled'].includes(status) };
|
|
40
|
+
}
|
|
41
|
+
/** Missing/invalid facts remain obligations; a valid public terminal does not invent live ownership. */
|
|
42
|
+
export function hasPendingRuntimeSessions(sessions, expectedIds = []) {
|
|
43
|
+
return sessions.some(session => runtimeSessionFacts(session).pendingManaged)
|
|
44
|
+
|| expectedIds.some(id => !sessions.some(session => record(session).sessionId === id));
|
|
45
|
+
}
|
|
46
|
+
export function runtimeSessionOwnership(sessions) {
|
|
47
|
+
const facts = sessions.map(runtimeSessionFacts);
|
|
48
|
+
return {
|
|
49
|
+
repairSessionIds: facts.filter(row => row.handling === 'model').map(row => row.sessionId),
|
|
50
|
+
hostSessionIds: facts.filter(row => row.handling === 'host').map(row => row.sessionId),
|
|
51
|
+
waitingSessionIds: facts.filter(row => row.handling === 'host'
|
|
52
|
+
&& (row.executionOwnership === 'live' || row.reason === 'live_execution')).map(row => row.sessionId),
|
|
53
|
+
needsUser: facts.some(row => row.handling === 'user'),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -10,6 +10,8 @@ export interface SessionExecutionIdentity {
|
|
|
10
10
|
readonly goalRevision?: number;
|
|
11
11
|
readonly generation?: string;
|
|
12
12
|
}
|
|
13
|
+
/** Shape only; a host must still compare it with the current canonical plan. */
|
|
14
|
+
export declare function normalizeSessionExecutionIdentity(raw: unknown): SessionExecutionIdentity | undefined;
|
|
13
15
|
export interface StopBarrierReceipt {
|
|
14
16
|
readonly receiptId: string;
|
|
15
17
|
readonly operationId: string;
|
package/dist/session-control.js
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/** Shape only; a host must still compare it with the current canonical plan. */
|
|
2
|
+
export function normalizeSessionExecutionIdentity(raw) {
|
|
3
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw) || ![Object.prototype, null].includes(Object.getPrototypeOf(raw)))
|
|
4
|
+
return;
|
|
5
|
+
const value = raw;
|
|
6
|
+
const token = (item) => typeof item === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,255}$/.test(item) && !item.includes('..');
|
|
7
|
+
if (Object.entries(Object.getOwnPropertyDescriptors(value)).some(([key, descriptor]) => !['planId', 'sessionId', 'executionEpoch', 'goalRevision', 'generation'].includes(key) || !('value' in descriptor))
|
|
8
|
+
|| !token(value.planId) || !token(value.sessionId) || typeof value.executionEpoch !== 'string' || !value.executionEpoch.length || value.executionEpoch.length > 512
|
|
9
|
+
|| /[\u0000-\u001f]/.test(value.executionEpoch) || value.generation !== undefined && !token(value.generation)
|
|
10
|
+
|| value.goalRevision !== undefined && (!Number.isSafeInteger(value.goalRevision) || Number(value.goalRevision) < 0))
|
|
11
|
+
return;
|
|
12
|
+
return { planId: value.planId, sessionId: value.sessionId, executionEpoch: value.executionEpoch,
|
|
13
|
+
...(value.generation !== undefined ? { generation: value.generation } : {}), ...(value.goalRevision !== undefined ? { goalRevision: Number(value.goalRevision) } : {}) };
|
|
14
|
+
}
|
|
1
15
|
/** Feed the existing lifecycle projector; a stale compatibility mirror cannot revive an old stop. */
|
|
2
16
|
export function controlPhasesForOrigin(origin) {
|
|
3
17
|
const control = origin.executionControl;
|
|
@@ -58,6 +58,18 @@ export interface VerificationDispatchReconciliation {
|
|
|
58
58
|
readonly outcome: 'verification_interrupted' | 'query_interrupted';
|
|
59
59
|
readonly at: string;
|
|
60
60
|
}
|
|
61
|
+
/** A registered, paired delegation result settles its dispatch, never its task. */
|
|
62
|
+
export interface SettledDelegationDispatch {
|
|
63
|
+
readonly attemptId?: string;
|
|
64
|
+
readonly turnId: string;
|
|
65
|
+
readonly toolCallId: string;
|
|
66
|
+
readonly evidenceRef: string;
|
|
67
|
+
readonly operationId: string;
|
|
68
|
+
readonly sessionId: string;
|
|
69
|
+
readonly executionEpoch: string;
|
|
70
|
+
readonly goalRevision: number;
|
|
71
|
+
readonly at: string;
|
|
72
|
+
}
|
|
61
73
|
export interface ProjectWorkReceipt {
|
|
62
74
|
readonly schemaVersion: 1;
|
|
63
75
|
readonly workId: string;
|
|
@@ -89,8 +101,9 @@ export interface ProjectWorkReceipt {
|
|
|
89
101
|
readonly attemptId?: string;
|
|
90
102
|
readonly pendingEventIds?: readonly string[];
|
|
91
103
|
readonly waitFor: readonly {
|
|
92
|
-
readonly kind: 'session' | 'approval' | 'question' | 'retry_timer';
|
|
104
|
+
readonly kind: 'session' | 'approval' | 'question' | 'retry_timer' | 'human_request' | 'resource' | 'recovery';
|
|
93
105
|
readonly id: string;
|
|
106
|
+
readonly revision?: string;
|
|
94
107
|
}[];
|
|
95
108
|
readonly consumedEventIds: readonly string[];
|
|
96
109
|
readonly pendingResultRefs: readonly string[];
|
|
@@ -123,6 +136,7 @@ export interface ProjectWorkReceipt {
|
|
|
123
136
|
}[];
|
|
124
137
|
}>>;
|
|
125
138
|
readonly reconciledDispatches?: readonly VerificationDispatchReconciliation[];
|
|
139
|
+
readonly settledDispatches?: readonly SettledDelegationDispatch[];
|
|
126
140
|
readonly uncertainDispatches?: readonly {
|
|
127
141
|
readonly attemptId: string;
|
|
128
142
|
readonly role: string;
|