@ai-matrx/agents 0.59.229 → 0.59.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,6 +47,7 @@ __export(models_exports, {
47
47
  buildSuccessionIndex: () => buildSuccessionIndex,
48
48
  catalogFingerprint: () => catalogFingerprint,
49
49
  catalogForApp: () => catalogForApp,
50
+ catalogKeyColumn: () => catalogKeyColumn,
50
51
  catalogKindOf: () => catalogKindOf,
51
52
  cheapestAdequateModel: () => cheapestAdequateModel,
52
53
  classConfigKey: () => classConfigKey,
@@ -290,6 +291,12 @@ function isInteractionMode(value) {
290
291
  return typeof value === "string" && INTERACTION_MODES.includes(value);
291
292
  }
292
293
 
294
+ // models/catalog-key.ts
295
+ var import_uuid = require("@ai-matrx/kit/uuid");
296
+ function catalogKeyColumn(value) {
297
+ return (0, import_uuid.isUuidShape)(value.trim()) ? "id" : "name";
298
+ }
299
+
293
300
  // models/model-normalizer.ts
294
301
  var LEGACY_KEY_MAP = {
295
302
  max_tokens: "max_output_tokens",
@@ -789,7 +796,7 @@ function serviceCountLabel(count) {
789
796
  }
790
797
 
791
798
  // models/favorites.ts
792
- var import_uuid = require("@ai-matrx/kit/uuid");
799
+ var import_uuid2 = require("@ai-matrx/kit/uuid");
793
800
  var MODEL_FAVORITE_ENTITY_TYPE = "ai_model";
794
801
  function reconcileModelFavoriteIds(cached, canonical) {
795
802
  const seen = /* @__PURE__ */ new Set();
@@ -837,7 +844,7 @@ function createModelFavorites(config) {
837
844
  };
838
845
  cache.subscribe?.(refresh);
839
846
  const writeCanonical = async (id, isFavorite) => {
840
- if (!(0, import_uuid.isUuidShape)(id)) {
847
+ if (!(0, import_uuid2.isUuidShape)(id)) {
841
848
  sink({ code: "model-favorite-not-a-uuid", message: "not a model uuid \u2014 skipped ues_set", context: { id } });
842
849
  return;
843
850
  }
@@ -1007,7 +1014,7 @@ function createModelRecords(config) {
1007
1014
  };
1008
1015
  async function readFullModel(modelId) {
1009
1016
  const relation = await isSignedIn() ? "model_config" : "model_public";
1010
- const { data, error } = await ai().from(relation).select(MODEL_CONFIG_COLUMNS).eq("id", modelId).maybeSingle();
1017
+ const { data, error } = await ai().from(relation).select(MODEL_CONFIG_COLUMNS).eq(catalogKeyColumn(modelId), modelId).maybeSingle();
1011
1018
  if (error) throw error;
1012
1019
  const row = data;
1013
1020
  if (!row) throw new Error(`AI model ${modelId} is not available (ai.${relation} has no such row)`);
@@ -1060,7 +1067,7 @@ function createModelRecords(config) {
1060
1067
  }
1061
1068
  for (const id of Object.keys(known.identityById)) {
1062
1069
  jobs.push(
1063
- Promise.resolve(ai().from("model_definition").select("id, name, common_name, is_deprecated").eq("id", id).maybeSingle()).then(
1070
+ Promise.resolve(ai().from("model_definition").select("id, name, common_name, is_deprecated").eq(catalogKeyColumn(id), id).maybeSingle()).then(
1064
1071
  ({ data, error }) => {
1065
1072
  if (error) throw error;
1066
1073
  if (data) update((s3) => ({ ...s3, identityById: { ...s3.identityById, [id]: data } }));
@@ -1290,14 +1297,14 @@ function createModelRecords(config) {
1290
1297
  return once(`identity:${modelId}`, async () => {
1291
1298
  update((s3) => ({ ...s3, identityStatusById: { ...s3.identityStatusById, [modelId]: "loading" } }));
1292
1299
  try {
1293
- const { data, error } = await ai().from("model_definition").select("id, name, common_name, is_deprecated").eq("id", modelId).maybeSingle();
1300
+ const { data, error } = await ai().from("model_definition").select("id, name, common_name, is_deprecated").eq(catalogKeyColumn(modelId), modelId).maybeSingle();
1294
1301
  if (error) throw error;
1295
1302
  if (!data) throw new Error(`AI model ${modelId} is not available (ai.model_definition has no such row)`);
1296
1303
  const row = data;
1297
1304
  update((s3) => ({
1298
1305
  ...s3,
1299
- identityById: { ...s3.identityById, [row.id]: row },
1300
- identityStatusById: { ...s3.identityStatusById, [row.id]: "succeeded" }
1306
+ identityById: { ...s3.identityById, [row.id]: row, [modelId]: row },
1307
+ identityStatusById: { ...s3.identityStatusById, [row.id]: "succeeded", [modelId]: "succeeded" }
1301
1308
  }));
1302
1309
  } catch (err) {
1303
1310
  errorSink({ code: "model-records-identity-failed", message: messageOf(err), context: { modelId } });
@@ -1810,8 +1817,9 @@ function resetSuccessionLogForTests() {
1810
1817
  async function resolveLiveModelId(client, modelId) {
1811
1818
  const index = /* @__PURE__ */ new Map();
1812
1819
  let want = modelId;
1820
+ let startId = modelId;
1813
1821
  for (let hop = 0; want && hop <= MAX_SUCCESSION_HOPS && !index.has(want); hop += 1) {
1814
- const { data, error } = await client.schema("ai").from("model_public").select("id, is_deprecated, retired_at, successor_id").in("id", [want]);
1822
+ const { data, error } = await client.schema("ai").from("model_public").select("id, is_deprecated, retired_at, successor_id").in(hop === 0 ? catalogKeyColumn(want) : "id", [want]);
1815
1823
  if (error) {
1816
1824
  console.warn(`[models/succession] ${modelId}: the catalog could not be read (${error.message}); keeping the model as given.`);
1817
1825
  return modelId;
@@ -1825,9 +1833,11 @@ async function resolveLiveModelId(client, modelId) {
1825
1833
  successorId: typeof row.successor_id === "string" ? row.successor_id : null
1826
1834
  };
1827
1835
  index.set(node.id, node);
1836
+ if (hop === 0) startId = node.id;
1828
1837
  want = isSupersedable(node) ? node.successorId : null;
1829
1838
  }
1830
- return resolveSuccessor(modelId, index);
1839
+ const resolved = resolveSuccessor(startId, index);
1840
+ return resolved === startId ? modelId : resolved;
1831
1841
  }
1832
1842
 
1833
1843
  // models/local.ts
@@ -71,6 +71,9 @@ declare function isContentType(value: unknown): value is ContentType;
71
71
  declare function isFeatureKey(value: unknown): value is FeatureKey;
72
72
  declare function isInteractionMode(value: unknown): value is InteractionMode;
73
73
 
74
+ type CatalogKeyColumn = "id" | "name";
75
+ declare function catalogKeyColumn(value: string): CatalogKeyColumn;
76
+
74
77
  /**
75
78
  * Normalizes legacy model control keys and prompt settings keys to their
76
79
  * current backend equivalents.
@@ -1808,4 +1811,4 @@ catalog?: SuccessionClient): Promise<NewAgentModel>;
1808
1811
  */
1809
1812
  declare function resolveModelMapKnob(value: unknown, catalog: SuccessionClient): Promise<Record<string, string>>;
1810
1813
 
1811
- export { type AdminOffering, type AdminPricingBand, type ArtifactUse, type AuditCapabilitiesRecord, CHAT_DEFAULT_MODEL_KNOB, CONTENT_TYPES, type CapabilitiesParseContext, type CatalogKindInput, type CatalogModel, type CatalogTier, type CheapestAdequateOptions, type CompatStatus, type ContentType, type CuratedCatalogClient, type CuratedModel, type CuratedPresentation, type CuratedRows, type CuratedVariant, DEFAULT_CAPABILITIES, type DecidedBy, type DeviceGraphics, type DeviceHardware, type DiscoveryAmbiguity, type DiscoveryArtifact, type DiscoveryMedia, type DiscoveryResult, type DiscoveryRuntime, type DiscoverySource, type DiscoveryVariant, EMPTY_MODEL_RECORDS, EXCLUDED_REVIEW_STATES, FEATURE_BUCKETS, FEATURE_BUCKET_ORDER, FEATURE_KEYS, FILE_TYPE_QUANT, type FeatureBucket, type FeatureBucketMeta, type FeatureKey, type FitCapabilities, GgufError, type GgufHeader, type GgufRead, type GgufTensor, type GroupedFeatures, type HardwareClass, type HardwareClasses, type HeaderFlag, type HeaderJudgement, type HeaderRefusal, INPUT_MODALITIES, INTERACTION_MODES, type Interaction, type InteractionMode, type LocalArtifact, type LocalCatalogClient, type LocalCatalogQuery, type LocalCompatRow, type LocalModel, type LocalModelCatalog, type LocalPresentation, type LocalRuntime, type LocalRuntimeBuild, type LocalVariant, MAX_SUCCESSION_HOPS, MODEL_CATALOG_KINDS, MODEL_FAVORITE_ENTITY_TYPE, type Modality, type ModelCapabilities, type ModelCatalog, type ModelCatalogClient, type ModelCatalogConfig, type ModelCatalogErrorSink, type ModelCatalogPgError, type ModelCatalogPgResult, type ModelCatalogQuery, type ModelCatalogState, type ModelCatalogVariant, type ModelCatalogVariantState, type ModelClassConfig, type ModelClassEntry, type ModelClassIndex, type ModelDiagnosticEntry, type ModelDiagnosticsSink, type ModelFavorites, type ModelFavoritesCache, type ModelFavoritesClient, type ModelFavoritesConfig, type ModelFavoritesErrorSink, type ModelFavoritesState, type ModelFetchScope, type ModelFileHandle, type ModelFit, type ModelIdentityRow, type ModelJson, type ModelNeed, type ModelOfferingRow, type ModelOption, type ModelOptionWithLifecycle, type ModelRecord, type ModelRecordFetchType, type ModelRecords, type ModelRecordsClient, type ModelRecordsConfig, type ModelRecordsState, type ModelSelectionPurpose, type ModelSetEnv, type ModelSetFacts, type ModelSetValidation, NEW_AGENT_DEFAULT_MODEL_KNOB, type NewAgentModel, type NoSelection, OUTPUT_MODALITIES, type OrderedLike, type PreferredModelChoice, type PreferredModelChoicePorts, type PriceTier, type PricedCatalogModel, type RankOptions, type RankedVariant, type ReadModelCatalogOptions, SERVICE_LABEL, SERVICE_LABEL_PLURAL, type SelectDevice, type Selection, type ShardName, type SuccessionClient, type SuccessionIndex, type SuccessionNode, TOP_TIER_COST_RATING, TOP_TIER_LOCKED_TITLE, type VariantDiscovery, type VariantVerdict, type Want, acceptsTextInstructions, blendedPrice, buildModelClassIndex, buildSuccessionIndex, catalogFingerprint, catalogForApp, catalogKindOf, cheapestAdequateModel, classConfigKey, collapseTiersByClass, costRatingTier, costRatingWord, createModelCatalog, createModelFavorites, createModelRecords, curatedList, displayOrderOf, favoriteIdsEqual, fetchCuratedModels, findNonCanonicalCapabilityValues, fitsMemory, fitsNeed, fitsThisComputer, formatMemoryBytes, fromDiscovery, ggufEngine, ggufFacts, groupFeatures, hardwareClassesOf, hasCompatibleDecisionInteraction, isChatModelCapability, isContentType, isConversationalModelCapability, isDecisionModelCapability, isFeatureKey, isHelperGguf, isInteractionMode, isListedVariant, isLocalModelCatalog, isManagedAgentModelCapability, isProjectorName, isSupersedable, isTopTierRating, judgeHeaderFacts, mergeAuditRecordIntoCapabilities, missingShards, modelClassKnobFor, modelClassName, modelClassPinOf, modelsForSelectionPurpose, normalizeArch, normalizeModel, normalizeModels, normalizeOs, normalizePromptSettings, orderCatalogGroups, orderCatalogModels, outputFormatControlKey, parseCapabilities, pickProjector, priceTierRating, quantFromName, rankVariants, readCuratedRows, readGgufHeader, readModelCatalog, reconcileModelFavoriteIds, reportModelDiagnostic, requireCanonicalCapabilities, requiredArtifacts, resetSuccessionLogForTests, resolveLiveModelId, resolveModelMapKnob, resolveNewAgentModelId, resolvePreferredModelChoice, resolveSuccessor, runtimesOnEngine, seesImages, selectActiveModels, selectActiveModelsReady, selectAllModelOptions, selectAllModels, selectAllModelsReady, selectDeprecatedModels, selectDeprecatedModelsReady, selectModelById, selectModelClassConfig, selectModelClassName, selectModelControls, selectModelDetailError, selectModelFetchType, selectModelFullyLoaded, selectModelIdentityById, selectModelIdentityLookupStatus, selectModelLabelById, selectModelLabelWithClass, selectModelNameById, selectModelOptions, selectVariant, serviceCountLabel, setModelDiagnosticsSink, shapeCuratedModels, shardFileName, shardName, speedRatingLabel, speedRatingWord, splitSetProblems, takesInput, toAuditRecord, validateModelSet, variantVerdict, withModelClass };
1814
+ export { type AdminOffering, type AdminPricingBand, type ArtifactUse, type AuditCapabilitiesRecord, CHAT_DEFAULT_MODEL_KNOB, CONTENT_TYPES, type CapabilitiesParseContext, type CatalogKeyColumn, type CatalogKindInput, type CatalogModel, type CatalogTier, type CheapestAdequateOptions, type CompatStatus, type ContentType, type CuratedCatalogClient, type CuratedModel, type CuratedPresentation, type CuratedRows, type CuratedVariant, DEFAULT_CAPABILITIES, type DecidedBy, type DeviceGraphics, type DeviceHardware, type DiscoveryAmbiguity, type DiscoveryArtifact, type DiscoveryMedia, type DiscoveryResult, type DiscoveryRuntime, type DiscoverySource, type DiscoveryVariant, EMPTY_MODEL_RECORDS, EXCLUDED_REVIEW_STATES, FEATURE_BUCKETS, FEATURE_BUCKET_ORDER, FEATURE_KEYS, FILE_TYPE_QUANT, type FeatureBucket, type FeatureBucketMeta, type FeatureKey, type FitCapabilities, GgufError, type GgufHeader, type GgufRead, type GgufTensor, type GroupedFeatures, type HardwareClass, type HardwareClasses, type HeaderFlag, type HeaderJudgement, type HeaderRefusal, INPUT_MODALITIES, INTERACTION_MODES, type Interaction, type InteractionMode, type LocalArtifact, type LocalCatalogClient, type LocalCatalogQuery, type LocalCompatRow, type LocalModel, type LocalModelCatalog, type LocalPresentation, type LocalRuntime, type LocalRuntimeBuild, type LocalVariant, MAX_SUCCESSION_HOPS, MODEL_CATALOG_KINDS, MODEL_FAVORITE_ENTITY_TYPE, type Modality, type ModelCapabilities, type ModelCatalog, type ModelCatalogClient, type ModelCatalogConfig, type ModelCatalogErrorSink, type ModelCatalogPgError, type ModelCatalogPgResult, type ModelCatalogQuery, type ModelCatalogState, type ModelCatalogVariant, type ModelCatalogVariantState, type ModelClassConfig, type ModelClassEntry, type ModelClassIndex, type ModelDiagnosticEntry, type ModelDiagnosticsSink, type ModelFavorites, type ModelFavoritesCache, type ModelFavoritesClient, type ModelFavoritesConfig, type ModelFavoritesErrorSink, type ModelFavoritesState, type ModelFetchScope, type ModelFileHandle, type ModelFit, type ModelIdentityRow, type ModelJson, type ModelNeed, type ModelOfferingRow, type ModelOption, type ModelOptionWithLifecycle, type ModelRecord, type ModelRecordFetchType, type ModelRecords, type ModelRecordsClient, type ModelRecordsConfig, type ModelRecordsState, type ModelSelectionPurpose, type ModelSetEnv, type ModelSetFacts, type ModelSetValidation, NEW_AGENT_DEFAULT_MODEL_KNOB, type NewAgentModel, type NoSelection, OUTPUT_MODALITIES, type OrderedLike, type PreferredModelChoice, type PreferredModelChoicePorts, type PriceTier, type PricedCatalogModel, type RankOptions, type RankedVariant, type ReadModelCatalogOptions, SERVICE_LABEL, SERVICE_LABEL_PLURAL, type SelectDevice, type Selection, type ShardName, type SuccessionClient, type SuccessionIndex, type SuccessionNode, TOP_TIER_COST_RATING, TOP_TIER_LOCKED_TITLE, type VariantDiscovery, type VariantVerdict, type Want, acceptsTextInstructions, blendedPrice, buildModelClassIndex, buildSuccessionIndex, catalogFingerprint, catalogForApp, catalogKeyColumn, catalogKindOf, cheapestAdequateModel, classConfigKey, collapseTiersByClass, costRatingTier, costRatingWord, createModelCatalog, createModelFavorites, createModelRecords, curatedList, displayOrderOf, favoriteIdsEqual, fetchCuratedModels, findNonCanonicalCapabilityValues, fitsMemory, fitsNeed, fitsThisComputer, formatMemoryBytes, fromDiscovery, ggufEngine, ggufFacts, groupFeatures, hardwareClassesOf, hasCompatibleDecisionInteraction, isChatModelCapability, isContentType, isConversationalModelCapability, isDecisionModelCapability, isFeatureKey, isHelperGguf, isInteractionMode, isListedVariant, isLocalModelCatalog, isManagedAgentModelCapability, isProjectorName, isSupersedable, isTopTierRating, judgeHeaderFacts, mergeAuditRecordIntoCapabilities, missingShards, modelClassKnobFor, modelClassName, modelClassPinOf, modelsForSelectionPurpose, normalizeArch, normalizeModel, normalizeModels, normalizeOs, normalizePromptSettings, orderCatalogGroups, orderCatalogModels, outputFormatControlKey, parseCapabilities, pickProjector, priceTierRating, quantFromName, rankVariants, readCuratedRows, readGgufHeader, readModelCatalog, reconcileModelFavoriteIds, reportModelDiagnostic, requireCanonicalCapabilities, requiredArtifacts, resetSuccessionLogForTests, resolveLiveModelId, resolveModelMapKnob, resolveNewAgentModelId, resolvePreferredModelChoice, resolveSuccessor, runtimesOnEngine, seesImages, selectActiveModels, selectActiveModelsReady, selectAllModelOptions, selectAllModels, selectAllModelsReady, selectDeprecatedModels, selectDeprecatedModelsReady, selectModelById, selectModelClassConfig, selectModelClassName, selectModelControls, selectModelDetailError, selectModelFetchType, selectModelFullyLoaded, selectModelIdentityById, selectModelIdentityLookupStatus, selectModelLabelById, selectModelLabelWithClass, selectModelNameById, selectModelOptions, selectVariant, serviceCountLabel, setModelDiagnosticsSink, shapeCuratedModels, shardFileName, shardName, speedRatingLabel, speedRatingWord, splitSetProblems, takesInput, toAuditRecord, validateModelSet, variantVerdict, withModelClass };
@@ -71,6 +71,9 @@ declare function isContentType(value: unknown): value is ContentType;
71
71
  declare function isFeatureKey(value: unknown): value is FeatureKey;
72
72
  declare function isInteractionMode(value: unknown): value is InteractionMode;
73
73
 
74
+ type CatalogKeyColumn = "id" | "name";
75
+ declare function catalogKeyColumn(value: string): CatalogKeyColumn;
76
+
74
77
  /**
75
78
  * Normalizes legacy model control keys and prompt settings keys to their
76
79
  * current backend equivalents.
@@ -1808,4 +1811,4 @@ catalog?: SuccessionClient): Promise<NewAgentModel>;
1808
1811
  */
1809
1812
  declare function resolveModelMapKnob(value: unknown, catalog: SuccessionClient): Promise<Record<string, string>>;
1810
1813
 
1811
- export { type AdminOffering, type AdminPricingBand, type ArtifactUse, type AuditCapabilitiesRecord, CHAT_DEFAULT_MODEL_KNOB, CONTENT_TYPES, type CapabilitiesParseContext, type CatalogKindInput, type CatalogModel, type CatalogTier, type CheapestAdequateOptions, type CompatStatus, type ContentType, type CuratedCatalogClient, type CuratedModel, type CuratedPresentation, type CuratedRows, type CuratedVariant, DEFAULT_CAPABILITIES, type DecidedBy, type DeviceGraphics, type DeviceHardware, type DiscoveryAmbiguity, type DiscoveryArtifact, type DiscoveryMedia, type DiscoveryResult, type DiscoveryRuntime, type DiscoverySource, type DiscoveryVariant, EMPTY_MODEL_RECORDS, EXCLUDED_REVIEW_STATES, FEATURE_BUCKETS, FEATURE_BUCKET_ORDER, FEATURE_KEYS, FILE_TYPE_QUANT, type FeatureBucket, type FeatureBucketMeta, type FeatureKey, type FitCapabilities, GgufError, type GgufHeader, type GgufRead, type GgufTensor, type GroupedFeatures, type HardwareClass, type HardwareClasses, type HeaderFlag, type HeaderJudgement, type HeaderRefusal, INPUT_MODALITIES, INTERACTION_MODES, type Interaction, type InteractionMode, type LocalArtifact, type LocalCatalogClient, type LocalCatalogQuery, type LocalCompatRow, type LocalModel, type LocalModelCatalog, type LocalPresentation, type LocalRuntime, type LocalRuntimeBuild, type LocalVariant, MAX_SUCCESSION_HOPS, MODEL_CATALOG_KINDS, MODEL_FAVORITE_ENTITY_TYPE, type Modality, type ModelCapabilities, type ModelCatalog, type ModelCatalogClient, type ModelCatalogConfig, type ModelCatalogErrorSink, type ModelCatalogPgError, type ModelCatalogPgResult, type ModelCatalogQuery, type ModelCatalogState, type ModelCatalogVariant, type ModelCatalogVariantState, type ModelClassConfig, type ModelClassEntry, type ModelClassIndex, type ModelDiagnosticEntry, type ModelDiagnosticsSink, type ModelFavorites, type ModelFavoritesCache, type ModelFavoritesClient, type ModelFavoritesConfig, type ModelFavoritesErrorSink, type ModelFavoritesState, type ModelFetchScope, type ModelFileHandle, type ModelFit, type ModelIdentityRow, type ModelJson, type ModelNeed, type ModelOfferingRow, type ModelOption, type ModelOptionWithLifecycle, type ModelRecord, type ModelRecordFetchType, type ModelRecords, type ModelRecordsClient, type ModelRecordsConfig, type ModelRecordsState, type ModelSelectionPurpose, type ModelSetEnv, type ModelSetFacts, type ModelSetValidation, NEW_AGENT_DEFAULT_MODEL_KNOB, type NewAgentModel, type NoSelection, OUTPUT_MODALITIES, type OrderedLike, type PreferredModelChoice, type PreferredModelChoicePorts, type PriceTier, type PricedCatalogModel, type RankOptions, type RankedVariant, type ReadModelCatalogOptions, SERVICE_LABEL, SERVICE_LABEL_PLURAL, type SelectDevice, type Selection, type ShardName, type SuccessionClient, type SuccessionIndex, type SuccessionNode, TOP_TIER_COST_RATING, TOP_TIER_LOCKED_TITLE, type VariantDiscovery, type VariantVerdict, type Want, acceptsTextInstructions, blendedPrice, buildModelClassIndex, buildSuccessionIndex, catalogFingerprint, catalogForApp, catalogKindOf, cheapestAdequateModel, classConfigKey, collapseTiersByClass, costRatingTier, costRatingWord, createModelCatalog, createModelFavorites, createModelRecords, curatedList, displayOrderOf, favoriteIdsEqual, fetchCuratedModels, findNonCanonicalCapabilityValues, fitsMemory, fitsNeed, fitsThisComputer, formatMemoryBytes, fromDiscovery, ggufEngine, ggufFacts, groupFeatures, hardwareClassesOf, hasCompatibleDecisionInteraction, isChatModelCapability, isContentType, isConversationalModelCapability, isDecisionModelCapability, isFeatureKey, isHelperGguf, isInteractionMode, isListedVariant, isLocalModelCatalog, isManagedAgentModelCapability, isProjectorName, isSupersedable, isTopTierRating, judgeHeaderFacts, mergeAuditRecordIntoCapabilities, missingShards, modelClassKnobFor, modelClassName, modelClassPinOf, modelsForSelectionPurpose, normalizeArch, normalizeModel, normalizeModels, normalizeOs, normalizePromptSettings, orderCatalogGroups, orderCatalogModels, outputFormatControlKey, parseCapabilities, pickProjector, priceTierRating, quantFromName, rankVariants, readCuratedRows, readGgufHeader, readModelCatalog, reconcileModelFavoriteIds, reportModelDiagnostic, requireCanonicalCapabilities, requiredArtifacts, resetSuccessionLogForTests, resolveLiveModelId, resolveModelMapKnob, resolveNewAgentModelId, resolvePreferredModelChoice, resolveSuccessor, runtimesOnEngine, seesImages, selectActiveModels, selectActiveModelsReady, selectAllModelOptions, selectAllModels, selectAllModelsReady, selectDeprecatedModels, selectDeprecatedModelsReady, selectModelById, selectModelClassConfig, selectModelClassName, selectModelControls, selectModelDetailError, selectModelFetchType, selectModelFullyLoaded, selectModelIdentityById, selectModelIdentityLookupStatus, selectModelLabelById, selectModelLabelWithClass, selectModelNameById, selectModelOptions, selectVariant, serviceCountLabel, setModelDiagnosticsSink, shapeCuratedModels, shardFileName, shardName, speedRatingLabel, speedRatingWord, splitSetProblems, takesInput, toAuditRecord, validateModelSet, variantVerdict, withModelClass };
1814
+ export { type AdminOffering, type AdminPricingBand, type ArtifactUse, type AuditCapabilitiesRecord, CHAT_DEFAULT_MODEL_KNOB, CONTENT_TYPES, type CapabilitiesParseContext, type CatalogKeyColumn, type CatalogKindInput, type CatalogModel, type CatalogTier, type CheapestAdequateOptions, type CompatStatus, type ContentType, type CuratedCatalogClient, type CuratedModel, type CuratedPresentation, type CuratedRows, type CuratedVariant, DEFAULT_CAPABILITIES, type DecidedBy, type DeviceGraphics, type DeviceHardware, type DiscoveryAmbiguity, type DiscoveryArtifact, type DiscoveryMedia, type DiscoveryResult, type DiscoveryRuntime, type DiscoverySource, type DiscoveryVariant, EMPTY_MODEL_RECORDS, EXCLUDED_REVIEW_STATES, FEATURE_BUCKETS, FEATURE_BUCKET_ORDER, FEATURE_KEYS, FILE_TYPE_QUANT, type FeatureBucket, type FeatureBucketMeta, type FeatureKey, type FitCapabilities, GgufError, type GgufHeader, type GgufRead, type GgufTensor, type GroupedFeatures, type HardwareClass, type HardwareClasses, type HeaderFlag, type HeaderJudgement, type HeaderRefusal, INPUT_MODALITIES, INTERACTION_MODES, type Interaction, type InteractionMode, type LocalArtifact, type LocalCatalogClient, type LocalCatalogQuery, type LocalCompatRow, type LocalModel, type LocalModelCatalog, type LocalPresentation, type LocalRuntime, type LocalRuntimeBuild, type LocalVariant, MAX_SUCCESSION_HOPS, MODEL_CATALOG_KINDS, MODEL_FAVORITE_ENTITY_TYPE, type Modality, type ModelCapabilities, type ModelCatalog, type ModelCatalogClient, type ModelCatalogConfig, type ModelCatalogErrorSink, type ModelCatalogPgError, type ModelCatalogPgResult, type ModelCatalogQuery, type ModelCatalogState, type ModelCatalogVariant, type ModelCatalogVariantState, type ModelClassConfig, type ModelClassEntry, type ModelClassIndex, type ModelDiagnosticEntry, type ModelDiagnosticsSink, type ModelFavorites, type ModelFavoritesCache, type ModelFavoritesClient, type ModelFavoritesConfig, type ModelFavoritesErrorSink, type ModelFavoritesState, type ModelFetchScope, type ModelFileHandle, type ModelFit, type ModelIdentityRow, type ModelJson, type ModelNeed, type ModelOfferingRow, type ModelOption, type ModelOptionWithLifecycle, type ModelRecord, type ModelRecordFetchType, type ModelRecords, type ModelRecordsClient, type ModelRecordsConfig, type ModelRecordsState, type ModelSelectionPurpose, type ModelSetEnv, type ModelSetFacts, type ModelSetValidation, NEW_AGENT_DEFAULT_MODEL_KNOB, type NewAgentModel, type NoSelection, OUTPUT_MODALITIES, type OrderedLike, type PreferredModelChoice, type PreferredModelChoicePorts, type PriceTier, type PricedCatalogModel, type RankOptions, type RankedVariant, type ReadModelCatalogOptions, SERVICE_LABEL, SERVICE_LABEL_PLURAL, type SelectDevice, type Selection, type ShardName, type SuccessionClient, type SuccessionIndex, type SuccessionNode, TOP_TIER_COST_RATING, TOP_TIER_LOCKED_TITLE, type VariantDiscovery, type VariantVerdict, type Want, acceptsTextInstructions, blendedPrice, buildModelClassIndex, buildSuccessionIndex, catalogFingerprint, catalogForApp, catalogKeyColumn, catalogKindOf, cheapestAdequateModel, classConfigKey, collapseTiersByClass, costRatingTier, costRatingWord, createModelCatalog, createModelFavorites, createModelRecords, curatedList, displayOrderOf, favoriteIdsEqual, fetchCuratedModels, findNonCanonicalCapabilityValues, fitsMemory, fitsNeed, fitsThisComputer, formatMemoryBytes, fromDiscovery, ggufEngine, ggufFacts, groupFeatures, hardwareClassesOf, hasCompatibleDecisionInteraction, isChatModelCapability, isContentType, isConversationalModelCapability, isDecisionModelCapability, isFeatureKey, isHelperGguf, isInteractionMode, isListedVariant, isLocalModelCatalog, isManagedAgentModelCapability, isProjectorName, isSupersedable, isTopTierRating, judgeHeaderFacts, mergeAuditRecordIntoCapabilities, missingShards, modelClassKnobFor, modelClassName, modelClassPinOf, modelsForSelectionPurpose, normalizeArch, normalizeModel, normalizeModels, normalizeOs, normalizePromptSettings, orderCatalogGroups, orderCatalogModels, outputFormatControlKey, parseCapabilities, pickProjector, priceTierRating, quantFromName, rankVariants, readCuratedRows, readGgufHeader, readModelCatalog, reconcileModelFavoriteIds, reportModelDiagnostic, requireCanonicalCapabilities, requiredArtifacts, resetSuccessionLogForTests, resolveLiveModelId, resolveModelMapKnob, resolveNewAgentModelId, resolvePreferredModelChoice, resolveSuccessor, runtimesOnEngine, seesImages, selectActiveModels, selectActiveModelsReady, selectAllModelOptions, selectAllModels, selectAllModelsReady, selectDeprecatedModels, selectDeprecatedModelsReady, selectModelById, selectModelClassConfig, selectModelClassName, selectModelControls, selectModelDetailError, selectModelFetchType, selectModelFullyLoaded, selectModelIdentityById, selectModelIdentityLookupStatus, selectModelLabelById, selectModelLabelWithClass, selectModelNameById, selectModelOptions, selectVariant, serviceCountLabel, setModelDiagnosticsSink, shapeCuratedModels, shardFileName, shardName, speedRatingLabel, speedRatingWord, splitSetProblems, takesInput, toAuditRecord, validateModelSet, variantVerdict, withModelClass };
@@ -132,6 +132,12 @@ function isInteractionMode(value) {
132
132
  return typeof value === "string" && INTERACTION_MODES.includes(value);
133
133
  }
134
134
 
135
+ // models/catalog-key.ts
136
+ import { isUuidShape } from "@ai-matrx/kit/uuid";
137
+ function catalogKeyColumn(value) {
138
+ return isUuidShape(value.trim()) ? "id" : "name";
139
+ }
140
+
135
141
  // models/model-normalizer.ts
136
142
  var LEGACY_KEY_MAP = {
137
143
  max_tokens: "max_output_tokens",
@@ -631,7 +637,7 @@ function serviceCountLabel(count) {
631
637
  }
632
638
 
633
639
  // models/favorites.ts
634
- import { isUuidShape } from "@ai-matrx/kit/uuid";
640
+ import { isUuidShape as isUuidShape2 } from "@ai-matrx/kit/uuid";
635
641
  var MODEL_FAVORITE_ENTITY_TYPE = "ai_model";
636
642
  function reconcileModelFavoriteIds(cached, canonical) {
637
643
  const seen = /* @__PURE__ */ new Set();
@@ -679,7 +685,7 @@ function createModelFavorites(config) {
679
685
  };
680
686
  cache.subscribe?.(refresh);
681
687
  const writeCanonical = async (id, isFavorite) => {
682
- if (!isUuidShape(id)) {
688
+ if (!isUuidShape2(id)) {
683
689
  sink({ code: "model-favorite-not-a-uuid", message: "not a model uuid \u2014 skipped ues_set", context: { id } });
684
690
  return;
685
691
  }
@@ -849,7 +855,7 @@ function createModelRecords(config) {
849
855
  };
850
856
  async function readFullModel(modelId) {
851
857
  const relation = await isSignedIn() ? "model_config" : "model_public";
852
- const { data, error } = await ai().from(relation).select(MODEL_CONFIG_COLUMNS).eq("id", modelId).maybeSingle();
858
+ const { data, error } = await ai().from(relation).select(MODEL_CONFIG_COLUMNS).eq(catalogKeyColumn(modelId), modelId).maybeSingle();
853
859
  if (error) throw error;
854
860
  const row = data;
855
861
  if (!row) throw new Error(`AI model ${modelId} is not available (ai.${relation} has no such row)`);
@@ -902,7 +908,7 @@ function createModelRecords(config) {
902
908
  }
903
909
  for (const id of Object.keys(known.identityById)) {
904
910
  jobs.push(
905
- Promise.resolve(ai().from("model_definition").select("id, name, common_name, is_deprecated").eq("id", id).maybeSingle()).then(
911
+ Promise.resolve(ai().from("model_definition").select("id, name, common_name, is_deprecated").eq(catalogKeyColumn(id), id).maybeSingle()).then(
906
912
  ({ data, error }) => {
907
913
  if (error) throw error;
908
914
  if (data) update((s3) => ({ ...s3, identityById: { ...s3.identityById, [id]: data } }));
@@ -1132,14 +1138,14 @@ function createModelRecords(config) {
1132
1138
  return once(`identity:${modelId}`, async () => {
1133
1139
  update((s3) => ({ ...s3, identityStatusById: { ...s3.identityStatusById, [modelId]: "loading" } }));
1134
1140
  try {
1135
- const { data, error } = await ai().from("model_definition").select("id, name, common_name, is_deprecated").eq("id", modelId).maybeSingle();
1141
+ const { data, error } = await ai().from("model_definition").select("id, name, common_name, is_deprecated").eq(catalogKeyColumn(modelId), modelId).maybeSingle();
1136
1142
  if (error) throw error;
1137
1143
  if (!data) throw new Error(`AI model ${modelId} is not available (ai.model_definition has no such row)`);
1138
1144
  const row = data;
1139
1145
  update((s3) => ({
1140
1146
  ...s3,
1141
- identityById: { ...s3.identityById, [row.id]: row },
1142
- identityStatusById: { ...s3.identityStatusById, [row.id]: "succeeded" }
1147
+ identityById: { ...s3.identityById, [row.id]: row, [modelId]: row },
1148
+ identityStatusById: { ...s3.identityStatusById, [row.id]: "succeeded", [modelId]: "succeeded" }
1143
1149
  }));
1144
1150
  } catch (err) {
1145
1151
  errorSink({ code: "model-records-identity-failed", message: messageOf(err), context: { modelId } });
@@ -1652,8 +1658,9 @@ function resetSuccessionLogForTests() {
1652
1658
  async function resolveLiveModelId(client, modelId) {
1653
1659
  const index = /* @__PURE__ */ new Map();
1654
1660
  let want = modelId;
1661
+ let startId = modelId;
1655
1662
  for (let hop = 0; want && hop <= MAX_SUCCESSION_HOPS && !index.has(want); hop += 1) {
1656
- const { data, error } = await client.schema("ai").from("model_public").select("id, is_deprecated, retired_at, successor_id").in("id", [want]);
1663
+ const { data, error } = await client.schema("ai").from("model_public").select("id, is_deprecated, retired_at, successor_id").in(hop === 0 ? catalogKeyColumn(want) : "id", [want]);
1657
1664
  if (error) {
1658
1665
  console.warn(`[models/succession] ${modelId}: the catalog could not be read (${error.message}); keeping the model as given.`);
1659
1666
  return modelId;
@@ -1667,9 +1674,11 @@ async function resolveLiveModelId(client, modelId) {
1667
1674
  successorId: typeof row.successor_id === "string" ? row.successor_id : null
1668
1675
  };
1669
1676
  index.set(node.id, node);
1677
+ if (hop === 0) startId = node.id;
1670
1678
  want = isSupersedable(node) ? node.successorId : null;
1671
1679
  }
1672
- return resolveSuccessor(modelId, index);
1680
+ const resolved = resolveSuccessor(startId, index);
1681
+ return resolved === startId ? modelId : resolved;
1673
1682
  }
1674
1683
 
1675
1684
  // models/local.ts
@@ -2760,6 +2769,7 @@ export {
2760
2769
  buildSuccessionIndex,
2761
2770
  catalogFingerprint,
2762
2771
  catalogForApp,
2772
+ catalogKeyColumn,
2763
2773
  catalogKindOf,
2764
2774
  cheapestAdequateModel,
2765
2775
  classConfigKey,
@@ -282,11 +282,8 @@ function makeIcon(name) {
282
282
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Svg, { ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Shape, { name, filled: false }) });
283
283
  };
284
284
  }
285
- var ArrowUpDownIcon = makeIcon("arrowUpDown");
286
285
  var LoaderIcon = makeIcon("loader");
287
286
  var UsersIcon = makeIcon("users");
288
- var MessageCircleIcon = makeIcon("messageCircle");
289
- var RocketIcon = makeIcon("rocket");
290
287
  var CircleCheckIcon = makeIcon("circleCheck");
291
288
  var AlertTriangleIcon = makeIcon("alertTriangle");
292
289
  var Music4Icon = makeIcon("music4");
@@ -226,7 +226,7 @@ var ICON_PATHS = SHAPES;
226
226
  var ICON_NAMES = Object.keys(ICON_PATHS);
227
227
 
228
228
  // catalog/react/icons.tsx
229
- import { FolderIcon, RotateCcwIcon, TagIcon } from "@ai-matrx/design-system/icons";
229
+ import { ArrowUpDownIcon, FolderIcon, MessageCircleIcon, RocketIcon, RotateCcwIcon, TagIcon } from "@ai-matrx/design-system/icons";
230
230
  import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
231
231
  function Svg({ children, ...props }) {
232
232
  return /* @__PURE__ */ jsx2(
@@ -273,11 +273,8 @@ function makeIcon(name) {
273
273
  return /* @__PURE__ */ jsx2(Svg, { ...props, children: /* @__PURE__ */ jsx2(Shape, { name, filled: false }) });
274
274
  };
275
275
  }
276
- var ArrowUpDownIcon = makeIcon("arrowUpDown");
277
276
  var LoaderIcon = makeIcon("loader");
278
277
  var UsersIcon = makeIcon("users");
279
- var MessageCircleIcon = makeIcon("messageCircle");
280
- var RocketIcon = makeIcon("rocket");
281
278
  var CircleCheckIcon = makeIcon("circleCheck");
282
279
  var AlertTriangleIcon = makeIcon("alertTriangle");
283
280
  var Music4Icon = makeIcon("music4");
@@ -20,49 +20,205 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // quick/index.ts
21
21
  var quick_exports = {};
22
22
  __export(quick_exports, {
23
- QUICK_AGENT_BOUNDS: () => QUICK_AGENT_BOUNDS,
24
- QUICK_AGENT_DEFAULT_SETTINGS: () => QUICK_AGENT_DEFAULT_SETTINGS,
25
23
  QUICK_AGENT_KIND: () => QUICK_AGENT_KIND,
24
+ QUICK_AGENT_KNOBS: () => QUICK_AGENT_KNOBS,
26
25
  QUICK_AGENT_TAG: () => QUICK_AGENT_TAG,
27
- buildQuickAgentRow: () => buildQuickAgentRow,
28
- buildQuickAgentUpdate: () => buildQuickAgentUpdate,
29
26
  clampQuickAgentSettings: () => clampQuickAgentSettings,
30
- createQuickAgent: () => createQuickAgent,
31
- deleteQuickAgent: () => deleteQuickAgent,
27
+ defaultQuickAgentSettings: () => defaultQuickAgentSettings,
32
28
  isQuickAgentSummary: () => isQuickAgentSummary,
33
29
  listMyQuickAgents: () => listMyQuickAgents,
30
+ listQuickAgents: () => listQuickAgents,
31
+ quickAgentFields: () => quickAgentFields,
34
32
  quickAgentFromRow: () => quickAgentFromRow,
35
33
  quickAgentMessages: () => quickAgentMessages,
36
34
  quickAgentProblems: () => quickAgentProblems,
37
35
  quickAgentSettingsJson: () => quickAgentSettingsJson,
38
36
  readQuickAgent: () => readQuickAgent,
39
- updateQuickAgent: () => updateQuickAgent,
37
+ resolveQuickAgentLimits: () => resolveQuickAgentLimits,
38
+ sliderStep: () => sliderStep,
40
39
  withoutQuickAgents: () => withoutQuickAgents
41
40
  });
42
41
  module.exports = __toCommonJS(quick_exports);
43
42
 
43
+ // catalog/selectors.ts
44
+ function memoize1(fn) {
45
+ let lastA;
46
+ let last;
47
+ let has = false;
48
+ return (a) => {
49
+ if (!has || lastA !== a) {
50
+ last = fn(a);
51
+ lastA = a;
52
+ has = true;
53
+ }
54
+ return last;
55
+ };
56
+ }
57
+ function memoize2(fn) {
58
+ let lastA;
59
+ let lastB;
60
+ let last;
61
+ let has = false;
62
+ return (a, b) => {
63
+ if (!has || lastA !== a || lastB !== b) {
64
+ last = fn(a, b);
65
+ lastA = a;
66
+ lastB = b;
67
+ has = true;
68
+ }
69
+ return last;
70
+ };
71
+ }
72
+ var selectAllAgentCategories = memoize1(
73
+ (agents) => {
74
+ const cats = /* @__PURE__ */ new Set();
75
+ for (const a of agents) {
76
+ if (a.agentType === "user" && a.category) cats.add(a.category);
77
+ }
78
+ return Array.from(cats).sort();
79
+ }
80
+ );
81
+ var selectAllSystemAgentCategories = memoize1(
82
+ (agents) => {
83
+ const cats = /* @__PURE__ */ new Set();
84
+ for (const a of agents) {
85
+ if (a.agentType === "builtin" && a.category) cats.add(a.category);
86
+ }
87
+ return Array.from(cats).sort();
88
+ }
89
+ );
90
+ var selectAllAgentTags = memoize1(
91
+ (agents) => {
92
+ const tags = /* @__PURE__ */ new Set();
93
+ for (const a of agents) {
94
+ if (a.agentType === "user") a.tags?.forEach((t) => tags.add(t));
95
+ }
96
+ return Array.from(tags).sort();
97
+ }
98
+ );
99
+ var selectAllSystemAgentTags = memoize1(
100
+ (agents) => {
101
+ const tags = /* @__PURE__ */ new Set();
102
+ for (const a of agents) {
103
+ if (a.agentType === "builtin") a.tags?.forEach((t) => tags.add(t));
104
+ }
105
+ return Array.from(tags).sort();
106
+ }
107
+ );
108
+ var selectUserTypeAgents = memoize1(
109
+ (agents) => agents.filter((a) => a.agentType === "user")
110
+ );
111
+ var selectBuiltinTypeAgents = memoize1(
112
+ (agents) => agents.filter((a) => a.agentType === "builtin")
113
+ );
114
+ function agentMatchesArchiveFilter(agent, archFilter) {
115
+ if (archFilter === "active") return !agent.isArchived;
116
+ if (archFilter === "archived") return Boolean(agent.isArchived);
117
+ return true;
118
+ }
119
+ function countBuiltinRows(agents, archFilter) {
120
+ let n = 0;
121
+ for (const a of agents) {
122
+ if (a.agentType !== "builtin") continue;
123
+ if (!agentMatchesArchiveFilter(a, archFilter)) continue;
124
+ n += 1;
125
+ }
126
+ return n;
127
+ }
128
+ function countUserRows(agents, archFilter, predicate) {
129
+ let n = 0;
130
+ for (const a of agents) {
131
+ if (a.agentType !== "user") continue;
132
+ if (!agentMatchesArchiveFilter(a, archFilter)) continue;
133
+ if (predicate(a)) n += 1;
134
+ }
135
+ return n;
136
+ }
137
+ var isOwned = (a) => a.isOwner === true;
138
+ var isShared = (a) => a.isOwner === false && a.accessLevel != null;
139
+ var isAny = () => true;
140
+ var isFavorite = (a) => Boolean(a.isFavorite);
141
+ var selectAgentTabCounts = memoize2(
142
+ (agents, archFilter) => ({
143
+ mine: countUserRows(agents, archFilter, isOwned),
144
+ shared: countUserRows(agents, archFilter, isShared),
145
+ all: countUserRows(agents, archFilter, isAny),
146
+ system: countBuiltinRows(agents, archFilter)
147
+ })
148
+ );
149
+ var selectTotalUserAgentsCount = memoize1(
150
+ (agents) => countUserRows(agents, "active", isAny)
151
+ );
152
+ var selectTotalOwnedAgentsCount = memoize1(
153
+ (agents) => countUserRows(agents, "active", isOwned)
154
+ );
155
+ var selectTotalSharedAgentsCount = memoize1(
156
+ (agents) => countUserRows(agents, "active", isShared)
157
+ );
158
+ var selectTotalBuiltinAgentsCount = memoize1(
159
+ (agents) => countBuiltinRows(agents, "active")
160
+ );
161
+ var selectTotalFavoriteAgentsCount = memoize1(
162
+ (agents) => countUserRows(agents, "active", isFavorite)
163
+ );
164
+
44
165
  // quick/shape.ts
45
166
  var QUICK_AGENT_KIND = "quick";
46
167
  var QUICK_AGENT_TAG = "kind:quick";
47
- var QUICK_AGENT_BOUNDS = {
48
- temperature: { min: 0, max: 2, step: 0.1 },
49
- topP: { min: 0, max: 1, step: 0.05 },
50
- maxOutputTokens: { min: 256, max: 32768, step: 256 }
168
+ var QUICK_AGENT_KNOBS = {
169
+ temperatureMax: { feature: "agents.quick", key: "temperature_max" },
170
+ temperatureDefault: { feature: "agents.quick", key: "temperature_default" },
171
+ topPDefault: { feature: "agents.quick", key: "top_p_default" },
172
+ maxOutputMin: { feature: "agents.quick", key: "max_output_min" },
173
+ maxOutputMax: { feature: "agents.quick", key: "max_output_max" },
174
+ maxOutputDefault: { feature: "agents.quick", key: "max_output_default" }
51
175
  };
52
- var QUICK_AGENT_DEFAULT_SETTINGS = Object.freeze({
53
- temperature: 0.7,
54
- topP: 1,
55
- maxOutputTokens: 4096
56
- });
176
+ var isNum = (v) => typeof v === "number" && Number.isFinite(v);
177
+ function sliderStep(min, max) {
178
+ const raw = (max - min) / 100;
179
+ if (!(raw > 0)) return 1;
180
+ const pow = 10 ** Math.floor(Math.log10(raw));
181
+ const unit = raw / pow;
182
+ const nice = unit <= 1 ? 1 : unit <= 2 ? 2 : unit <= 5 ? 5 : 10;
183
+ return Number((nice * pow).toPrecision(6));
184
+ }
185
+ function limit(min, max, rest, whole) {
186
+ const step = whole ? Math.max(1, Math.round(sliderStep(min, max))) : sliderStep(min, max);
187
+ return { min, max, step, default: Math.min(max, Math.max(min, rest)) };
188
+ }
189
+ function resolveQuickAgentLimits(model, knobs) {
190
+ const t = model?.temperature;
191
+ const p = model?.top_p;
192
+ const m = model?.max_output_tokens;
193
+ const tMin = isNum(t?.min) ? t.min : 0;
194
+ const tMax = isNum(t?.max) ? t.max : knobs.temperatureMax;
195
+ const tRest = isNum(t?.default) ? t.default : knobs.temperatureDefault;
196
+ const pMin = isNum(p?.min) ? p.min : 0;
197
+ const pMax = isNum(p?.max) ? p.max : 1;
198
+ const pRest = isNum(p?.default) ? p.default : knobs.topPDefault;
199
+ const mMin = isNum(m?.min) ? m.min : knobs.maxOutputMin;
200
+ const mMax = isNum(m?.max) ? m.max : knobs.maxOutputMax;
201
+ const mRest = isNum(m?.default) ? m.default : knobs.maxOutputDefault;
202
+ if (!isNum(tMax) || !isNum(tRest) || !isNum(pRest) || !isNum(mMin) || !isNum(mMax) || !isNum(mRest)) return null;
203
+ if (tMax <= tMin || pMax <= pMin || mMax <= mMin) return null;
204
+ return {
205
+ temperature: limit(tMin, tMax, tRest, false),
206
+ topP: limit(pMin, pMax, pRest, false),
207
+ maxOutputTokens: limit(mMin, mMax, mRest, true)
208
+ };
209
+ }
210
+ function defaultQuickAgentSettings(limits) {
211
+ return { temperature: limits.temperature.default, topP: limits.topP.default, maxOutputTokens: limits.maxOutputTokens.default };
212
+ }
57
213
  function clamp(value, bound) {
58
214
  if (!Number.isFinite(value)) return bound.min;
59
215
  return Math.min(bound.max, Math.max(bound.min, value));
60
216
  }
61
- function clampQuickAgentSettings(settings) {
217
+ function clampQuickAgentSettings(settings, limits) {
62
218
  return {
63
- temperature: clamp(settings.temperature, QUICK_AGENT_BOUNDS.temperature),
64
- topP: clamp(settings.topP, QUICK_AGENT_BOUNDS.topP),
65
- maxOutputTokens: Math.round(clamp(settings.maxOutputTokens, QUICK_AGENT_BOUNDS.maxOutputTokens))
219
+ temperature: clamp(settings.temperature, limits.temperature),
220
+ topP: clamp(settings.topP, limits.topP),
221
+ maxOutputTokens: Math.round(clamp(settings.maxOutputTokens, limits.maxOutputTokens))
66
222
  };
67
223
  }
68
224
  function quickAgentProblems(def) {
@@ -73,44 +229,31 @@ function quickAgentProblems(def) {
73
229
  return problems;
74
230
  }
75
231
  function quickAgentSettingsJson(settings) {
76
- const s = clampQuickAgentSettings(settings);
77
- return { stream: true, temperature: s.temperature, top_p: s.topP, max_output_tokens: s.maxOutputTokens };
232
+ return { stream: true, temperature: settings.temperature, top_p: settings.topP, max_output_tokens: settings.maxOutputTokens };
78
233
  }
79
234
  function quickAgentMessages(systemPrompt) {
80
235
  return [{ role: "system", content: [{ type: "text", text: systemPrompt }] }];
81
236
  }
82
- function buildQuickAgentRow(def, owner) {
237
+ function quickAgentFields(def) {
83
238
  return {
84
- agent_type: "user",
85
239
  name: def.name.trim(),
86
- description: null,
87
240
  tags: [QUICK_AGENT_TAG],
88
- is_active: true,
89
- is_archived: false,
90
- model_id: def.modelId,
241
+ isActive: true,
242
+ isArchived: false,
243
+ modelId: def.modelId,
91
244
  messages: quickAgentMessages(def.systemPrompt),
92
245
  settings: quickAgentSettingsJson(def.settings),
93
- tools: [],
94
- metadata: { kind: QUICK_AGENT_KIND },
95
- created_by: owner.userId,
96
- organization_id: owner.organizationId
97
- };
98
- }
99
- function buildQuickAgentUpdate(def) {
100
- return {
101
- name: def.name.trim(),
102
- model_id: def.modelId,
103
- messages: quickAgentMessages(def.systemPrompt),
104
- settings: quickAgentSettingsJson(def.settings)
246
+ tools: []
105
247
  };
106
248
  }
107
249
  function num(value, fallback) {
108
250
  return typeof value === "number" && Number.isFinite(value) ? value : fallback;
109
251
  }
110
- function quickAgentFromRow(row) {
252
+ function quickAgentFromRow(row, defaults) {
111
253
  if (!row) return null;
112
254
  const metadata = row["metadata"];
113
- if (metadata?.["kind"] !== QUICK_AGENT_KIND) return null;
255
+ const tags = Array.isArray(row["tags"]) ? row["tags"] : [];
256
+ if (metadata?.["kind"] !== QUICK_AGENT_KIND && !tags.includes(QUICK_AGENT_TAG)) return null;
114
257
  const messages = Array.isArray(row["messages"]) ? row["messages"] : [];
115
258
  const system = messages.find((m) => m["role"] === "system");
116
259
  const parts = Array.isArray(system?.["content"]) ? system?.["content"] : [];
@@ -121,55 +264,35 @@ function quickAgentFromRow(row) {
121
264
  name: typeof row["name"] === "string" ? row["name"] : "",
122
265
  systemPrompt,
123
266
  modelId: typeof row["model_id"] === "string" ? row["model_id"] : "",
124
- settings: clampQuickAgentSettings({
125
- temperature: num(raw["temperature"], QUICK_AGENT_DEFAULT_SETTINGS.temperature),
126
- topP: num(raw["top_p"], QUICK_AGENT_DEFAULT_SETTINGS.topP),
127
- maxOutputTokens: num(raw["max_output_tokens"], QUICK_AGENT_DEFAULT_SETTINGS.maxOutputTokens)
128
- })
267
+ settings: {
268
+ temperature: num(raw["temperature"], defaults.temperature),
269
+ topP: num(raw["top_p"], defaults.topP),
270
+ maxOutputTokens: num(raw["max_output_tokens"], defaults.maxOutputTokens)
271
+ }
129
272
  };
130
273
  }
131
274
  function isQuickAgentSummary(row) {
132
275
  return row.tags.includes(QUICK_AGENT_TAG);
133
276
  }
277
+ function listQuickAgents(rows, userId) {
278
+ const live = (row) => isQuickAgentSummary(row) && !row.isArchived && row.isActive !== false;
279
+ const user = selectUserTypeAgents(rows).filter(live);
280
+ const mine = userId ? user.filter((row) => row.createdBy === userId) : [];
281
+ const organization = user.filter((row) => !mine.includes(row));
282
+ const system = selectBuiltinTypeAgents(rows).filter(live);
283
+ return { mine, organization, system };
284
+ }
134
285
  function listMyQuickAgents(rows, userId) {
135
- if (!userId) return [];
136
- return rows.filter((row) => isQuickAgentSummary(row) && row.createdBy === userId && !row.isArchived && row.isActive !== false);
286
+ const lanes = listQuickAgents(rows, userId);
287
+ return [...lanes.mine, ...lanes.organization, ...lanes.system];
137
288
  }
138
289
  function withoutQuickAgents(rows) {
139
290
  return rows.filter((row) => !isQuickAgentSummary(row));
140
291
  }
141
292
 
142
- // quick/writes.ts
143
- function refuse(def) {
144
- const problems = quickAgentProblems(def);
145
- if (problems.length > 0) throw new Error(problems[0]);
146
- }
147
- function fail(error) {
148
- throw new Error(error?.message ?? "The agent could not be saved.");
149
- }
150
- var table = (client) => client.schema("agent").from("definition");
151
- async function createQuickAgent(client, def, owner) {
152
- refuse(def);
153
- const { data, error } = await table(client).insert(buildQuickAgentRow(def, owner)).select().single();
154
- if (error) fail(error);
155
- const saved = quickAgentFromRow(data);
156
- if (!saved) fail(null);
157
- return saved;
158
- }
159
- async function updateQuickAgent(client, id, def) {
160
- refuse(def);
161
- const { data, error } = await table(client).update(buildQuickAgentUpdate(def)).eq("id", id).select().single();
162
- if (error) fail(error);
163
- const saved = quickAgentFromRow(data);
164
- if (!saved) fail(null);
165
- return saved;
166
- }
167
- async function deleteQuickAgent(client, id) {
168
- const { error } = await table(client).update({ deleted_at: (/* @__PURE__ */ new Date()).toISOString() }).eq("id", id);
169
- if (error) fail(error);
170
- }
171
- async function readQuickAgent(client, id) {
172
- const { data, error } = await table(client).select("id,name,model_id,messages,settings,metadata").eq("id", id).is("deleted_at", null).maybeSingle();
173
- if (error) fail(error);
174
- return quickAgentFromRow(data);
293
+ // quick/reads.ts
294
+ async function readQuickAgent(client, id, defaults) {
295
+ const { data, error } = await client.schema("agent").from("definition").select("id,name,model_id,messages,settings,tags,metadata").eq("id", id).is("deleted_at", null).maybeSingle();
296
+ if (error) throw new Error(error.message ?? "The agent could not be read.");
297
+ return quickAgentFromRow(data, defaults);
175
298
  }