registerArchiveModel static method
Future<ModelInfo>
registerArchiveModel({
- required String archiveUrl,
- required ArchiveStructure structure,
- String? id,
- required String name,
- required InferenceFramework framework,
- ModelCategory modality = ModelCategory.MODEL_CATEGORY_LANGUAGE,
- ArchiveType? archiveType,
- int? memoryRequirement,
- bool supportsThinking = false,
- bool supportsLora = false,
Register an archive-packaged model (tar.gz / tar.bz2 / tar.xz / zip) where the caller needs to specify the on-disk layout (ArchiveStructure.ARCHIVE_STRUCTURE_DIRECTORY_BASED, ArchiveStructure.ARCHIVE_STRUCTURE_NESTED_DIRECTORY, etc.) the URL-form registerModel cannot infer.
Composes registerModel and then patches the resolved ArchiveArtifact.structure before re-saving through the registry.
Mirrors Swift RunAnywhere.registerModel(archive:structure:...).
Implementation
static Future<ModelInfo> registerArchiveModel({
required String archiveUrl,
required ArchiveStructure structure,
String? id,
required String name,
required InferenceFramework framework,
ModelCategory modality = ModelCategory.MODEL_CATEGORY_LANGUAGE,
ArchiveType? archiveType,
int? memoryRequirement,
bool supportsThinking = false,
bool supportsLora = false,
}) async {
// Map an explicit caller archive type to its artifact-type override.
// When the caller passes none, leave the override unset so commons
// infers the archive type from the URL extension (mirroring Swift's
// `ArchiveType.from(url:)`, which lives behind
// `rac_model_info_make_proto`).
final ModelArtifactType? resolvedArtifactType;
if (archiveType == null) {
resolvedArtifactType = null;
} else {
switch (archiveType) {
case ArchiveType.ARCHIVE_TYPE_ZIP:
resolvedArtifactType =
ModelArtifactType.MODEL_ARTIFACT_TYPE_ZIP_ARCHIVE;
break;
case ArchiveType.ARCHIVE_TYPE_TAR_GZ:
resolvedArtifactType =
ModelArtifactType.MODEL_ARTIFACT_TYPE_TAR_GZ_ARCHIVE;
break;
case ArchiveType.ARCHIVE_TYPE_TAR_BZ2:
resolvedArtifactType =
ModelArtifactType.MODEL_ARTIFACT_TYPE_TAR_BZ2_ARCHIVE;
break;
case ArchiveType.ARCHIVE_TYPE_TAR_XZ:
resolvedArtifactType =
ModelArtifactType.MODEL_ARTIFACT_TYPE_TAR_XZ_ARCHIVE;
break;
default:
resolvedArtifactType = ModelArtifactType.MODEL_ARTIFACT_TYPE_ARCHIVE;
}
}
var model = await registerModel(
id: id,
name: name,
url: archiveUrl,
framework: framework,
modality: modality,
artifactType: resolvedArtifactType,
memoryRequirement: memoryRequirement,
supportsThinking: supportsThinking,
supportsLora: supportsLora,
);
// Preserve the caller-specified layout on the archive artifact. Commons
// infers the archive type from the URL; the nested/directory layout can
// only come from the caller — patch and re-persist (mirroring Swift's
// archive overload, which always carries an archive artifact with the
// caller's structure).
final patchedArchive =
(model.hasArchive() ? model.archive.deepCopy() : ArchiveArtifact())
..structure = structure;
if (archiveType != null) {
patchedArchive.type = archiveType;
}
model = model.deepCopy()
..archive = patchedArchive
..updatedAtUnixMs = Int64(DateTime.now().millisecondsSinceEpoch);
await DartBridgeModelRegistry.instance.saveProtoModel(model);
return model;
}