Skip to content

Commit 6478f54

Browse files
authored
chore(js/core): Tweak the DAP action Dev UI display (#3941)
1 parent 7b40538 commit 6478f54

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

js/core/src/dynamic-action-provider.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ class SimpleCache {
6767

6868
if (!params?.skipTrace) {
6969
// Also run the action
70-
// This returns metadata and shows up in dev UI
70+
// This action actually does nothing, with the important side
71+
// effect of logging its input and output (which are the same).
7172
// It does not change what we return, it just makes
72-
// the content of the DAP visible in the trace.
73-
await this.dap.run(this.value);
73+
// the content of the DAP visible in the DevUI and logging trace.
74+
await this.dap.run(transformDapValue(this.value));
7475
}
7576
return this.value;
7677
} catch (error) {
@@ -170,12 +171,16 @@ export function defineDynamicActionProvider(
170171
metadata: { ...(cfg.metadata || {}), type: 'dynamic-action-provider' },
171172
},
172173
async (i, _options) => {
173-
// The actions are retrieved and saved in a cache and then passed in here.
174-
// We run this action to return the metadata for the actions only.
175-
// We pass the actions in here to prevent duplicate calls to the mcp
176-
// and also so we are guaranteed the same actions since there is only a
177-
// single call to mcp client/host.
178-
return transformDapValue(i);
174+
// The actions are retrieved, saved in a cache, formatted nicely and
175+
// then passed in here so they can be automatically logged by the action
176+
// call. This action is for logging only. We cannot run the actual
177+
// 'getting the data from the DAP' here because the DAP data is required
178+
// to resolve tools/resources etc. And there can be a LOT of tools etc.
179+
// for a single generate. Which would log one DAP action per resolve,
180+
// and unnecessarily overwhelm the Dev UI with DAP actions that all have
181+
// the same information. So we only run this action (for the logging) when
182+
// we go get new data from the DAP (so we can see what it returned).
183+
return i;
179184
}
180185
);
181186
implementDap(a as DynamicActionProviderAction, cfg, fn);

js/core/tests/dynamic-action-provider_test.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,23 @@ describe('dynamic action provider', () => {
230230
assert.strictEqual(callCount, 2);
231231
});
232232

233-
it('returns metadata when run', async () => {
233+
it('runs the action with transformed metadata when fetching', async () => {
234234
const dap = defineDynamicActionProvider(registry, 'my-dap', async () => {
235235
return {
236236
tool: [tool1, tool2],
237237
};
238238
});
239239

240-
const result = await dap.run({ tool: [tool1, tool2] });
241-
assert.deepStrictEqual(result.result, {
240+
let runInput: any;
241+
const originalRun = dap.run.bind(dap);
242+
dap.run = async (input, options) => {
243+
runInput = input;
244+
return originalRun(input, options);
245+
};
246+
247+
await dap.__cache.getOrFetch();
248+
249+
assert.deepStrictEqual(runInput, {
242250
tool: [tool1.__action, tool2.__action],
243251
});
244252
});

0 commit comments

Comments
 (0)