Use the TypeScript SDK in a source workspace
@codant/sdk is an ESM package currently built from the Codant source workspace. It depends on the internal @codant/api via workspace:*. The build exports dist/index.js and the types in dist/index.d.ts. Install dependencies and build in the Codant source workspace using the quickstart. See private, exports, and dependencies in packages/sdk/package.json. SDK exports
Open and negotiate a connection
Provide an RPC transport in your local application, for example stdio. Common SDK clients accept an existing connection. Your application writes requests, matches responses, handles notifications, and ends pending requests when the connection closes. negotiateSessionProtocol accepts call, a check that the connection is still current, and a function that recognizes a server rejection. It returns validated capabilities for the connection. If the connection already has a successful initialization result, pass its capabilities to the relevant client. See negotiateSessionProtocol in packages/api/src/session-handshake.ts, PlanClientConnection in packages/api/src/plan-client.ts, and packages/sdk/src/index.ts.
Enable features according to the initialization result. Advanced features may need an explicit opt-in and a data source on the server. negotiateSessionProtocol tries another option after the relevant explicit RPC rejection. Transport failure, a stale connection, or a response that cannot be validated fails the original call. See packages/api/src/session-handshake.ts, packages/api/src/protocol-initialization.ts, and the initialization reference.
Read the plan for an existing task
The example takes an initialized rpc, the capability result from negotiateSessionProtocol, and an existing task ID. It checks task/plan support, requests a first page of up to ten steps, and returns the result for the caller to handle. Make isCurrent() check that the original connection is still the active one. See createPlanClient in packages/api/src/plan-client.ts, packages/api/src/task-plan-protocol.ts, and the task query reference.
import { createPlanClient, type PlanClientConnection } from '@codant/sdk';
type Rpc = Pick<PlanClientConnection, 'call' | 'isCurrent'>;
type PlanFeatures = Pick<PlanClientConnection,
'supportsTaskPlan' | 'supportsSessionPlan' | 'supportsTaskObservation'>;
export async function readTaskPlan(rpc: Rpc, negotiated: PlanFeatures, taskId: string) {
const plans = createPlanClient({
...negotiated,
call: (method, params, timeoutMs) => rpc.call(method, params, timeoutMs),
isCurrent: () => rpc.isCurrent(),
});
if (!plans.supportsTaskPlan) {
return { status: 'unsupported' as const, reason: 'Task plan unavailable on this connection' };
}
return plans.task({ taskId, limit: 10 });
}Reuse the same plan client for later pages and pass confirmed.nextCursor back for the original task. The client verifies the connection, task identity, query watermark, and original fact. When task observation is available, observe and unobserve manage a subscription on that connection. The transport dispatches task/event. See packages/api/src/plan-client.ts and the event reference.
