registerModel static method
Future<ModelInfo>
registerModel({
- String? id,
- required String name,
- required String url,
- required InferenceFramework framework,
- ModelCategory modality = ModelCategory.MODEL_CATEGORY_LANGUAGE,
- ModelArtifactType? artifactType,
- int? memoryRequirement,
- bool supportsThinking = false,
- bool supportsLora = false,
Register a remote model with the in-memory model registry from a
download URL. Delegates the full build-and-save flow to the commons
single-call factory rac_register_model_from_url_proto, which derives
the canonical id from the URL (rac_model_generate_id), defaults
format/framework/category/context-length, infers the artifact type from
the URL extension (archive vs single-file), overlays the caller-supplied
capability fields, and persists through the registry save path.
Mirrors Swift RunAnywhere.registerModel(id:name:url:framework:modality: artifactType:memoryRequirement:supportsThinking:supportsLora:), which
routes through the same commons factory (rac_model_info_make_proto).
Implementation
static Future<ModelInfo> registerModel({
String? id,
required String name,
required String url,
required InferenceFramework framework,
ModelCategory modality = ModelCategory.MODEL_CATEGORY_LANGUAGE,
ModelArtifactType? artifactType,
int? memoryRequirement,
bool supportsThinking = false,
bool supportsLora = false,
}) async {
if (!DartBridge.isInitialized) {
throw SDKException.notInitialized();
}
final request = RegisterModelFromUrlRequest(
url: url,
name: name,
framework: framework,
category: modality,
source: ModelSource.MODEL_SOURCE_REMOTE,
supportsThinking: supportsThinking,
supportsLora: supportsLora,
);
// Caller-supplied id always wins; otherwise commons derives it from the
// URL (matching Swift's `generatedModelID(from:name:)`).
if (id != null) {
request.id = id;
}
// Explicit artifact-type override wins over commons' URL inference.
if (artifactType != null) {
request.artifactType = artifactType;
}
if (memoryRequirement != null) {
request.memoryRequiredBytes = Int64(memoryRequirement);
}
// Intentionally NOT setting downloadSizeBytes from memoryRequirement: that
// value gates the post-finalize download-size check, and the RAM estimate
// is usually a round placeholder (e.g. 500 MB for a real 397 MB file),
// which leaves is_downloaded=false forever. Leaving it unset lets commons
// validate against the actual transfer — matches Kotlin's catalog.
final model = await DartBridgeModelRegistry.instance.registerModelFromUrl(
request,
);
if (model == null) {
throw SDKException.internalError(
'rac_register_model_from_url_proto failed for model "$name"',
);
}
return model;
}