Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/core/capabilities/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function prepareRun(manifest: CapabilityManifest, args: Readonly<Record<string,
return { error: `${entry.name} carries the credential and cannot be supplied as an input` };
}
const value = args[entry.name];
if (entry.in === 'query') setQueryParam(target.url.searchParams, entry.name, value);
if (entry.in === 'query') setQueryParam(target.url.searchParams, entry.name, value, manifest.effect);
else if (entry.in === 'header') headers[entry.name] = stringifyParam(value);
else if (entry.in === 'body') body = JSON.stringify(value);
}
Expand Down Expand Up @@ -656,6 +656,10 @@ function checkInput(
continue;
}
errors.push(...validateValue(entry.schema, copied.value, entry.name));
// An empty list would send nothing at all: a required one is missing.
if (entry.required && entry.in === 'query' && Array.isArray(copied.value) && copied.value.length === 0) {
errors.push(`${entry.name} needs at least one value`);
}
args[entry.name] = copied.value;
}
if (errors.length === 0 && manifest.transport.kind === 'http') {
Expand Down
11 changes: 7 additions & 4 deletions src/core/capabilities/httpTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// A path argument fills one segment of the template and nothing else: the
// resolved pathname must be exactly the expanded template.

import type { CapabilityEffect } from './manifest';
import type { ValueType } from './valueType';

export function joinUrl(baseUrl: string, path: string): URL {
Expand All @@ -17,11 +18,13 @@ export function isPlainList(schema: ValueType): boolean {
}

/**
* Put one query argument on a URL. A list is sent the OpenAPI default way for
* a query (form, exploded): one `name=value` per element, in order.
* Put one query argument on a URL. On a read, a list is sent the OpenAPI
* default way for a query (form, exploded): one `name=value` per element, in
* order. Any other capability keeps sending one JSON value, as it always did:
* repeated lists are read-only surface (AGENTS.md stop condition 3).
*/
export function setQueryParam(params: URLSearchParams, name: string, value: unknown): void {
if (Array.isArray(value)) {
export function setQueryParam(params: URLSearchParams, name: string, value: unknown, effect: CapabilityEffect): void {
if (Array.isArray(value) && effect === 'read') {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve exploded lists for GET compute capabilities

A GET or HEAD operation explicitly marked x-omni-effect: compute is still accepted by collectInputs with a plain exploded query list and is eligible for the broker, but this condition serializes that list as one JSON value rather than the OpenAPI name=a&name=b form. Consequently, any such valid manifest sends a different request than before this commit (for example tags=%5B%22a%22%2C%22b%22%5D), which breaks endpoints that require exploded list parameters. Base the list encoding on the HTTP method/supported parameter shape, or retain repeated encoding for compute GET/HEAD capabilities.

Useful? React with 👍 / 👎.

params.delete(name);
for (const element of value) params.append(name, stringifyParam(element));
return;
Expand Down
21 changes: 20 additions & 1 deletion src/core/capabilities/listQueryParameters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,18 @@ describe('compiling a list-valued query parameter', () => {
describe('sending a list in the query', () => {
it('repeats the name once per element, in order', () => {
const params = new URLSearchParams('part=old');
setQueryParam(params, 'part', ['snippet', 'statistics']);
setQueryParam(params, 'part', ['snippet', 'statistics'], 'read');
expect(params.toString()).toBe('part=snippet&part=statistics');
});

it('keeps sending one JSON value for anything but a read, as before', () => {
for (const effect of ['compute', 'write', 'destructive'] as const) {
const params = new URLSearchParams();
setQueryParam(params, 'tags', ['a', 'b'], effect);
expect(params.getAll('tags')).toEqual(['["a","b"]']);
}
});

beforeEach(() => {
clearCapabilities();
capabilitySecrets.clear();
Expand All @@ -79,6 +87,17 @@ describe('sending a list in the query', () => {
expect(new URL(fetchMock.mock.calls[0][0]).searchParams.getAll('part')).toEqual(['snippet']);
});

it('refuses an empty required list instead of leaving it out', async () => {
const [manifest] = compileOpenApi(spec(LIST)).manifests;
expect(installProposal(manifest).ok).toBe(true);
const fetchMock = vi.fn();
vi.stubGlobal('fetch', fetchMock);
const result = await executeCapability(manifest.id, { part: [] });
expect(result.error?.code).toBe('INPUT_INVALID');
expect(result.error?.message).toContain('part needs at least one value');
expect(fetchMock).not.toHaveBeenCalled();
});

it('through the broker', async () => {
const [manifest] = compileOpenApi(spec(LIST), { brokerOrigins: ['https://videos.example.test'] }).manifests;
const seen: PinnedRequest[] = [];
Expand Down
2 changes: 1 addition & 1 deletion src/core/services/server/capabilityBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ function buildUrl(manifest: CapabilityManifest, input: Record<string, unknown>):
const url = target.url;
for (const entry of manifest.inputs) {
if (!Object.hasOwn(input, entry.name) || input[entry.name] === undefined || entry.in !== 'query') continue;
setQueryParam(url.searchParams, entry.name, input[entry.name]);
setQueryParam(url.searchParams, entry.name, input[entry.name], manifest.effect);
}
return url;
}
Expand Down
Loading