Repository navigation
Expand file tree
/
Copy pathbackend.ts
More file actions
99 lines (94 loc) · 3.46 KB
/
Copy pathbackend.ts
File metadata and controls
99 lines (94 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import type { AgentSettings, Submission } from './protocol';
export type BackendOwnership = 'managed' | 'adopted';
export type BackendCapabilities = Record<string, boolean>;
export interface RuntimeMetadata {
rPid?: number;
rVersion?: string;
runtimeSessionId?: string;
rPath?: string;
libraryPaths?: string[];
}
export type InspectionMethod =
| 'workspace'
| 'workspace_children'
| 'workspace_view'
| 'listview_navigate'
| 'listview_view'
| 'hover'
| 'completion'
| 'dataview_init'
| 'dataview_page'
| 'dataview_dispose';
export interface InspectionRequest {
method: InspectionMethod;
params: Record<string, unknown>;
timeout?: number;
}
export interface InputReply {
value: string;
}
export interface ClientReply {
result?: unknown;
error?: string;
}
export interface ResizePlotRequest {
device: string;
plot: number;
width: number;
height: number;
}
/** Decoded application events; no provider sockets, wire packets or RPC identifiers. */
export type BackendEvent = (
| { type: 'ready'; metadata: RuntimeMetadata; capabilities: BackendCapabilities }
| { type: 'metadata'; metadata: RuntimeMetadata }
| { type: 'started' }
| { type: 'finished'; state: 'success' | 'error' | 'interrupted' }
| { type: 'stream'; text: string; channel: string; external?: boolean }
| { type: 'condition' | 'input' | 'display'; data: Record<string, unknown> }
| { type: 'workspaceChanged' }
| { type: 'notification' | 'viewer'; method: string; params: Record<string, unknown> }
| { type: 'clientRequest'; id: string; method: string; params: unknown }
| { type: 'clientRequestExpired'; id: string }
| { type: 'external'; code: string; success: boolean }
| { type: 'warning' | 'error' | 'truncated'; message: string }
| { type: 'provider'; data: Record<string, unknown> }
| { type: 'unavailable'; message: string }
| { type: 'exit'; code?: number | null; signal?: string | null }
) & { executionId?: string };
export interface SessionBackend {
readonly ownership: BackendOwnership;
readonly capabilities: BackendCapabilities;
onEvent(listener: (event: BackendEvent) => void): () => void;
start(): Promise<void>;
/** Acknowledges transport only. Started/finished events establish evaluation outcome. */
dispatch(submission: Submission): Promise<void>;
inspect(request: InspectionRequest): Promise<unknown>;
replyInput(reply: InputReply): Promise<void>;
replyClientRequest(id: string, reply: ClientReply): Promise<void>;
interrupt(): Promise<void>;
/** Explicit user Stop, including for an adopted runtime. Resolves after confirmed exit. */
stop(options?: { force?: boolean }): Promise<void>;
resizePlot?(request: ResizePlotRequest): Promise<void>;
/** Bounded, idempotent cleanup. Must not kill an adopted runtime. */
dispose(): Promise<void>;
}
export type BackendFactory = (settings: AgentSettings) => SessionBackend;
export function inspectionMethod(value: unknown): InspectionMethod {
if (
![
'workspace',
'workspace_children',
'workspace_view',
'listview_navigate',
'listview_view',
'hover',
'completion',
'dataview_init',
'dataview_page',
'dataview_dispose',
].includes(String(value))
) {
throw new Error('Unsupported inspection method');
}
return value as InspectionMethod;
}