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
18 changes: 18 additions & 0 deletions docs/release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ The JSON fields remain `name`, `systemPrompt` and
rely on the removed reply type's rejection of unknown fields. There is no
App Server protocol, event or persistence-format change.

## Method progress type compatibility

The progress callback a `dimcode/plugin` method handler receives returns
`Promise<void>`; its declaration was `() => void`. The host already supplies an
asynchronous callback, so `await progress(...)` and `progress(...).catch(...)`
now type-check, and no host build is required. The change breaks code that calls
an exported `MethodHandler` or `SessionMethodHandler` directly: a synchronous
argument such as `() => {}`, as a unit-test mock uses, fails with TS2345. Pass
`async () => {}` instead. Handlers registered through
`managementMethods.register` or `sessionMethods.register` receive the same
callback at runtime. Awaiting it orders the host's send attempts and does not
acknowledge client delivery; the App Server's progress allowance can drop a
notice while the call still resolves, whereas a frame over the rutis session's
transfer limit fails the call and rejects the promise. The
[authoring guide](../typescript-plugin-authoring.md#session-tools-and-client-methods)
states the callback's delivery and rejection behaviour. There is no App Server
protocol, event or persistence-format change.

## File access

Under `read-only` and `workspace-write`, a file tool read (`read`, `grep` or `glob`) whose
Expand Down
20 changes: 18 additions & 2 deletions docs/typescript-plugin-authoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ export const sessionExample = definePlugin({
'session.example',
[{ name: 'session.example.echo', mutating: false, interruption: 'report', progress: true }],
async (call, _cancelled, progress) => {
progress({ phase: 'started' });
await progress({ phase: 'started' });
return { kind: 'value', value: call.params };
},
);
Expand Down Expand Up @@ -646,7 +646,23 @@ under the `hello`, `daemon`, `agent` or `approval` roots; an `apply` that awaits
fails its part. The registration lasts until the part unloads, and `session.methods`
lists the methods registered at that call. `call` is asynchronous and receives an
opaque runtime `callId`, the method and original params containing `sessionId` and
optional `branchId`; it also receives cancellation and a per-call progress callback.
optional `branchId`; it also receives cancellation and a per-call progress callback. The callback
returns a promise, and awaiting it is what keeps your notices in order: each call is a frame the host
runs on its own task, so two calls without a wait between them can arrive in either order. Await it
as well when a notice has to be queued before the method returns, because the reply closes the
progress channel and drops a send that has not run yet.

Awaiting that promise orders the host's send attempts; it does not acknowledge
delivery to the client. The App Server's progress allowance is best effort: it
drops progress a method does not declare, progress sent after it hands over the
reply, and progress its connection cannot take, including after a disconnect,
while the call itself still resolves. The rutis transfer limit is not: a call
whose encoded frame exceeds the session's `max_transfer` fails with
`bad-value`, and a call on a closed bridge fails too, so a progress call you do
not await can reject. Attach `.catch(...)` to a detached call. A unit test that
calls a `MethodHandler` or `SessionMethodHandler` directly must pass
`async () => {}` as the progress callback; the type requires a promise.

Return `{kind: 'value', value}`, return a failure as data, `{code, message}`, or
rethrow the service error you received. An omitted value becomes JSON null. Rpc maps a failure to
the wire error: `code` becomes `appError`, with JSON-RPC code -32602 for `invalid_params` and
Expand Down
2 changes: 1 addition & 1 deletion npm/plugin.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ export type MethodReply<T = BridgeJsonValue> = { kind: 'value'; value?: T } | Me
export type CheckedData<T> = T extends BridgeJsonValue | undefined ? T
: T extends ((...args: never[]) => unknown) | (abstract new (...args: never[]) => unknown) ? never
: T extends object ? keyof T extends never ? never : { [K in keyof T]: CheckedData<T[K]> } : never;
export type MethodProgress = <T>(data: T & CheckedData<T>) => void;
export type MethodProgress = <T>(data: T & CheckedData<T>) => Promise<void>;
export type SessionMethodDeclaration = MethodDeclaration;
export type SessionMethodReply<T = BridgeJsonValue> = MethodReply<T>;
/** How a registered management namespace serves one call. */
Expand Down
11 changes: 6 additions & 5 deletions runtime/plugin-sdk.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ void management.register('fixture', [], typedHandler);
void methods.register('fixture', [], async () => initialReply);
void management.register('fixture', [], async () => configuredReply);
void methods.register('fixture', [], async (call, cancelled, progress) => {
progress(configured);
const sent: Promise<void> = progress(configured);
await sent;
progress(entry);
progress({});
// @ts-expect-error progress carries data, not callbacks.
Expand All @@ -120,7 +121,7 @@ void management.register('fixture', [], async () => ({ kind: 'other', value: con

const declarations: MethodDeclaration[] = [{ name: 'example.status', mutating: false, interruption: 'report', progress: false }];
void management.register('example', declarations, handler);
void handler({ callId: 'call', method: 'example.status', params: [1, true] }, Promise.resolve(), () => {});
void handler({ callId: 'call', method: 'example.status', params: [1, true] }, Promise.resolve(), async () => {});
// @ts-expect-error a declaration states its interruption and progress.
void management.register('example', [{ name: 'example.status', mutating: false }], handler);
const at = { sessionId: 'session', branchId: 'main' };
Expand Down Expand Up @@ -240,11 +241,11 @@ void execute({
}, Promise.resolve());
void methods.register('session.example', [{ name: 'session.example.echo', mutating: false, interruption: 'drain', progress: true }], sessionHandler);
void sessionHandler({ callId: 'call', method: 'session.example.echo', params: { sessionId: 'session' } },
Promise.resolve(), () => {});
Promise.resolve(), async () => {});
// @ts-expect-error a Session method call names its Session.
void sessionHandler({ callId: 'call', method: 'session.example.echo', params: {} }, Promise.resolve(), () => {});
void sessionHandler({ callId: 'call', method: 'session.example.echo', params: {} }, Promise.resolve(), async () => {});
void handler({ callId: 'call', method: 'example.status', params: [1, true],
origin: { connectionId: 'connection' } }, Promise.resolve(), () => {});
origin: { connectionId: 'connection' } }, Promise.resolve(), async () => {});
const notificationOrigin: MethodDeclaration = { name: 'example.status', mutating: false,
interruption: 'report', progress: false, notifications: ['example.changed'] };
void notificationOrigin;
Expand Down