4078158c01
Signed-off-by: Abhijay Jain <Abhijay007j@gmail.com> Co-authored-by: Lifei Zhou <lifei@squareup.com>
72 lines
2.3 KiB
TypeScript
72 lines
2.3 KiB
TypeScript
import {
|
|
client,
|
|
methods,
|
|
type Client,
|
|
type ClientConnection,
|
|
type Stream,
|
|
} from '@agentclientprotocol/sdk';
|
|
import {
|
|
GOOSE_EXT_AGENT_REQUESTS,
|
|
GOOSE_EXT_NOTIFICATIONS,
|
|
GooseExtClient,
|
|
type GooseSessionNotification_unstable,
|
|
type ProviderDeviceCodeNotification_unstable,
|
|
type RecipeParamsResponse_unstable,
|
|
type RequestRecipeParams_unstable,
|
|
zGooseSessionNotification_unstable,
|
|
zProviderDeviceCodeNotification_unstable,
|
|
zRequestRecipeParams_unstable,
|
|
} from '@aaif/goose-sdk';
|
|
|
|
const [gooseSessionUpdate, providerDeviceCode] = GOOSE_EXT_NOTIFICATIONS;
|
|
const [gooseRecipeParamsRequest] = GOOSE_EXT_AGENT_REQUESTS;
|
|
|
|
export type GooseAcpCallbacks = Required<
|
|
Pick<Client, 'requestPermission' | 'sessionUpdate' | 'unstable_createElicitation'>
|
|
> & {
|
|
unstable_sessionRecipeRequestParams: (
|
|
request: RequestRecipeParams_unstable
|
|
) => Promise<RecipeParamsResponse_unstable>;
|
|
unstable_sessionUpdate: (notification: GooseSessionNotification_unstable) => Promise<void>;
|
|
unstable_providerDeviceCode: (
|
|
notification: ProviderDeviceCodeNotification_unstable
|
|
) => Promise<void>;
|
|
};
|
|
|
|
export type GooseAcpClient = {
|
|
connection: ClientConnection;
|
|
goose: GooseExtClient;
|
|
};
|
|
|
|
export function connectGooseAcpClient(
|
|
stream: Stream,
|
|
callbacks: GooseAcpCallbacks
|
|
): GooseAcpClient {
|
|
const app = client({ name: 'goose' })
|
|
.onRequest(methods.client.session.requestPermission, (context) =>
|
|
callbacks.requestPermission(context.params)
|
|
)
|
|
.onNotification(methods.client.session.update, (context) =>
|
|
callbacks.sessionUpdate(context.params)
|
|
)
|
|
.onRequest(methods.client.elicitation.create, (context) =>
|
|
callbacks.unstable_createElicitation(context.params)
|
|
)
|
|
.onRequest(gooseRecipeParamsRequest.method, zRequestRecipeParams_unstable, (context) =>
|
|
callbacks.unstable_sessionRecipeRequestParams(context.params)
|
|
)
|
|
.onNotification(gooseSessionUpdate.method, zGooseSessionNotification_unstable, (context) =>
|
|
callbacks.unstable_sessionUpdate(context.params)
|
|
)
|
|
.onNotification(
|
|
providerDeviceCode.method,
|
|
zProviderDeviceCodeNotification_unstable,
|
|
(context) => callbacks.unstable_providerDeviceCode(context.params)
|
|
);
|
|
|
|
const connection = app.connect(stream);
|
|
const goose = new GooseExtClient(connection.agent);
|
|
|
|
return { connection, goose };
|
|
}
|