@athree/runner-proto 2.0.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.
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@athree/runner-proto",
3
+ "version": "2.0.0",
4
+ "type": "module",
5
+ "sideEffects": false,
6
+ "exports": {
7
+ ".": "./out/main/index.js"
8
+ },
9
+ "scripts": {
10
+ "clean": "rm -rf out/ *.tsbuildinfo"
11
+ }
12
+ }
@@ -0,0 +1,166 @@
1
+ import { DomainDef } from '@nodescript/protocomm';
2
+ import { Event } from 'nanoevent';
3
+
4
+ import { KeyboardEventRequest } from '../schema/KeyboardEventRequest.js';
5
+ import { MouseEventRequest } from '../schema/MouseEventRequest.js';
6
+ import { ScreencastFrame } from '../schema/ScreencastFrame.js';
7
+
8
+ export interface BrowserDomain {
9
+
10
+ getUrl(req: {}): Promise<{
11
+ url: string;
12
+ }>;
13
+
14
+ goto(req: {
15
+ url: string;
16
+ waitUntil?: 'load' | 'domcontentloaded' | 'networkidle';
17
+ }): Promise<{}>;
18
+
19
+ sendCdpCommand(req: {
20
+ command: string;
21
+ params: any;
22
+ }): Promise<{
23
+ result: any;
24
+ }>;
25
+
26
+ startScreencast(req: {}): Promise<{}>;
27
+
28
+ stopScreencast(req: {}): Promise<{}>;
29
+
30
+ dispatchMouseEvent(req: MouseEventRequest): Promise<{}>;
31
+
32
+ dispatchKeyboardEvent(req: KeyboardEventRequest): Promise<{}>;
33
+
34
+ getViewportSize(req: {}): Promise<{
35
+ width: number;
36
+ height: number;
37
+ }>;
38
+
39
+ setViewportSize(req: {
40
+ width: number;
41
+ height: number;
42
+ }): Promise<{}>;
43
+
44
+ urlChanged: Event<{
45
+ url: string;
46
+ }>;
47
+
48
+ screencastFrame: Event<ScreencastFrame>;
49
+
50
+ }
51
+
52
+ export const BrowserDomain: DomainDef<BrowserDomain> = {
53
+ name: 'Browser',
54
+ methods: {
55
+ getUrl: {
56
+ type: 'query',
57
+ params: {},
58
+ returns: {
59
+ url: { type: 'string' },
60
+ },
61
+ },
62
+ goto: {
63
+ type: 'command',
64
+ params: {
65
+ url: { type: 'string' },
66
+ waitUntil: {
67
+ type: 'string',
68
+ enum: [
69
+ 'load',
70
+ 'domcontentloaded',
71
+ 'networkidle',
72
+ ],
73
+ optional: true,
74
+ },
75
+ },
76
+ returns: {},
77
+ },
78
+ sendCdpCommand: {
79
+ type: 'command',
80
+ params: {
81
+ command: { type: 'string' },
82
+ params: { type: 'any' },
83
+ },
84
+ returns: {
85
+ result: { type: 'any' },
86
+ },
87
+ },
88
+ startScreencast: {
89
+ type: 'command',
90
+ params: {},
91
+ returns: {},
92
+ },
93
+ stopScreencast: {
94
+ type: 'command',
95
+ params: {},
96
+ returns: {},
97
+ },
98
+ dispatchMouseEvent: {
99
+ type: 'command',
100
+ params: {
101
+ type: {
102
+ type: 'string',
103
+ enum: ['mousedown', 'mouseup', 'mousemove', 'wheel'],
104
+ },
105
+ x: { type: 'number' },
106
+ y: { type: 'number' },
107
+ button: {
108
+ type: 'string',
109
+ enum: ['left', 'right', 'middle'],
110
+ optional: true,
111
+ },
112
+ buttons: { type: 'number', optional: true },
113
+ clickCount: { type: 'number', optional: true },
114
+ deltaX: { type: 'number', optional: true },
115
+ deltaY: { type: 'number', optional: true },
116
+ modifiers: { type: 'number', optional: true },
117
+ },
118
+ returns: {},
119
+ },
120
+ dispatchKeyboardEvent: {
121
+ type: 'command',
122
+ params: {
123
+ type: {
124
+ type: 'string',
125
+ enum: ['keydown', 'keyup', 'keypress'],
126
+ },
127
+ key: { type: 'string', optional: true },
128
+ code: { type: 'string', optional: true },
129
+ text: { type: 'string', optional: true },
130
+ modifiers: { type: 'number', optional: true },
131
+ },
132
+ returns: {},
133
+ },
134
+ getViewportSize: {
135
+ type: 'query',
136
+ params: {},
137
+ returns: {
138
+ width: { type: 'number' },
139
+ height: { type: 'number' },
140
+ },
141
+ },
142
+ setViewportSize: {
143
+ type: 'command',
144
+ params: {
145
+ width: { type: 'number' },
146
+ height: { type: 'number' },
147
+ },
148
+ returns: {},
149
+ },
150
+ },
151
+ events: {
152
+ urlChanged: {
153
+ params: {
154
+ url: { type: 'string' },
155
+ },
156
+ },
157
+ screencastFrame: {
158
+ params: {
159
+ sessionId: { type: 'number' },
160
+ data: { type: 'string' },
161
+ width: { type: 'number' },
162
+ height: { type: 'number' },
163
+ },
164
+ },
165
+ },
166
+ };
@@ -0,0 +1,30 @@
1
+ import { DomainDef } from '@nodescript/protocomm';
2
+
3
+ import { EvaluateRequest, EvaluateRequestSchema } from '../schema/EvaluateRequest.js';
4
+ import { EvaluateResponse, EvaluateResponseSchema } from '../schema/EvaluateResponse.js';
5
+
6
+ export interface EvalDomain {
7
+
8
+ evaluate(req: {
9
+ request: EvaluateRequest;
10
+ }): Promise<{
11
+ response: EvaluateResponse;
12
+ }>;
13
+
14
+ }
15
+
16
+ export const EvalDomain: DomainDef<EvalDomain> = {
17
+ name: 'Eval',
18
+ methods: {
19
+ evaluate: {
20
+ type: 'command',
21
+ params: {
22
+ request: EvaluateRequestSchema.schema,
23
+ },
24
+ returns: {
25
+ response: EvaluateResponseSchema.schema,
26
+ },
27
+ },
28
+ },
29
+ events: {},
30
+ };
@@ -0,0 +1,64 @@
1
+ import { DomainDef } from '@nodescript/protocomm';
2
+ import { Event } from 'nanoevent';
3
+
4
+ import { WorkflowMessage, WorkflowMessageSchema } from '../schema/WorkflowMessage.js';
5
+
6
+ export interface MessageDomain {
7
+
8
+ getMessages(req: {}): Promise<{
9
+ messages: WorkflowMessage[];
10
+ }>;
11
+
12
+ clearMessages(req: {}): Promise<{}>;
13
+
14
+ messageAdded: Event<{
15
+ message: WorkflowMessage;
16
+ }>;
17
+
18
+ messageUpdated: Event<{
19
+ messageId: string;
20
+ content: string;
21
+ }>;
22
+
23
+ messagesCleared: Event<{}>;
24
+
25
+ }
26
+
27
+ export const MessageDomain: DomainDef<MessageDomain> = {
28
+ name: 'Message',
29
+ methods: {
30
+ getMessages: {
31
+ type: 'query',
32
+ params: {},
33
+ returns: {
34
+ messages: {
35
+ type: 'array',
36
+ items: WorkflowMessageSchema.schema,
37
+ },
38
+ },
39
+ },
40
+ clearMessages: {
41
+ type: 'command',
42
+ params: {
43
+ workflowId: { type: 'string' },
44
+ },
45
+ returns: {},
46
+ },
47
+ },
48
+ events: {
49
+ messageAdded: {
50
+ params: {
51
+ message: WorkflowMessageSchema.schema,
52
+ },
53
+ },
54
+ messageUpdated: {
55
+ params: {
56
+ messageId: { type: 'string' },
57
+ content: { type: 'string' },
58
+ },
59
+ },
60
+ messagesCleared: {
61
+ params: {},
62
+ },
63
+ },
64
+ };
@@ -0,0 +1,75 @@
1
+ import { DomainDef } from '@nodescript/protocomm';
2
+ import { Event } from 'nanoevent';
3
+
4
+ export interface StateDomain {
5
+
6
+ getState(req: {}): Promise<{
7
+ data: Record<string, any>;
8
+ }>;
9
+
10
+ setStateData(req: {
11
+ key: string;
12
+ value: any;
13
+ }): Promise<{}>;
14
+
15
+ clearState(req: {}): Promise<{}>;
16
+
17
+ stateCleared: Event<{}>;
18
+
19
+ stateUpdated: Event<{
20
+ key: string;
21
+ value: any;
22
+ }>;
23
+
24
+ }
25
+
26
+ export const StateDomain: DomainDef<StateDomain> = {
27
+ name: 'State',
28
+ methods: {
29
+ getState: {
30
+ type: 'query',
31
+ params: {},
32
+ returns: {
33
+ data: {
34
+ type: 'object',
35
+ properties: {},
36
+ additionalProperties: {
37
+ type: 'any',
38
+ },
39
+ },
40
+ },
41
+ },
42
+ setStateData: {
43
+ type: 'command',
44
+ params: {
45
+ key: {
46
+ type: 'string',
47
+ },
48
+ value: {
49
+ type: 'any',
50
+ },
51
+ },
52
+ returns: {},
53
+ },
54
+ clearState: {
55
+ type: 'command',
56
+ params: {},
57
+ returns: {},
58
+ },
59
+ },
60
+ events: {
61
+ stateCleared: {
62
+ params: {},
63
+ },
64
+ stateUpdated: {
65
+ params: {
66
+ key: {
67
+ type: 'string',
68
+ },
69
+ value: {
70
+ type: 'any',
71
+ },
72
+ },
73
+ },
74
+ },
75
+ };
@@ -0,0 +1,13 @@
1
+ export * from './domains/BrowserDomain.js';
2
+ export * from './domains/EvalDomain.js';
3
+ export * from './domains/MessageDomain.js';
4
+ export * from './domains/StateDomain.js';
5
+ export * from './protocol.js';
6
+ export * from './schema/EvaluateRequest.js';
7
+ export * from './schema/EvaluateResponse.js';
8
+ export * from './schema/KeyboardEventRequest.js';
9
+ export * from './schema/MouseEventRequest.js';
10
+ export * from './schema/PageMetadata.js';
11
+ export * from './schema/ScreencastFrame.js';
12
+ export * from './schema/WorkflowInfo.js';
13
+ export * from './schema/WorkflowMessage.js';
@@ -0,0 +1,20 @@
1
+ import { ProtocolIndex } from '@nodescript/protocomm';
2
+
3
+ import { BrowserDomain } from './domains/BrowserDomain.js';
4
+ import { EvalDomain } from './domains/EvalDomain.js';
5
+ import { MessageDomain } from './domains/MessageDomain.js';
6
+ import { StateDomain } from './domains/StateDomain.js';
7
+
8
+ export interface RunnerProtocol {
9
+ Browser: BrowserDomain;
10
+ Eval: EvalDomain;
11
+ State: StateDomain;
12
+ Message: MessageDomain;
13
+ }
14
+
15
+ export const runnerProtocol = new ProtocolIndex<RunnerProtocol>({
16
+ Browser: BrowserDomain,
17
+ Eval: EvalDomain,
18
+ State: StateDomain,
19
+ Message: MessageDomain,
20
+ });
@@ -0,0 +1,18 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface EvaluateRequest {
4
+ code: string;
5
+ args: Record<string, unknown>;
6
+ }
7
+
8
+ export const EvaluateRequestSchema = new Schema<EvaluateRequest>({
9
+ type: 'object',
10
+ properties: {
11
+ code: { type: 'string' },
12
+ args: {
13
+ type: 'object',
14
+ properties: {},
15
+ additionalProperties: { type: 'any' },
16
+ },
17
+ },
18
+ });
@@ -0,0 +1,27 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface EvaluateResponse {
4
+ result?: unknown;
5
+ error?: {
6
+ name: string;
7
+ message: string;
8
+ };
9
+ }
10
+
11
+ export const EvaluateResponseSchema = new Schema<EvaluateResponse>({
12
+ type: 'object',
13
+ properties: {
14
+ result: {
15
+ type: 'any',
16
+ optional: true,
17
+ },
18
+ error: {
19
+ type: 'object',
20
+ properties: {
21
+ name: { type: 'string' },
22
+ message: { type: 'string' },
23
+ },
24
+ optional: true,
25
+ },
26
+ },
27
+ });
@@ -0,0 +1,23 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface KeyboardEventRequest {
4
+ type: 'keydown' | 'keyup' | 'keypress';
5
+ key?: string;
6
+ code?: string;
7
+ text?: string;
8
+ modifiers?: number;
9
+ }
10
+
11
+ export const KeyboardEventRequestSchema = new Schema<KeyboardEventRequest>({
12
+ type: 'object',
13
+ properties: {
14
+ type: {
15
+ type: 'string',
16
+ enum: ['keydown', 'keyup', 'keypress'],
17
+ },
18
+ key: { type: 'string', optional: true },
19
+ code: { type: 'string', optional: true },
20
+ text: { type: 'string', optional: true },
21
+ modifiers: { type: 'number', optional: true },
22
+ },
23
+ });
@@ -0,0 +1,35 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface MouseEventRequest {
4
+ type: 'mousedown' | 'mouseup' | 'mousemove' | 'wheel';
5
+ x: number;
6
+ y: number;
7
+ button?: 'left' | 'right' | 'middle';
8
+ buttons?: number;
9
+ clickCount?: number;
10
+ deltaX?: number;
11
+ deltaY?: number;
12
+ modifiers?: number;
13
+ }
14
+
15
+ export const MouseEventRequestSchema = new Schema<MouseEventRequest>({
16
+ type: 'object',
17
+ properties: {
18
+ type: {
19
+ type: 'string',
20
+ enum: ['mousedown', 'mouseup', 'mousemove', 'wheel'],
21
+ },
22
+ x: { type: 'number' },
23
+ y: { type: 'number' },
24
+ button: {
25
+ type: 'string',
26
+ enum: ['left', 'right', 'middle'],
27
+ optional: true,
28
+ },
29
+ buttons: { type: 'number', optional: true },
30
+ clickCount: { type: 'number', optional: true },
31
+ deltaX: { type: 'number', optional: true },
32
+ deltaY: { type: 'number', optional: true },
33
+ modifiers: { type: 'number', optional: true },
34
+ },
35
+ });
@@ -0,0 +1,22 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface PageMetadata {
4
+ id: string;
5
+ title: string;
6
+ type: 'page' | 'iframe';
7
+ url: string;
8
+ devtoolsFrontendUrl: string;
9
+ webSocketDebuggerUrl: string;
10
+ }
11
+
12
+ export const PageMetadataSchema = new Schema<PageMetadata>({
13
+ type: 'object',
14
+ properties: {
15
+ id: { type: 'string' },
16
+ title: { type: 'string' },
17
+ type: { type: 'string', enum: ['page', 'iframe'] },
18
+ url: { type: 'string' },
19
+ devtoolsFrontendUrl: { type: 'string' },
20
+ webSocketDebuggerUrl: { type: 'string' },
21
+ },
22
+ });
@@ -0,0 +1,18 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface ScreencastFrame {
4
+ sessionId: number;
5
+ data: string;
6
+ width: number;
7
+ height: number;
8
+ }
9
+
10
+ export const ScreencastFrameSchema = new Schema<ScreencastFrame>({
11
+ type: 'object',
12
+ properties: {
13
+ sessionId: { type: 'number' },
14
+ data: { type: 'string' },
15
+ width: { type: 'number' },
16
+ height: { type: 'number' },
17
+ },
18
+ });
@@ -0,0 +1,16 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface WorkflowInfo {
4
+ workflowId: string;
5
+ title: string;
6
+ description?: string;
7
+ }
8
+
9
+ export const WorkflowInfoSchema = new Schema<WorkflowInfo>({
10
+ type: 'object',
11
+ properties: {
12
+ workflowId: { type: 'string' },
13
+ title: { type: 'string' },
14
+ description: { type: 'string', optional: true },
15
+ },
16
+ });
@@ -0,0 +1,24 @@
1
+ import { Schema } from 'airtight';
2
+
3
+ export interface WorkflowMessage {
4
+ messageId?: string;
5
+ title?: string;
6
+ icon?: string;
7
+ content: string;
8
+ data?: any;
9
+ code?: string;
10
+ timestamp?: number;
11
+ }
12
+
13
+ export const WorkflowMessageSchema = new Schema<WorkflowMessage>({
14
+ type: 'object',
15
+ properties: {
16
+ messageId: { type: 'string', optional: true },
17
+ title: { type: 'string', optional: true },
18
+ icon: { type: 'string', optional: true },
19
+ content: { type: 'string' },
20
+ data: { type: 'any', optional: true },
21
+ code: { type: 'string', optional: true },
22
+ timestamp: { type: 'number', optional: true },
23
+ },
24
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./out",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src"]
8
+ }