Skip to content

Commit 55ffe15

Browse files
committed
Refactor: Generalize Property Access to InstanceService (#8324)
1 parent b6833f6 commit 55ffe15

6 files changed

Lines changed: 141 additions & 47 deletions

File tree

ai/mcp/server/neural-link/openapi.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,23 @@ paths:
9797
tree:
9898
type: object
9999

100-
/get_component_property:
100+
/instance/property/get:
101101
post:
102-
summary: Get Component Property
103-
operationId: get_component_property
102+
summary: Get Instance Property
103+
operationId: get_instance_property
104104
x-pass-as-object: true
105105
description: |
106-
Retrieves a property from a component by its ID.
106+
Retrieves a property from a specific instance by its ID.
107107
108108
**When to Use:**
109-
To inspect the current state of a component (e.g., `width`, `store`, `value`).
110-
tags: [Component]
109+
To inspect the current state of any Neo instance (e.g., Component, Store, Controller, Manager).
110+
tags: [Instance]
111111
requestBody:
112112
required: true
113113
content:
114114
application/json:
115115
schema:
116-
$ref: '#/components/schemas/GetComponentPropertyRequest'
116+
$ref: '#/components/schemas/GetInstancePropertyRequest'
117117
responses:
118118
'200':
119119
description: The value of the property
@@ -892,23 +892,23 @@ paths:
892892
chrome:
893893
type: object
894894

895-
/component/property/set:
895+
/instance/property/set:
896896
post:
897-
summary: Set Component Property
898-
operationId: set_component_property
897+
summary: Set Instance Property
898+
operationId: set_instance_property
899899
x-pass-as-object: true
900900
description: |
901-
Sets a property on a component by its ID.
901+
Sets a property on a specific instance by its ID.
902902
903903
**When to Use:**
904-
To modify the runtime state of a component (e.g., change text, toggle visibility).
905-
tags: [Component]
904+
To modify the runtime state of an instance (e.g., change component text, update store filter).
905+
tags: [Instance]
906906
requestBody:
907907
required: true
908908
content:
909909
application/json:
910910
schema:
911-
$ref: '#/components/schemas/SetComponentPropertyRequest'
911+
$ref: '#/components/schemas/SetInstancePropertyRequest'
912912
responses:
913913
'200':
914914
description: Property set successfully
@@ -1208,15 +1208,15 @@ components:
12081208
uptime:
12091209
type: number
12101210

1211-
GetComponentPropertyRequest:
1211+
GetInstancePropertyRequest:
12121212
type: object
12131213
required:
12141214
- id
12151215
- property
12161216
properties:
12171217
id:
12181218
type: string
1219-
description: The component ID
1219+
description: The instance ID
12201220
property:
12211221
type: string
12221222
description: The property name to retrieve
@@ -1349,7 +1349,7 @@ components:
13491349
type: string
13501350
description: The target App Worker Session ID
13511351

1352-
SetComponentPropertyRequest:
1352+
SetInstancePropertyRequest:
13531353
type: object
13541354
required:
13551355
- id
@@ -1358,7 +1358,7 @@ components:
13581358
properties:
13591359
id:
13601360
type: string
1361-
description: The component ID
1361+
description: The instance ID
13621362
property:
13631363
type: string
13641364
description: The property name to set
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import Base from '../../../../../src/core/Base.mjs';
2+
import ConnectionService from './ConnectionService.mjs';
3+
4+
/**
5+
* @summary Manages generic instance inspection and manipulation for the Neural Link MCP Server.
6+
*
7+
* This service provides tools for reading and writing properties of any registered Neo instance
8+
* (e.g. Components, Stores, Managers, Controllers).
9+
*
10+
* @class Neo.ai.mcp.server.neural-link.services.InstanceService
11+
* @extends Neo.core.Base
12+
* @singleton
13+
*/
14+
class InstanceService extends Base {
15+
static config = {
16+
/**
17+
* @member {String} className='Neo.ai.mcp.server.neural-link.services.InstanceService'
18+
* @protected
19+
*/
20+
className: 'Neo.ai.mcp.server.neural-link.services.InstanceService',
21+
/**
22+
* @member {Boolean} singleton=true
23+
* @protected
24+
*/
25+
singleton: true
26+
}
27+
28+
/**
29+
* Retrieves a property from a specific instance by its ID.
30+
* @param {Object} opts
31+
* @param {String} opts.sessionId
32+
* @param {String} opts.id
33+
* @param {String} opts.property
34+
* @returns {Promise<Object>}
35+
*/
36+
async getInstanceProperty({sessionId, id, property}) {
37+
return await ConnectionService.call(sessionId, 'get_instance_property', {
38+
id,
39+
property
40+
})
41+
}
42+
43+
/**
44+
* Sets a property on a specific instance by its ID.
45+
* @param {Object} opts
46+
* @param {String} opts.sessionId
47+
* @param {String} opts.id
48+
* @param {String} opts.property
49+
* @param {*} opts.value
50+
* @returns {Promise<Object>}
51+
*/
52+
async setInstanceProperty({sessionId, id, property, value}) {
53+
return await ConnectionService.call(sessionId, 'set_instance_property', {
54+
id,
55+
property,
56+
value
57+
})
58+
}
59+
}
60+
61+
export default Neo.setupClass(InstanceService);

ai/mcp/server/neural-link/services/toolService.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import ComponentService from './ComponentService.mjs';
55
import ConnectionService from './ConnectionService.mjs';
66
import DataService from './DataService.mjs';
77
import HealthService from './HealthService.mjs';
8+
import InstanceService from './InstanceService.mjs';
89
import InteractionService from './InteractionService.mjs';
910
import RuntimeService from './RuntimeService.mjs';
1011

@@ -14,14 +15,14 @@ const openApiFilePath = path.join(__dirname, '../openapi.yaml');
1415

1516
const serviceMapping = {
1617
check_namespace : RuntimeService .checkNamespace .bind(RuntimeService),
17-
get_component_property : ComponentService .getComponentProperty .bind(ComponentService),
1818
get_component_tree : ComponentService .getComponentTree .bind(ComponentService),
1919
get_computed_styles : ComponentService .getComputedStyles .bind(ComponentService),
2020
get_console_logs : ConnectionService .getConsoleLogs .bind(ConnectionService),
2121
get_dom_event_listeners : RuntimeService .getDomEventListeners .bind(RuntimeService),
2222
get_dom_event_summary : RuntimeService .getDomEventSummary .bind(RuntimeService),
2323
get_dom_rect : ComponentService .getDomRect .bind(ComponentService),
2424
get_drag_state : InteractionService.getDragState .bind(InteractionService),
25+
get_instance_property : InstanceService .getInstanceProperty .bind(InstanceService),
2526
get_method_source : RuntimeService .getMethodSource .bind(RuntimeService),
2627
get_namespace_tree : RuntimeService .getNamespaceTree .bind(RuntimeService),
2728
get_record : DataService .getRecord .bind(DataService),
@@ -41,7 +42,7 @@ const serviceMapping = {
4142
patch_code : RuntimeService .patchCode .bind(RuntimeService),
4243
query_component : ComponentService .queryComponent .bind(ComponentService),
4344
reload_page : RuntimeService .reloadPage .bind(RuntimeService),
44-
set_component_property : ComponentService .setComponentProperty .bind(ComponentService),
45+
set_instance_property : InstanceService .setInstanceProperty .bind(InstanceService),
4546
set_route : RuntimeService .setRoute .bind(RuntimeService),
4647
simulate_event : InteractionService.simulateEvent .bind(InteractionService)
4748
};

src/ai/Client.mjs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Base from '../core/Base.mjs';
22
import ClassSystemUtil from '../util/ClassSystem.mjs';
33
import ComponentService from './client/ComponentService.mjs';
44
import DataService from './client/DataService.mjs';
5+
import InstanceService from './client/InstanceService.mjs';
56
import InteractionService from './client/InteractionService.mjs';
67
import RuntimeService from './client/RuntimeService.mjs';
78
import Socket from '../data/connection/WebSocket.mjs';
@@ -78,11 +79,12 @@ class Client extends Base {
7879
me.services = {
7980
component : Neo.create(ComponentService, {client: me}),
8081
data : Neo.create(DataService, {client: me}),
82+
instance : Neo.create(InstanceService, {client: me}),
8183
interaction: Neo.create(InteractionService, {client: me}),
8284
runtime : Neo.create(RuntimeService, {client: me})
8385
};
8486

85-
const {component, data, interaction, runtime} = me.services;
87+
const {component, data, instance, interaction, runtime} = me.services;
8688

8789
me.serviceMap = {
8890
get_component : component,
@@ -95,6 +97,9 @@ class Client extends Base {
9597
query_component : component,
9698
set_component : component,
9799

100+
get_instance : instance,
101+
set_instance : instance,
102+
98103
get_record : data,
99104
inspect_state_provider: data,
100105
inspect_store : data,

src/ai/client/ComponentService.mjs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,6 @@ class ComponentService extends Service {
1515
className: 'Neo.ai.client.ComponentService'
1616
}
1717

18-
/**
19-
* @param {Object} params
20-
* @param {String} params.id
21-
* @param {String} params.property
22-
* @returns {Object}
23-
*/
24-
getComponentProperty({id, property}) {
25-
const component = Neo.getComponent(id);
26-
if (!component) throw new Error(`Component not found: ${id}`);
27-
return {value: this.safeSerialize(component[property])};
28-
}
29-
3018
/**
3119
* @param {Object} params
3220
* @param {String} params.componentId
@@ -188,20 +176,6 @@ class ComponentService extends Service {
188176
}
189177
}
190178

191-
/**
192-
* @param {Object} params
193-
* @param {String} params.id
194-
* @param {String} params.property
195-
* @param {*} params.value
196-
* @returns {Object}
197-
*/
198-
setComponentProperty({id, property, value}) {
199-
const component = Neo.getComponent(id);
200-
if (!component) throw new Error(`Component not found: ${id}`);
201-
component[property] = value;
202-
return {success: true}
203-
}
204-
205179
/**
206180
* @param {String} [rootId]
207181
* @returns {Neo.component.Base|null}

src/ai/client/InstanceService.mjs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import Service from './Service.mjs';
2+
3+
/**
4+
* Handles generic instance-related Neural Link requests.
5+
* @class Neo.ai.client.InstanceService
6+
* @extends Neo.ai.client.Service
7+
*/
8+
class InstanceService extends Service {
9+
static config = {
10+
/**
11+
* @member {String} className='Neo.ai.client.InstanceService'
12+
* @protected
13+
*/
14+
className: 'Neo.ai.client.InstanceService'
15+
}
16+
17+
/**
18+
* @param {Object} params
19+
* @param {String} params.id
20+
* @param {String} params.property
21+
* @returns {Object}
22+
*/
23+
getInstanceProperty({id, property}) {
24+
const instance = Neo.get(id);
25+
26+
if (!instance) {
27+
throw new Error(`Instance not found: ${id}`)
28+
}
29+
30+
return {value: this.safeSerialize(instance[property])}
31+
}
32+
33+
/**
34+
* @param {Object} params
35+
* @param {String} params.id
36+
* @param {String} params.property
37+
* @param {*} params.value
38+
* @returns {Object}
39+
*/
40+
setInstanceProperty({id, property, value}) {
41+
const instance = Neo.get(id);
42+
43+
if (!instance) {
44+
throw new Error(`Instance not found: ${id}`)
45+
}
46+
47+
instance[property] = value;
48+
49+
return {success: true}
50+
}
51+
}
52+
53+
export default Neo.setupClass(InstanceService);

0 commit comments

Comments
 (0)