@frockbot/plugin-computer 0.0.0 → 0.1.1
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/frockbot.json +25 -0
- package/package.json +54 -6
- package/src/agent.test.ts +271 -0
- package/src/agent.ts +1419 -0
- package/src/backend.test.ts +149 -0
- package/src/backend.ts +163 -0
- package/src/bot.test.ts +411 -0
- package/src/bot.ts +831 -0
- package/src/client/ComputerCard.test.ts +96 -0
- package/src/client/ComputerCard.vue +60 -0
- package/src/client/ComputerStrip.test.ts +54 -0
- package/src/client/ComputerStrip.vue +55 -0
- package/src/client/ComputerViewerOverlay.vue +252 -0
- package/src/client/application.test.ts +403 -0
- package/src/client/application.ts +359 -0
- package/src/client/cordis-client-shim.d.ts +16 -0
- package/src/client/dialog-focus.ts +13 -0
- package/src/client/index.ts +28 -0
- package/src/client/state-machine.test.ts +200 -0
- package/src/client/state-machine.ts +172 -0
- package/src/client/styles.css +594 -0
- package/src/client/viewer.ts +58 -0
- package/src/control-record.ts +57 -0
- package/src/doctor.test.ts +247 -0
- package/src/env.d.ts +12 -0
- package/src/index.ts +6 -0
- package/src/manifest.ts +3 -0
- package/src/process-records.test.ts +178 -0
- package/src/process-records.ts +278 -0
- package/src/process-store.ts +96 -0
- package/src/processes.test.ts +388 -0
- package/src/protocol.ts +405 -0
- package/src/roots.ts +6 -0
- package/src/screenshot.test.ts +253 -0
- package/src/shared-provider.test.ts +56 -0
- package/src/shared-provider.ts +121 -0
- package/src/shared.ts +54 -0
- package/src/sync.test.ts +255 -0
- package/src/workspace-fixture.ts +126 -0
- package/tsconfig.json +19 -0
- package/vite.config.ts +24 -0
- package/README.md +0 -3
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ComputerDoctorViewV1,
|
|
3
|
+
ComputerPhase,
|
|
4
|
+
ComputerProjectionV1,
|
|
5
|
+
ComputerScreenshotViewV1,
|
|
6
|
+
} from "../protocol.js";
|
|
7
|
+
|
|
8
|
+
export interface ComputerMachineState {
|
|
9
|
+
phase: ComputerPhase;
|
|
10
|
+
botId: string;
|
|
11
|
+
providerLabel: string;
|
|
12
|
+
message: string;
|
|
13
|
+
viewerUrl?: string;
|
|
14
|
+
expanded: boolean;
|
|
15
|
+
takingControl: boolean;
|
|
16
|
+
screenshots: ComputerScreenshotViewV1[];
|
|
17
|
+
doctor?: ComputerDoctorViewV1;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type ComputerMachineEvent =
|
|
21
|
+
| {
|
|
22
|
+
type: "configured";
|
|
23
|
+
botId: string;
|
|
24
|
+
providerLabel: string;
|
|
25
|
+
configured: boolean;
|
|
26
|
+
message: string;
|
|
27
|
+
}
|
|
28
|
+
| { type: "connect-requested" }
|
|
29
|
+
| { type: "update-reported"; message: string }
|
|
30
|
+
| { type: "connected"; viewerUrl: string }
|
|
31
|
+
| { type: "take-control-requested" }
|
|
32
|
+
| { type: "control-acquired" }
|
|
33
|
+
| { type: "control-released" }
|
|
34
|
+
| { type: "viewer-expanded" }
|
|
35
|
+
| { type: "viewer-collapsed" }
|
|
36
|
+
| { type: "viewer-disconnected"; message: string }
|
|
37
|
+
| { type: "retry-requested" }
|
|
38
|
+
| { type: "failed"; message: string; takingControl?: boolean }
|
|
39
|
+
| { type: "doctor-updated"; doctor: ComputerDoctorViewV1 }
|
|
40
|
+
| { type: "projection-received"; projection: ComputerProjectionV1 };
|
|
41
|
+
|
|
42
|
+
export function initialComputerMachineState(): ComputerMachineState {
|
|
43
|
+
return {
|
|
44
|
+
phase: "unconfigured",
|
|
45
|
+
botId: "unconfigured",
|
|
46
|
+
providerLabel: "unconfigured",
|
|
47
|
+
message: "No Computer provider is configured for this host",
|
|
48
|
+
viewerUrl: undefined,
|
|
49
|
+
expanded: false,
|
|
50
|
+
takingControl: false,
|
|
51
|
+
screenshots: [],
|
|
52
|
+
doctor: undefined,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The single phase transition table shared by local and hosted Computers.
|
|
58
|
+
* The client only projects authority and transient request progress; it never
|
|
59
|
+
* invents a durable lease or decides whether a Computer is actually awake.
|
|
60
|
+
*/
|
|
61
|
+
export function transitionComputerState(
|
|
62
|
+
state: ComputerMachineState,
|
|
63
|
+
event: ComputerMachineEvent,
|
|
64
|
+
): ComputerMachineState {
|
|
65
|
+
switch (event.type) {
|
|
66
|
+
case "configured":
|
|
67
|
+
return {
|
|
68
|
+
...state,
|
|
69
|
+
phase: event.configured ? "idle" : "unconfigured",
|
|
70
|
+
botId: event.botId,
|
|
71
|
+
providerLabel: event.providerLabel,
|
|
72
|
+
message: event.message,
|
|
73
|
+
viewerUrl: undefined,
|
|
74
|
+
takingControl: false,
|
|
75
|
+
};
|
|
76
|
+
case "connect-requested":
|
|
77
|
+
case "retry-requested":
|
|
78
|
+
return {
|
|
79
|
+
...state,
|
|
80
|
+
phase: "provisioning",
|
|
81
|
+
message: "Waking and preparing the Computer…",
|
|
82
|
+
viewerUrl: undefined,
|
|
83
|
+
takingControl: false,
|
|
84
|
+
};
|
|
85
|
+
case "connected":
|
|
86
|
+
return {
|
|
87
|
+
...state,
|
|
88
|
+
phase: "ready",
|
|
89
|
+
message: "Computer ready",
|
|
90
|
+
viewerUrl: event.viewerUrl,
|
|
91
|
+
takingControl: false,
|
|
92
|
+
};
|
|
93
|
+
case "update-reported":
|
|
94
|
+
return {
|
|
95
|
+
...state,
|
|
96
|
+
phase: "updating",
|
|
97
|
+
message: event.message,
|
|
98
|
+
takingControl: false,
|
|
99
|
+
};
|
|
100
|
+
case "take-control-requested":
|
|
101
|
+
return {
|
|
102
|
+
...state,
|
|
103
|
+
phase: "taking-control",
|
|
104
|
+
message: "Pausing new agent computer actions…",
|
|
105
|
+
};
|
|
106
|
+
case "control-acquired":
|
|
107
|
+
return {
|
|
108
|
+
...state,
|
|
109
|
+
phase: "human-control",
|
|
110
|
+
message: "You have control. Release when finished with private data.",
|
|
111
|
+
takingControl: true,
|
|
112
|
+
};
|
|
113
|
+
case "control-released":
|
|
114
|
+
return {
|
|
115
|
+
...state,
|
|
116
|
+
phase: "ready",
|
|
117
|
+
message: "Computer ready",
|
|
118
|
+
takingControl: false,
|
|
119
|
+
};
|
|
120
|
+
case "viewer-expanded":
|
|
121
|
+
return { ...state, expanded: true };
|
|
122
|
+
case "viewer-collapsed":
|
|
123
|
+
return { ...state, expanded: false };
|
|
124
|
+
case "viewer-disconnected":
|
|
125
|
+
return {
|
|
126
|
+
...state,
|
|
127
|
+
phase: "disconnected",
|
|
128
|
+
message: event.message,
|
|
129
|
+
viewerUrl: undefined,
|
|
130
|
+
};
|
|
131
|
+
case "failed":
|
|
132
|
+
return {
|
|
133
|
+
...state,
|
|
134
|
+
phase: "error",
|
|
135
|
+
message: event.message,
|
|
136
|
+
takingControl: event.takingControl ?? state.takingControl,
|
|
137
|
+
};
|
|
138
|
+
case "doctor-updated":
|
|
139
|
+
return { ...state, doctor: event.doctor };
|
|
140
|
+
case "projection-received": {
|
|
141
|
+
const projection = event.projection;
|
|
142
|
+
// A Workspace read URL may be reissued on every projection, but the
|
|
143
|
+
// durable bytes have not changed until their content hash does. Holding
|
|
144
|
+
// the object stable keeps Vue from replacing the visible capture merely
|
|
145
|
+
// because a wake-free poll returned another DTO instance (P1).
|
|
146
|
+
const currentCapture = state.screenshots[0];
|
|
147
|
+
const projectedCapture = projection.screenshots[0];
|
|
148
|
+
const screenshots =
|
|
149
|
+
currentCapture &&
|
|
150
|
+
projectedCapture?.contentHash === currentCapture.contentHash
|
|
151
|
+
? [currentCapture, ...projection.screenshots.slice(1)]
|
|
152
|
+
: projection.screenshots;
|
|
153
|
+
return {
|
|
154
|
+
phase: projection.phase,
|
|
155
|
+
botId: projection.botId,
|
|
156
|
+
providerLabel: projection.providerLabel,
|
|
157
|
+
message: projection.message,
|
|
158
|
+
viewerUrl:
|
|
159
|
+
projection.phase === "disconnected"
|
|
160
|
+
? undefined
|
|
161
|
+
: projection.viewerSession?.url,
|
|
162
|
+
expanded: state.expanded,
|
|
163
|
+
// A dead viewer and a live control lease can coexist. Keep projecting
|
|
164
|
+
// the lease so Close/Escape can release it explicitly instead of
|
|
165
|
+
// falling back to expiry merely because the frame disappeared (P2).
|
|
166
|
+
takingControl: projection.controlLease !== undefined,
|
|
167
|
+
screenshots,
|
|
168
|
+
doctor: projection.doctor,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|