Skip to content

Commit 224fcc7

Browse files
committed
Enhance: Instance Tools Batch Operations (#8325)
1 parent 55ffe15 commit 224fcc7

5 files changed

Lines changed: 54 additions & 50 deletions

File tree

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

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

100-
/instance/property/get:
100+
/instance/properties/get:
101101
post:
102-
summary: Get Instance Property
103-
operationId: get_instance_property
102+
summary: Get Instance Properties
103+
operationId: get_instance_properties
104104
x-pass-as-object: true
105105
description: |
106-
Retrieves a property from a specific instance by its ID.
106+
Retrieves properties from a specific instance by its ID.
107107
108108
**When to Use:**
109109
To inspect the current state of any Neo instance (e.g., Component, Store, Controller, Manager).
@@ -113,14 +113,14 @@ paths:
113113
content:
114114
application/json:
115115
schema:
116-
$ref: '#/components/schemas/GetInstancePropertyRequest'
116+
$ref: '#/components/schemas/GetInstancePropertiesRequest'
117117
responses:
118118
'200':
119-
description: The value of the property
119+
description: The values of the properties
120120
content:
121121
application/json:
122122
schema:
123-
description: The property value
123+
description: The property values
124124
'400':
125125
description: Invalid request body
126126
content:
@@ -892,13 +892,13 @@ paths:
892892
chrome:
893893
type: object
894894

895-
/instance/property/set:
895+
/instance/properties/set:
896896
post:
897-
summary: Set Instance Property
898-
operationId: set_instance_property
897+
summary: Set Instance Properties
898+
operationId: set_instance_properties
899899
x-pass-as-object: true
900900
description: |
901-
Sets a property on a specific instance by its ID.
901+
Sets properties on a specific instance by its ID.
902902
903903
**When to Use:**
904904
To modify the runtime state of an instance (e.g., change component text, update store filter).
@@ -908,10 +908,10 @@ paths:
908908
content:
909909
application/json:
910910
schema:
911-
$ref: '#/components/schemas/SetInstancePropertyRequest'
911+
$ref: '#/components/schemas/SetInstancePropertiesRequest'
912912
responses:
913913
'200':
914-
description: Property set successfully
914+
description: Properties set successfully
915915
'400':
916916
description: Invalid request body
917917
content:
@@ -1208,18 +1208,20 @@ components:
12081208
uptime:
12091209
type: number
12101210

1211-
GetInstancePropertyRequest:
1211+
GetInstancePropertiesRequest:
12121212
type: object
12131213
required:
12141214
- id
1215-
- property
1215+
- properties
12161216
properties:
12171217
id:
12181218
type: string
12191219
description: The instance ID
1220-
property:
1221-
type: string
1222-
description: The property name to retrieve
1220+
properties:
1221+
type: array
1222+
items:
1223+
type: string
1224+
description: List of property names to retrieve
12231225
sessionId:
12241226
type: string
12251227
description: The target App Worker Session ID
@@ -1349,21 +1351,18 @@ components:
13491351
type: string
13501352
description: The target App Worker Session ID
13511353

1352-
SetInstancePropertyRequest:
1354+
SetInstancePropertiesRequest:
13531355
type: object
13541356
required:
13551357
- id
1356-
- property
1357-
- value
1358+
- properties
13581359
properties:
13591360
id:
13601361
type: string
13611362
description: The instance ID
1362-
property:
1363-
type: string
1364-
description: The property name to set
1365-
value:
1366-
description: The value to set
1363+
properties:
1364+
type: object
1365+
description: Key-value pairs of properties to set
13671366
sessionId:
13681367
type: string
13691368
description: The target App Worker Session ID

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,32 @@ class InstanceService extends Base {
2626
}
2727

2828
/**
29-
* Retrieves a property from a specific instance by its ID.
29+
* Retrieves properties from a specific instance by its ID.
3030
* @param {Object} opts
3131
* @param {String} opts.sessionId
3232
* @param {String} opts.id
33-
* @param {String} opts.property
33+
* @param {String[]} opts.properties
3434
* @returns {Promise<Object>}
3535
*/
36-
async getInstanceProperty({sessionId, id, property}) {
37-
return await ConnectionService.call(sessionId, 'get_instance_property', {
36+
async getInstanceProperties({sessionId, id, properties}) {
37+
return await ConnectionService.call(sessionId, 'get_instance_properties', {
3838
id,
39-
property
39+
properties
4040
})
4141
}
4242

4343
/**
44-
* Sets a property on a specific instance by its ID.
44+
* Sets properties on a specific instance by its ID.
4545
* @param {Object} opts
4646
* @param {String} opts.sessionId
4747
* @param {String} opts.id
48-
* @param {String} opts.property
49-
* @param {*} opts.value
48+
* @param {Object} opts.properties
5049
* @returns {Promise<Object>}
5150
*/
52-
async setInstanceProperty({sessionId, id, property, value}) {
53-
return await ConnectionService.call(sessionId, 'set_instance_property', {
51+
async setInstanceProperties({sessionId, id, properties}) {
52+
return await ConnectionService.call(sessionId, 'set_instance_properties', {
5453
id,
55-
property,
56-
value
54+
properties
5755
})
5856
}
5957
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const serviceMapping = {
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),
25+
get_instance_properties : InstanceService .getInstanceProperties .bind(InstanceService),
2626
get_method_source : RuntimeService .getMethodSource .bind(RuntimeService),
2727
get_namespace_tree : RuntimeService .getNamespaceTree .bind(RuntimeService),
2828
get_record : DataService .getRecord .bind(DataService),
@@ -42,7 +42,7 @@ const serviceMapping = {
4242
patch_code : RuntimeService .patchCode .bind(RuntimeService),
4343
query_component : ComponentService .queryComponent .bind(ComponentService),
4444
reload_page : RuntimeService .reloadPage .bind(RuntimeService),
45-
set_instance_property : InstanceService .setInstanceProperty .bind(InstanceService),
45+
set_instance_properties : InstanceService .setInstanceProperties .bind(InstanceService),
4646
set_route : RuntimeService .setRoute .bind(RuntimeService),
4747
simulate_event : InteractionService.simulateEvent .bind(InteractionService)
4848
};

src/ai/Client.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ class Client extends Base {
9797
query_component : component,
9898
set_component : component,
9999

100-
get_instance : instance,
101-
set_instance : instance,
100+
get_instance_properties: instance,
101+
set_instance_properties: instance,
102102

103103
get_record : data,
104104
inspect_state_provider: data,

src/ai/client/InstanceService.mjs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,43 @@ class InstanceService extends Service {
1515
}
1616

1717
/**
18+
* Retrieves properties from a specific instance by its ID.
1819
* @param {Object} params
1920
* @param {String} params.id
20-
* @param {String} params.property
21+
* @param {String[]} params.properties
2122
* @returns {Object}
2223
*/
23-
getInstanceProperty({id, property}) {
24-
const instance = Neo.get(id);
24+
getInstanceProperties({id, properties}) {
25+
const
26+
instance = Neo.get(id),
27+
result = {};
2528

2629
if (!instance) {
2730
throw new Error(`Instance not found: ${id}`)
2831
}
2932

30-
return {value: this.safeSerialize(instance[property])}
33+
properties.forEach(property => {
34+
result[property] = this.safeSerialize(instance[property])
35+
});
36+
37+
return {properties: result}
3138
}
3239

3340
/**
41+
* Sets properties on a specific instance by its ID.
3442
* @param {Object} params
3543
* @param {String} params.id
36-
* @param {String} params.property
37-
* @param {*} params.value
44+
* @param {Object} params.properties
3845
* @returns {Object}
3946
*/
40-
setInstanceProperty({id, property, value}) {
47+
setInstanceProperties({id, properties}) {
4148
const instance = Neo.get(id);
4249

4350
if (!instance) {
4451
throw new Error(`Instance not found: ${id}`)
4552
}
4653

47-
instance[property] = value;
54+
instance.set(properties);
4855

4956
return {success: true}
5057
}

0 commit comments

Comments
 (0)