handle method
Implementation
@override
Future<StructuredResponse> handle(GlintSession session, CallToolRequest request) async {
final args = request.arguments ?? const {};
final durationMs = argInt(args, 'durationMs') ?? 800;
final t = readTargetedArgs(args, session.config);
final seg = readSegment(args);
if (seg != null) {
return segmentSwipe(session, 'drag', seg, durationMs,
verb: 'dragged', returnScene: t.returnScene, fetchScene: t.fetchScene);
}
final from = args['fromGlintId'] as String?;
final to = args['toGlintId'] as String?;
if (from == null || to == null) {
return StructuredResponse.error(
summary: 'drag needs either fromGlintId + toGlintId, or x1,y1,x2,y2',
errorKind: GlintErrorKind.invalidArgument,
nextSteps: const [
'pass fromGlintId + toGlintId (from get_scene), or all four of '
'x1,y1,x2,y2',
],
);
}
final arming = await maybeAwaitReady(
session: session,
glintId: from,
awaitReady: t.awaitReady,
ceilingMs: t.readyTimeoutMs,
toolLabel: 'drag',
);
if (arming is ArmingFailed) return arming.envelope;
final action = await openActionScene(session, snapshot: t.returnScene);
final scene = action.scene;
try {
final result = await session.interactor.run(
scene,
Swipe(SymbolicTarget(from), SymbolicTarget(to), durationMs: durationMs),
);
var response = StructuredResponse.fromActionResult(result);
if (arming is ArmingReady) response = withArmedMetadata(response, arming);
return await appendPostAction(session, response, action.pre,
returnScene: t.returnScene, fetchScene: t.fetchScene);
} finally {
await action.dispose();
}
}