ProviderQueueEntry.fromJsonMap constructor
ProviderQueueEntry.fromJsonMap(})
Parses one entry from a decoded JSON map (the env / @file form).
Throws ConfigException with the 1-based position (entry index)
in every message; unknown keys inside provider_config are tolerated
as params and reported in warnings.
Implementation
factory ProviderQueueEntry.fromJsonMap(
Map<Object?, Object?> map, {
required int position,
List<String>? warnings,
}) {
final where = 'queue entry #$position';
final type = map['provider_type'];
if (type is! String || type.trim().isEmpty) {
throw ConfigException(
'$where: missing a "provider_type" string — '
'supported: ${providerQueueKinds.join(', ')}',
);
}
final providerType = type.trim();
if (!providerQueueKinds.contains(providerType)) {
throw ConfigException(
'$where: unknown provider_type "$providerType" — '
'supported: ${providerQueueKinds.join(', ')}',
);
}
final config = map['provider_config'];
if (config is! Map) {
throw ConfigException(
'$where: missing a "provider_config" object '
'(needs at least {"model": "..."})',
);
}
final model = config['model'];
if (model is! String || model.trim().isEmpty) {
throw ConfigException('$where: provider_config needs a "model" string');
}
for (final key in const ['apiKey', 'api_key', 'apiKeyValue']) {
if (config[key] != null) {
throw ConfigException(
'$where: provider_config."$key" is not allowed — name the key '
'with "apiKeyEnv" instead; key values never ride in config '
'blobs',
);
}
}
final unknown = [
for (final key in config.keys)
if (key is String &&
!const [
'model',
'baseUrl',
'apiKeyEnv',
'contextWindow',
'maxTokens',
].contains(key))
key,
];
if (unknown.isNotEmpty && warnings != null) {
warnings.add(
'$where: unknown provider_config key(s) '
'${unknown.map((k) => '"$k"').join(', ')} — carried as params',
);
}
return ProviderQueueEntry(
providerType: providerType,
model: model.trim(),
baseUrl: _optionalString(config, 'baseUrl', where),
apiKeyEnv: _optionalString(config, 'apiKeyEnv', where),
contextWindow: _optionalInt(config, 'contextWindow', where),
maxTokens: _optionalInt(config, 'maxTokens', where),
);
}