Interrupt<Input, Output> constructor
Interrupt<Input, Output> ({})
Implementation
Interrupt({
required String name,
required String description,
SchemanticType<Input>? inputSchema,
SchemanticType<Output>? outputSchema,
Map<String, dynamic>? metadata,
/// Optional data attached to the `interrupt` metadata of the generated tool
/// request. Receives the tool input and may return a value or a future.
/// When omitted, the interrupt metadata defaults to `true`.
FutureOr<Object?> Function(Input input, ToolFnArg<Input> ctx)?
requestMetadata,
}) : super(
name: name,
description: description,
inputSchema: inputSchema,
outputSchema: outputSchema,
metadata: {
...?metadata,
'tool': {
// `metadata['tool']` is user-supplied; only spread it when it is
// actually a map (it may be absent, a `Map<dynamic, dynamic>` from
// a literal, or an unrelated value), otherwise ignore it.
if (metadata?['tool'] is Map)
...(metadata!['tool'] as Map).cast<String, dynamic>(),
'restartable': false,
},
},
fn: (input, ctx) async {
final data = requestMetadata == null
? null
: await requestMetadata(input, ctx);
return ToolResult.interrupt(data);
},
);