@peer-agent/protocol 0.0.12 → 0.0.14
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/desktop-preview.d.ts +23 -0
- package/dist/desktop-preview.js +4 -0
- package/dist/goal.d.ts +18 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/model-menu.d.ts +20 -0
- package/dist/model-menu.js +25 -0
- package/dist/remote-access.d.ts +52 -0
- package/dist/remote-access.js +58 -0
- package/dist/ui-delivery-verification.d.ts +39 -0
- package/dist/ui-delivery-verification.js +60 -0
- package/package.json +1 -1
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** Private parent/child IPC for a Peer-owned preview. Never a renderer or model API. */
|
|
2
|
+
export declare const DESKTOP_PREVIEW_PROTOCOL: "peer-desktop-preview-v1";
|
|
3
|
+
export type DesktopPreviewScene = 'application' | 'background-runtime';
|
|
4
|
+
export type DesktopPreviewRequest = {
|
|
5
|
+
protocol: typeof DESKTOP_PREVIEW_PROTOCOL;
|
|
6
|
+
requestId: string;
|
|
7
|
+
action: 'observe' | 'close' | 'keepalive';
|
|
8
|
+
scene?: DesktopPreviewScene;
|
|
9
|
+
};
|
|
10
|
+
export type DesktopPreviewReply = {
|
|
11
|
+
protocol: typeof DESKTOP_PREVIEW_PROTOCOL;
|
|
12
|
+
requestId?: string;
|
|
13
|
+
instanceId: string;
|
|
14
|
+
status: 'ready' | 'observed' | 'failed';
|
|
15
|
+
buildFingerprint?: string;
|
|
16
|
+
scene?: DesktopPreviewScene;
|
|
17
|
+
pngBase64?: string;
|
|
18
|
+
width?: number;
|
|
19
|
+
height?: number;
|
|
20
|
+
error?: string;
|
|
21
|
+
};
|
|
22
|
+
export declare const DESKTOP_PREVIEW_CAPABILITY: "local.desktop.preview";
|
|
23
|
+
export declare const DESKTOP_PREVIEW_TOOL: "desktop_preview";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Private parent/child IPC for a Peer-owned preview. Never a renderer or model API. */
|
|
2
|
+
export const DESKTOP_PREVIEW_PROTOCOL = 'peer-desktop-preview-v1';
|
|
3
|
+
export const DESKTOP_PREVIEW_CAPABILITY = 'local.desktop.preview';
|
|
4
|
+
export const DESKTOP_PREVIEW_TOOL = 'desktop_preview';
|
package/dist/goal.d.ts
CHANGED
|
@@ -614,6 +614,24 @@ export interface GoalRunnerState {
|
|
|
614
614
|
readonly reason: string;
|
|
615
615
|
readonly interruptedAt: string;
|
|
616
616
|
};
|
|
617
|
+
/**
|
|
618
|
+
* Independent visual-repair budget. Not maxTurns. Host-normalized findings only;
|
|
619
|
+
* never raw model text or image bytes.
|
|
620
|
+
*/
|
|
621
|
+
readonly visualRepair?: {
|
|
622
|
+
readonly attempts: number;
|
|
623
|
+
readonly maxAttempts: number;
|
|
624
|
+
readonly lastFingerprint?: string;
|
|
625
|
+
readonly pendingTurn?: boolean;
|
|
626
|
+
readonly feedback: {
|
|
627
|
+
readonly verdict: 'failed' | 'inconclusive';
|
|
628
|
+
readonly scene: string;
|
|
629
|
+
readonly artifactRef?: string;
|
|
630
|
+
readonly evidenceRef?: string;
|
|
631
|
+
readonly findings: readonly string[];
|
|
632
|
+
readonly repairSuggestions: readonly string[];
|
|
633
|
+
};
|
|
634
|
+
};
|
|
617
635
|
readonly updatedAt: string;
|
|
618
636
|
}
|
|
619
637
|
/** 计划 Artifact 定型版,见提案 §3。 */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
export type { SelectionRange, SelectionReference, SelectionDraft, SelectionOrigin, SelectionChildSession, SelectionChildSummary, SelectionChildrenPage, SelectionChildRead } from './selection-reference.ts';
|
|
2
|
+
export { buildModelMenuGroups, modelMenuChannelName, type ModelMenuRow } from './model-menu.ts';
|
|
3
|
+
export { evaluateUiDelivery } from './ui-delivery-verification.ts';
|
|
4
|
+
export { DESKTOP_PREVIEW_PROTOCOL, DESKTOP_PREVIEW_CAPABILITY, DESKTOP_PREVIEW_TOOL } from './desktop-preview.ts';
|
|
5
|
+
export type { DesktopPreviewRequest, DesktopPreviewReply } from './desktop-preview.ts';
|
|
6
|
+
export type { UiDeliveryIdentity, UiDeliveryRequirement, UiDeliveryObservation, UiDeliveryJudgment, UiDeliveryGap } from './ui-delivery-verification.ts';
|
|
7
|
+
export { REMOTE_PROTOCOL_VERSION, parseRemoteReadRequest, admitRemoteRead } from './remote-access.ts';
|
|
8
|
+
export type { RemoteReadRequest, RemoteReadContext, RemoteReadRejection, RemoteReadAdmission } from './remote-access.ts';
|
|
2
9
|
export type LocalAccessLevel = 'ask_before_local' | 'session_local' | 'restricted_local' | 'full_local';
|
|
3
10
|
export type { ConversationLifetimeUsage, ProviderRequestUsage, RuntimeTurnUsage, UsageAmounts, UsageScope, } from './usage-accounting.ts';
|
|
4
11
|
export type CapabilityRiskLevel = 'L0_inert' | 'L1_local_read' | 'L2_local_write' | 'L3_external_write' | 'L4_privileged' | 'L5_destructive';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export { buildModelMenuGroups, modelMenuChannelName } from "./model-menu.js";
|
|
2
|
+
export { evaluateUiDelivery } from "./ui-delivery-verification.js";
|
|
3
|
+
export { DESKTOP_PREVIEW_PROTOCOL, DESKTOP_PREVIEW_CAPABILITY, DESKTOP_PREVIEW_TOOL } from "./desktop-preview.js";
|
|
4
|
+
export { REMOTE_PROTOCOL_VERSION, parseRemoteReadRequest, admitRemoteRead } from "./remote-access.js";
|
|
1
5
|
export function resolveLlmModelOptionValues(definitions, values) {
|
|
2
6
|
if (!definitions?.length)
|
|
3
7
|
return {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Presentation-only model menu projection shared by local clients. No sorting or deduplication. */
|
|
2
|
+
export declare function modelMenuChannelName(name: string | undefined, model: string, authMethod: string | undefined, isZh: boolean): string;
|
|
3
|
+
export interface ModelMenuRow {
|
|
4
|
+
readonly id: string;
|
|
5
|
+
readonly groupId?: string;
|
|
6
|
+
readonly groupLabel: string;
|
|
7
|
+
readonly model: string;
|
|
8
|
+
readonly modelLabel?: string;
|
|
9
|
+
readonly available: boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildModelMenuGroups(rows: readonly ModelMenuRow[], hideDisabled?: boolean): {
|
|
12
|
+
disabled: boolean;
|
|
13
|
+
id: string;
|
|
14
|
+
label: string;
|
|
15
|
+
items: {
|
|
16
|
+
id: string;
|
|
17
|
+
label: string;
|
|
18
|
+
disabled: boolean;
|
|
19
|
+
}[];
|
|
20
|
+
}[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Presentation-only model menu projection shared by local clients. No sorting or deduplication. */
|
|
2
|
+
export function modelMenuChannelName(name, model, authMethod, isZh) {
|
|
3
|
+
const trimmed = name?.trim();
|
|
4
|
+
if (authMethod === 'oauth_chatgpt' && (!trimmed || trimmed === 'ChatGPT 订阅' || trimmed === 'ChatGPT Subscription')) {
|
|
5
|
+
return isZh ? 'ChatGPT 订阅' : 'ChatGPT Subscription';
|
|
6
|
+
}
|
|
7
|
+
return trimmed || model;
|
|
8
|
+
}
|
|
9
|
+
export function buildModelMenuGroups(rows, hideDisabled = false) {
|
|
10
|
+
const groups = new Map();
|
|
11
|
+
for (const row of rows) {
|
|
12
|
+
const key = row.groupId || row.id;
|
|
13
|
+
let group = groups.get(key);
|
|
14
|
+
if (!group) {
|
|
15
|
+
group = { id: key, label: row.groupLabel, items: [] };
|
|
16
|
+
groups.set(key, group);
|
|
17
|
+
}
|
|
18
|
+
if (!hideDisabled || row.available) {
|
|
19
|
+
group.items.push({ id: row.id, label: row.modelLabel || row.model, disabled: !row.available });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return [...groups.values()]
|
|
23
|
+
.filter((group) => !hideDisabled || group.items.length > 0)
|
|
24
|
+
.map((group) => ({ ...group, disabled: group.items.every((item) => item.disabled) }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/** ADR 75: preflight checks only. Passing does not grant tool execution permission. */
|
|
2
|
+
export declare const REMOTE_PROTOCOL_VERSION: 1;
|
|
3
|
+
export interface RemoteReadRequest {
|
|
4
|
+
readonly protocolVersion: typeof REMOTE_PROTOCOL_VERSION;
|
|
5
|
+
readonly type: 'task.submit';
|
|
6
|
+
readonly requestId: string;
|
|
7
|
+
readonly ownerId: string;
|
|
8
|
+
readonly deviceId: string;
|
|
9
|
+
readonly workspaceId: string;
|
|
10
|
+
readonly bindingVersion: number;
|
|
11
|
+
readonly connectionEpoch: number;
|
|
12
|
+
readonly delegationVersion: number;
|
|
13
|
+
readonly expiresAt: number;
|
|
14
|
+
readonly operation: 'task.read';
|
|
15
|
+
readonly taskId: string;
|
|
16
|
+
}
|
|
17
|
+
/** Constructed by the authenticated host, never from a request payload. */
|
|
18
|
+
export interface RemoteReadContext {
|
|
19
|
+
readonly now: number;
|
|
20
|
+
readonly ownerId: string;
|
|
21
|
+
readonly deviceId: string;
|
|
22
|
+
readonly bindingVersion: number;
|
|
23
|
+
readonly connectionEpoch: number;
|
|
24
|
+
readonly online: boolean;
|
|
25
|
+
readonly bindingRevoked: boolean;
|
|
26
|
+
readonly delegation: {
|
|
27
|
+
readonly version: number;
|
|
28
|
+
readonly expiresAt: number;
|
|
29
|
+
readonly revoked: boolean;
|
|
30
|
+
readonly workspaceIds: readonly string[];
|
|
31
|
+
readonly allowTaskRead: boolean;
|
|
32
|
+
readonly allowResultExport: boolean;
|
|
33
|
+
};
|
|
34
|
+
/** Resolve from the local task store; caller must not trust client task ownership. */
|
|
35
|
+
readonly task: {
|
|
36
|
+
readonly taskId: string;
|
|
37
|
+
readonly ownerId: string;
|
|
38
|
+
readonly workspaceId: string;
|
|
39
|
+
} | null;
|
|
40
|
+
}
|
|
41
|
+
export type RemoteReadRejection = 'INVALID_REQUEST' | 'PROTOCOL_UNSUPPORTED' | 'IDENTITY_UNBOUND' | 'DEVICE_OFFLINE' | 'STALE_CONNECTION' | 'REQUEST_EXPIRED' | 'DELEGATION_EXPIRED' | 'WORKSPACE_DENIED' | 'CAPABILITY_DENIED' | 'EXPORT_DENIED' | 'TASK_DENIED';
|
|
42
|
+
export type RemoteReadAdmission = {
|
|
43
|
+
readonly ok: true;
|
|
44
|
+
readonly request: RemoteReadRequest;
|
|
45
|
+
} | {
|
|
46
|
+
readonly ok: false;
|
|
47
|
+
readonly code: RemoteReadRejection;
|
|
48
|
+
};
|
|
49
|
+
/** Strict wire shape: M1 deliberately has no shell, path, arbitrary arguments, or writes. */
|
|
50
|
+
export declare function parseRemoteReadRequest(value: unknown): RemoteReadAdmission;
|
|
51
|
+
/** New submissions only. Duplicate receipt lookup belongs to the persistent host ledger. */
|
|
52
|
+
export declare function admitRemoteRead(value: unknown, context: RemoteReadContext): RemoteReadAdmission;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** ADR 75: preflight checks only. Passing does not grant tool execution permission. */
|
|
2
|
+
export const REMOTE_PROTOCOL_VERSION = 1;
|
|
3
|
+
const fields = new Set([
|
|
4
|
+
'protocolVersion', 'type', 'requestId', 'ownerId', 'deviceId', 'workspaceId',
|
|
5
|
+
'bindingVersion', 'connectionEpoch', 'delegationVersion', 'expiresAt', 'operation', 'taskId',
|
|
6
|
+
]);
|
|
7
|
+
const identifier = (value) => typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/.test(value);
|
|
8
|
+
const integer = (value) => typeof value === 'number' && Number.isSafeInteger(value) && value > 0;
|
|
9
|
+
/** Strict wire shape: M1 deliberately has no shell, path, arbitrary arguments, or writes. */
|
|
10
|
+
export function parseRemoteReadRequest(value) {
|
|
11
|
+
const reject = (code) => ({ ok: false, code });
|
|
12
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
13
|
+
return reject('INVALID_REQUEST');
|
|
14
|
+
const r = value;
|
|
15
|
+
if (r.protocolVersion !== REMOTE_PROTOCOL_VERSION)
|
|
16
|
+
return reject('PROTOCOL_UNSUPPORTED');
|
|
17
|
+
if (Object.keys(r).length !== fields.size || Object.keys(r).some(key => !fields.has(key))) {
|
|
18
|
+
return reject('INVALID_REQUEST');
|
|
19
|
+
}
|
|
20
|
+
if (r.type !== 'task.submit' || r.operation !== 'task.read'
|
|
21
|
+
|| !['requestId', 'ownerId', 'deviceId', 'workspaceId', 'taskId'].every(key => identifier(r[key]))
|
|
22
|
+
|| !['bindingVersion', 'connectionEpoch', 'delegationVersion', 'expiresAt'].every(key => integer(r[key]))) {
|
|
23
|
+
return reject('INVALID_REQUEST');
|
|
24
|
+
}
|
|
25
|
+
return { ok: true, request: { ...r } };
|
|
26
|
+
}
|
|
27
|
+
/** New submissions only. Duplicate receipt lookup belongs to the persistent host ledger. */
|
|
28
|
+
export function admitRemoteRead(value, context) {
|
|
29
|
+
const parsed = parseRemoteReadRequest(value);
|
|
30
|
+
if (!parsed.ok)
|
|
31
|
+
return parsed;
|
|
32
|
+
const r = parsed.request;
|
|
33
|
+
const deny = (code) => ({ ok: false, code });
|
|
34
|
+
if (context.bindingRevoked || r.ownerId !== context.ownerId || r.deviceId !== context.deviceId
|
|
35
|
+
|| r.bindingVersion !== context.bindingVersion)
|
|
36
|
+
return deny('IDENTITY_UNBOUND');
|
|
37
|
+
const d = context.delegation;
|
|
38
|
+
if (!Number.isFinite(context.now) || !Number.isFinite(d.expiresAt)
|
|
39
|
+
|| d.revoked || d.expiresAt <= context.now || r.delegationVersion !== d.version) {
|
|
40
|
+
return deny('DELEGATION_EXPIRED');
|
|
41
|
+
}
|
|
42
|
+
if (!d.workspaceIds.includes(r.workspaceId))
|
|
43
|
+
return deny('WORKSPACE_DENIED');
|
|
44
|
+
if (!d.allowTaskRead)
|
|
45
|
+
return deny('CAPABILITY_DENIED');
|
|
46
|
+
if (!d.allowResultExport)
|
|
47
|
+
return deny('EXPORT_DENIED');
|
|
48
|
+
if (!context.task || context.task.taskId !== r.taskId || context.task.ownerId !== r.ownerId
|
|
49
|
+
|| context.task.workspaceId !== r.workspaceId)
|
|
50
|
+
return deny('TASK_DENIED');
|
|
51
|
+
if (!context.online)
|
|
52
|
+
return deny('DEVICE_OFFLINE');
|
|
53
|
+
if (r.connectionEpoch !== context.connectionEpoch)
|
|
54
|
+
return deny('STALE_CONNECTION');
|
|
55
|
+
if (r.expiresAt <= context.now || r.expiresAt - context.now > 30_000)
|
|
56
|
+
return deny('REQUEST_EXPIRED');
|
|
57
|
+
return parsed;
|
|
58
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Inputs are resolved by the local evidence authority, never trusted from model arguments.
|
|
2
|
+
* Pure checking here does not authorize preview execution or validate image bytes.
|
|
3
|
+
*/
|
|
4
|
+
export interface UiDeliveryIdentity {
|
|
5
|
+
readonly requirementRevision: string;
|
|
6
|
+
readonly buildFingerprint: string;
|
|
7
|
+
readonly instanceId: string;
|
|
8
|
+
}
|
|
9
|
+
export interface UiDeliveryRequirement extends UiDeliveryIdentity {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
readonly host: 'web' | 'desktop';
|
|
12
|
+
}
|
|
13
|
+
export interface UiDeliveryObservation extends UiDeliveryIdentity {
|
|
14
|
+
readonly requirementId: string;
|
|
15
|
+
readonly host: 'web' | 'desktop';
|
|
16
|
+
readonly evidenceRef: string;
|
|
17
|
+
readonly artifactHash: string;
|
|
18
|
+
/** Local image validation and context admission, not a model assertion. */
|
|
19
|
+
readonly admittedToRunId: string;
|
|
20
|
+
}
|
|
21
|
+
export interface UiDeliveryJudgment {
|
|
22
|
+
readonly requirementId: string;
|
|
23
|
+
readonly observationRef: string;
|
|
24
|
+
readonly modelRunId: string;
|
|
25
|
+
readonly evidenceRef: string;
|
|
26
|
+
readonly decision: 'passed' | 'failed' | 'unknown';
|
|
27
|
+
}
|
|
28
|
+
export type UiDeliveryGap = 'invalid-requirement' | 'judgment-missing' | 'judgment-unresolved' | 'judgment-failed' | 'judgment-unknown' | 'observation-missing' | 'observation-unresolved' | 'observation-stale' | 'image-not-admitted' | 'invalid-record';
|
|
29
|
+
/** Empty requirements preserve legacy non-UI behavior. The host must supply the
|
|
30
|
+
* authoritative requirements and current identities; callers cannot omit UI pins.
|
|
31
|
+
* Last judgment per requirement supersedes earlier success, including failed reruns.
|
|
32
|
+
*/
|
|
33
|
+
export declare function evaluateUiDelivery(requirements: readonly UiDeliveryRequirement[], observations: readonly UiDeliveryObservation[], judgments: readonly UiDeliveryJudgment[], knownEvidenceRefs: ReadonlySet<string>): {
|
|
34
|
+
passed: boolean;
|
|
35
|
+
gaps: {
|
|
36
|
+
requirementId: string;
|
|
37
|
+
reason: UiDeliveryGap;
|
|
38
|
+
}[];
|
|
39
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Empty requirements preserve legacy non-UI behavior. The host must supply the
|
|
2
|
+
* authoritative requirements and current identities; callers cannot omit UI pins.
|
|
3
|
+
* Last judgment per requirement supersedes earlier success, including failed reruns.
|
|
4
|
+
*/
|
|
5
|
+
export function evaluateUiDelivery(requirements, observations, judgments, knownEvidenceRefs) {
|
|
6
|
+
// Persisted JSON may be corrupt despite static types. Do not discard bad
|
|
7
|
+
// records: dropping a malformed latest judgment could resurrect an old pass.
|
|
8
|
+
if (![requirements, observations, judgments].every(list => Array.isArray(list)
|
|
9
|
+
&& list.every(item => item !== null && typeof item === 'object' && !Array.isArray(item)))) {
|
|
10
|
+
return { passed: false, gaps: [{ requirementId: '', reason: 'invalid-record' }] };
|
|
11
|
+
}
|
|
12
|
+
const gaps = [];
|
|
13
|
+
const latest = new Map(judgments.map(j => [j.requirementId, j]));
|
|
14
|
+
const seen = new Set();
|
|
15
|
+
for (const r of requirements) {
|
|
16
|
+
const add = (reason) => gaps.push({ requirementId: r.id, reason });
|
|
17
|
+
if (![r.id, r.requirementRevision, r.buildFingerprint, r.instanceId].every(nonempty)
|
|
18
|
+
|| !['web', 'desktop'].includes(r.host) || seen.has(r.id)) {
|
|
19
|
+
add('invalid-requirement');
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
seen.add(r.id);
|
|
23
|
+
const j = latest.get(r.id);
|
|
24
|
+
if (!j) {
|
|
25
|
+
add('judgment-missing');
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (!nonempty(j.evidenceRef) || !knownEvidenceRefs.has(j.evidenceRef)) {
|
|
29
|
+
add('judgment-unresolved');
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (j.decision !== 'passed') {
|
|
33
|
+
add(j.decision === 'failed' ? 'judgment-failed' : 'judgment-unknown');
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const matches = observations.filter(o => o.evidenceRef === j.observationRef);
|
|
37
|
+
if (matches.length !== 1) {
|
|
38
|
+
add('observation-missing');
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const o = matches[0];
|
|
42
|
+
if (!nonempty(o.evidenceRef) || !knownEvidenceRefs.has(o.evidenceRef)) {
|
|
43
|
+
add('observation-unresolved');
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
if (o.requirementId !== r.id || o.host !== r.host
|
|
47
|
+
|| o.requirementRevision !== r.requirementRevision
|
|
48
|
+
|| o.buildFingerprint !== r.buildFingerprint || o.instanceId !== r.instanceId) {
|
|
49
|
+
add('observation-stale');
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (!nonempty(o.artifactHash) || !nonempty(j.modelRunId)
|
|
53
|
+
|| o.admittedToRunId !== j.modelRunId)
|
|
54
|
+
add('image-not-admitted');
|
|
55
|
+
}
|
|
56
|
+
return { passed: gaps.length === 0, gaps };
|
|
57
|
+
}
|
|
58
|
+
function nonempty(value) {
|
|
59
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
60
|
+
}
|