Skip to content

Commit 29b64a0

Browse files
committed
modify openRPC specs to autogen comms ccode and fix bug with passing
'path' parameter, also rename summarizeData function to make it more generic
1 parent 5567433 commit 29b64a0

File tree

10 files changed

+172
-61
lines changed

10 files changed

+172
-61
lines changed

extensions/positron-assistant/src/tools.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,10 @@ export function registerAssistantTools(
321321
}
322322

323323
// Call the Positron API to get the session variable data summaries
324-
const result = await positron.runtime.getSessionVariableDataSummaries(
324+
const result = await positron.runtime.querySessionVariable(
325325
options.input.sessionIdentifier,
326-
options.input.accessKeys);
326+
options.input.accessKeys,
327+
['summary_stats']);
327328

328329
// Return the result as a JSON string to the model
329330
return new vscode.LanguageModelToolResult([

extensions/positron-python/python_files/posit/positron/variables.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
InspectedVariable,
3131
InspectRequest,
3232
ListRequest,
33+
QueryVariableDataRequest,
3334
RefreshParams,
34-
SummarizeDataRequest,
3535
UpdateParams,
3636
Variable,
3737
VariableKind,
@@ -138,9 +138,8 @@ def handle_msg(
138138
elif isinstance(request, ViewRequest):
139139
self._perform_view_action(request.params.path)
140140

141-
elif isinstance(request, SummarizeDataRequest):
142-
for path in request.params.paths:
143-
self._perform_get_variable_summary(path)
141+
elif isinstance(request, QueryVariableDataRequest):
142+
self._perform_get_variable_summary(request.params.path)
144143

145144
else:
146145
logger.warning(f"Unhandled request: {request}")
@@ -727,8 +726,8 @@ def _summarize_data(self, path: list[str]):
727726
from .data_explorer import DataExplorerState, _get_table_view, _value_type_is_supported
728727
from .data_explorer_comm import FormatOptions
729728

730-
is_found, value = self._find_var(path)
731-
if not is_found:
729+
is_known, value = self._find_var(path)
730+
if not is_known:
732731
raise ValueError(f"Cannot find variable at '{path}' to summarize")
733732

734733
if not _value_type_is_supported(value):

extensions/positron-python/python_files/posit/positron/variables_comm.py

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ class FormattedVariable(BaseModel):
105105
)
106106

107107

108+
class SummarizedData(BaseModel):
109+
"""
110+
Result of the summarize operation
111+
"""
112+
113+
children: List[Variable] = Field(
114+
description="An array of summarized variables, each containing a summary of the data.",
115+
)
116+
117+
length: StrictInt = Field(
118+
description="The total number of summarized variables. This may be greater than the number of variables in the 'children' array if the array is truncated.",
119+
)
120+
121+
108122
class Variable(BaseModel):
109123
"""
110124
A single variable in the runtime.
@@ -183,8 +197,8 @@ class VariablesBackendRequest(str, enum.Enum):
183197
# Request a viewer for a variable
184198
View = "view"
185199

186-
# Summarize data
187-
SummarizeData = "summarize_data"
200+
# Query variable data
201+
QueryVariableData = "query_variable_data"
188202

189203

190204
class ListRequest(BaseModel):
@@ -355,6 +369,39 @@ class ViewRequest(BaseModel):
355369
)
356370

357371

372+
class QueryVariableDataParams(BaseModel):
373+
"""
374+
Request a data summary for a variable or variables.
375+
"""
376+
377+
path: List[StrictStr] = Field(
378+
description="The path to the variable to inspect, as an array of access keys.",
379+
)
380+
381+
query_types: List[StrictStr] = Field(
382+
description="A list of types to summarize.",
383+
)
384+
385+
386+
class QueryVariableDataRequest(BaseModel):
387+
"""
388+
Request a data summary for a variable or variables.
389+
"""
390+
391+
params: QueryVariableDataParams = Field(
392+
description="Parameters to the QueryVariableData method",
393+
)
394+
395+
method: Literal[VariablesBackendRequest.QueryVariableData] = Field(
396+
description="The JSON-RPC method name (query_variable_data)",
397+
)
398+
399+
jsonrpc: str = Field(
400+
default="2.0",
401+
description="The JSON-RPC version specifier",
402+
)
403+
404+
358405
class VariablesBackendMessageContent(BaseModel):
359406
comm_id: str
360407
data: Union[
@@ -364,7 +411,7 @@ class VariablesBackendMessageContent(BaseModel):
364411
InspectRequest,
365412
ClipboardFormatRequest,
366413
ViewRequest,
367-
SummarizeDataRequest,
414+
QueryVariableDataRequest,
368415
] = Field(..., discriminator="method")
369416

370417

@@ -421,37 +468,14 @@ class RefreshParams(BaseModel):
421468
)
422469

423470

424-
class SummarizeDataParams(BaseModel):
425-
paths: List[List[StrictStr]] = Field(
426-
description="Array of paths to variables to summarize, each path is an array of access keys.",
427-
)
428-
429-
430-
class SummarizeDataRequest(BaseModel):
431-
"""
432-
Request that the runtime summarize data in a variable.
433-
"""
434-
435-
params: SummarizeDataParams = Field(
436-
description="Parameters to the SummarizeData method",
437-
)
438-
439-
method: Literal[VariablesBackendRequest.SummarizeData] = Field(
440-
description="The JSON-RPC method name (summarize_data)",
441-
)
442-
443-
jsonrpc: str = Field(
444-
default="2.0",
445-
description="The JSON-RPC version specifier",
446-
)
447-
448-
449471
VariableList.update_forward_refs()
450472

451473
InspectedVariable.update_forward_refs()
452474

453475
FormattedVariable.update_forward_refs()
454476

477+
SummarizedData.update_forward_refs()
478+
455479
Variable.update_forward_refs()
456480

457481
ListRequest.update_forward_refs()
@@ -476,12 +500,10 @@ class SummarizeDataRequest(BaseModel):
476500

477501
ViewRequest.update_forward_refs()
478502

479-
UpdateParams.update_forward_refs()
480-
481-
RefreshParams.update_forward_refs()
503+
QueryVariableDataParams.update_forward_refs()
482504

483-
SummarizeDataParams.update_forward_refs()
505+
QueryVariableDataRequest.update_forward_refs()
484506

485-
SummarizeDataRequest.update_forward_refs()
507+
UpdateParams.update_forward_refs()
486508

487-
VariablesBackendMessageContent.update_forward_refs()
509+
RefreshParams.update_forward_refs()

positron/comms/variables-backend-openrpc.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,57 @@
188188
"type": "string"
189189
}
190190
}
191+
},
192+
{
193+
"name": "query_variable_data",
194+
"summary": "Query variable data",
195+
"description": "Request a data summary for a variable or variables.",
196+
"params": [
197+
{
198+
"name": "path",
199+
"description": "The path to the variable to inspect, as an array of access keys.",
200+
"schema": {
201+
"type": "array",
202+
"items": {
203+
"type": "string"
204+
}
205+
}
206+
},
207+
{
208+
"name": "query_types",
209+
"description": "A list of types to summarize.",
210+
"schema": {
211+
"type": "array",
212+
"items": {
213+
"type": "string"
214+
}
215+
}
216+
}
217+
],
218+
"result": {
219+
"schema": {
220+
"name": "summarized_data",
221+
"description": "Result of the summarize operation",
222+
"type": "object",
223+
"properties": {
224+
"children": {
225+
"type": "array",
226+
"description": "An array of summarized variables, each containing a summary of the data.",
227+
"items": {
228+
"$ref": "#/components/schemas/variable"
229+
}
230+
},
231+
"length": {
232+
"type": "integer",
233+
"description": "The total number of summarized variables. This may be greater than the number of variables in the 'children' array if the array is truncated."
234+
}
235+
},
236+
"required": [
237+
"children",
238+
"length"
239+
]
240+
}
241+
}
191242
}
192243
],
193244
"components": {

src/positron-dts/positron.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1788,9 +1788,10 @@ declare module 'positron' {
17881788
accessKeys?: Array<Array<string>>):
17891789
Thenable<Array<Array<RuntimeVariable>>>;
17901790

1791-
export function getSessionVariableDataSummaries(
1791+
export function querySessionVariable(
17921792
sessionId: string,
1793-
accessKeys: Array<Array<string>>):
1793+
accessKeys: Array<Array<string>>,
1794+
queryTypes: Array<string>):
17941795
Thenable<Array<string>>;
17951796

17961797
/**

src/vs/workbench/api/browser/positron/mainThreadLanguageRuntime.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,18 +1583,19 @@ export class MainThreadLanguageRuntime
15831583
}
15841584
}
15851585

1586-
$getSessionVariableDataSummaries(handle: number, accessKeys: Array<Array<string>>): Promise<Array<string>> {
1586+
$querySessionVariable(handle: number, accessKeys: Array<Array<string>>, queryTypes: Array<string>): Promise<Array<string>> {
15871587
const sessionId = this.findSession(handle).sessionId;
15881588
const instances = this._positronVariablesService.positronVariablesInstances;
15891589
for (const instance of instances) {
15901590
if (instance.session.sessionId === sessionId) {
1591-
return this.getSessionVariableDataSummaries(instance, accessKeys);
1591+
return this.querySessionVariable(instance, accessKeys, queryTypes);
15921592
}
15931593
}
15941594
throw new Error(`No variables provider found for session ${sessionId}`);
15951595
}
15961596

1597-
async getSessionVariableDataSummaries(instance: IPositronVariablesInstance, accessKeys: Array<Array<string>>): Promise<Array<string>> {
1597+
async querySessionVariable(instance: IPositronVariablesInstance, accessKeys: Array<Array<string>>, queryTypes: Array<string>):
1598+
Promise<Array<string>> {
15981599
const client = instance.getClientInstance();
15991600
if (!client) {
16001601
throw new Error(`No variables provider available for session ${instance.session.sessionId}`);
@@ -1604,7 +1605,7 @@ export class MainThreadLanguageRuntime
16041605
}
16051606
const result = [];
16061607
for (const accessKey of accessKeys) {
1607-
result.push((await client.comm.summarizeData(accessKey)));
1608+
result.push(JSON.stringify(await client.comm.queryVariableData(accessKey, queryTypes)));
16081609
}
16091610
return result;
16101611
}

src/vs/workbench/api/common/positron/extHost.positron.api.impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ export function createPositronApiFactoryAndRegisterActors(accessor: ServicesAcce
141141
Thenable<Array<Array<positron.RuntimeVariable>>> {
142142
return extHostLanguageRuntime.getSessionVariables(sessionId, accessKeys);
143143
},
144-
getSessionVariableDataSummaries(sessionId: string, accessKeys: Array<Array<string>>):
144+
querySessionVariable(sessionId: string, accessKeys: Array<Array<string>>, queryTypes: Array<string>):
145145
Thenable<Array<string>> {
146-
return extHostLanguageRuntime.getSessionVariableDataSummaries(sessionId, accessKeys);
146+
return extHostLanguageRuntime.querySessionVariable(sessionId, accessKeys, queryTypes);
147147
},
148148
registerClientHandler(handler: positron.RuntimeClientHandler): vscode.Disposable {
149149
return extHostLanguageRuntime.registerClientHandler(handler);

src/vs/workbench/api/common/positron/extHost.positron.protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface MainThreadLanguageRuntimeShape extends IDisposable {
5353
$interruptSession(handle: number): Promise<void>;
5454
$focusSession(handle: number): void;
5555
$getSessionVariables(handle: number, accessKeys?: Array<Array<string>>): Promise<Array<Array<Variable>>>;
56-
$getSessionVariableDataSummaries(handle: number, accessKeys: Array<Array<string>>): Promise<Array<string>>;
56+
$querySessionVariable(handle: number, accessKeys: Array<Array<string>>, queryTypes: Array<string>): Promise<Array<string>>;
5757
$emitLanguageRuntimeMessage(handle: number, handled: boolean, message: SerializableObjectWithBuffers<ILanguageRuntimeMessage>): void;
5858
$emitLanguageRuntimeState(handle: number, clock: number, state: RuntimeState): void;
5959
$emitLanguageRuntimeExit(handle: number, exit: ILanguageRuntimeExit): void;

src/vs/workbench/api/common/positron/extHostLanguageRuntime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,11 +1224,11 @@ export class ExtHostLanguageRuntime implements extHostProtocol.ExtHostLanguageRu
12241224
throw new Error(`Session with ID '${sessionId}' not found`);
12251225
}
12261226

1227-
public getSessionVariableDataSummaries(sessionId: string, accessKeys: Array<Array<string>>):
1227+
public querySessionVariable(sessionId: string, accessKeys: Array<Array<string>>, queryTypes: Array<string>):
12281228
Promise<Array<string>> {
12291229
for (let i = 0; i < this._runtimeSessions.length; i++) {
12301230
if (this._runtimeSessions[i].metadata.sessionId === sessionId) {
1231-
return this._proxy.$getSessionVariableDataSummaries(i, accessKeys);
1231+
return this._proxy.$querySessionVariable(i, accessKeys, queryTypes);
12321232
}
12331233
}
12341234
throw new Error(`Session with ID '${sessionId}' not found`);

0 commit comments

Comments
 (0)