@happyvertical/smrt-inference 0.0.0-stage → 0.60.15
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.
- package/AGENTS.md +201 -0
- package/CLAUDE.md +1 -0
- package/LICENSE +7 -0
- package/README.md +73 -2
- package/agents/fusions.md +92 -0
- package/agents/hosted.md +145 -0
- package/agents/resolver.md +65 -0
- package/agents/settings.md +84 -0
- package/dist/__smrt-register__.d.ts +2 -0
- package/dist/__smrt-register__.d.ts.map +1 -0
- package/dist/chunks/InferenceOverrideCollection-wl7sI-3C.js +398 -0
- package/dist/chunks/InferenceOverrideCollection-wl7sI-3C.js.map +1 -0
- package/dist/chunks/provider-config-4Bx8N52X.js +1847 -0
- package/dist/chunks/provider-config-4Bx8N52X.js.map +1 -0
- package/dist/classify.d.ts +32 -0
- package/dist/classify.d.ts.map +1 -0
- package/dist/config.d.ts +89 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/errors.d.ts +51 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/executor.d.ts +45 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/fusion-store.d.ts +16 -0
- package/dist/fusion-store.d.ts.map +1 -0
- package/dist/fusion.d.ts +155 -0
- package/dist/fusion.d.ts.map +1 -0
- package/dist/gate.d.ts +143 -0
- package/dist/gate.d.ts.map +1 -0
- package/dist/gate.js +94 -0
- package/dist/gate.js.map +1 -0
- package/dist/hosted.d.ts +454 -0
- package/dist/hosted.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.json +453 -0
- package/dist/models/InferenceOverride.d.ts +38 -0
- package/dist/models/InferenceOverride.d.ts.map +1 -0
- package/dist/models/InferenceOverrideCollection.d.ts +35 -0
- package/dist/models/InferenceOverrideCollection.d.ts.map +1 -0
- package/dist/models.d.ts +11 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +2 -0
- package/dist/node.d.ts +110 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +1361 -0
- package/dist/node.js.map +1 -0
- package/dist/provider-config.d.ts +113 -0
- package/dist/provider-config.d.ts.map +1 -0
- package/dist/register.d.ts +30 -0
- package/dist/register.d.ts.map +1 -0
- package/dist/resolver.d.ts +166 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +288 -0
- package/dist/resolver.js.map +1 -0
- package/dist/server.d.ts +24 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +985 -0
- package/dist/server.js.map +1 -0
- package/dist/settings/cache.d.ts +5 -0
- package/dist/settings/cache.d.ts.map +1 -0
- package/dist/settings/keys.d.ts +70 -0
- package/dist/settings/keys.d.ts.map +1 -0
- package/dist/settings/layers.d.ts +54 -0
- package/dist/settings/layers.d.ts.map +1 -0
- package/dist/settings/override-service.d.ts +119 -0
- package/dist/settings/override-service.d.ts.map +1 -0
- package/dist/settings/preferences.d.ts +137 -0
- package/dist/settings/preferences.d.ts.map +1 -0
- package/dist/settings/resolver.d.ts +34 -0
- package/dist/settings/resolver.d.ts.map +1 -0
- package/dist/settings/settings-service.d.ts +282 -0
- package/dist/settings/settings-service.d.ts.map +1 -0
- package/dist/settings/targets.d.ts +93 -0
- package/dist/settings/targets.d.ts.map +1 -0
- package/dist/smrt-knowledge.json +335 -0
- package/dist/smrt-knowledge.okf.md +80 -0
- package/dist/svelte/components/InferenceAliasEditor.svelte +210 -0
- package/dist/svelte/components/InferenceAliasEditor.svelte.d.ts +13 -0
- package/dist/svelte/components/InferenceAliasEditor.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InferenceDefaultView.svelte +330 -0
- package/dist/svelte/components/InferenceDefaultView.svelte.d.ts +15 -0
- package/dist/svelte/components/InferenceDefaultView.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InferenceFusionList.svelte +135 -0
- package/dist/svelte/components/InferenceFusionList.svelte.d.ts +16 -0
- package/dist/svelte/components/InferenceFusionList.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InferenceSettingsPanel.svelte +345 -0
- package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts +65 -0
- package/dist/svelte/components/InferenceSettingsPanel.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InferenceTierRow.svelte +199 -0
- package/dist/svelte/components/InferenceTierRow.svelte.d.ts +14 -0
- package/dist/svelte/components/InferenceTierRow.svelte.d.ts.map +1 -0
- package/dist/svelte/components/InferenceUsageTable.svelte +127 -0
- package/dist/svelte/components/InferenceUsageTable.svelte.d.ts +15 -0
- package/dist/svelte/components/InferenceUsageTable.svelte.d.ts.map +1 -0
- package/dist/svelte/index.d.ts +17 -0
- package/dist/svelte/index.d.ts.map +1 -0
- package/dist/svelte/index.js +14 -0
- package/dist/svelte/types.d.ts +197 -0
- package/dist/svelte/types.d.ts.map +1 -0
- package/dist/svelte/types.js +96 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/package.json +105 -3
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User inference choices as the smrt-preferences kind `inference` (#4754):
|
|
3
|
+
* mode, provider, base URL, model and default tier, at the tenant default
|
|
4
|
+
* and per user. Never a key: the validator refuses credential-shaped members
|
|
5
|
+
* (keys go to smrt-secrets through the host).
|
|
6
|
+
*
|
|
7
|
+
* smrt-preferences is not a dependency: the kind is a plain definition the
|
|
8
|
+
* host registers with `registerPreferenceKind(inferencePreferenceKind)` (and
|
|
9
|
+
* the two permissions with smrt-users' `registerPermissionDefinitions`), and
|
|
10
|
+
* {@link createInferencePreferences} takes the store structurally.
|
|
11
|
+
*/
|
|
12
|
+
import { type InferenceTier } from '@happyvertical/smrt-core';
|
|
13
|
+
import { type InferenceMode } from './targets.js';
|
|
14
|
+
export declare const INFERENCE_PREFERENCE_KIND = "inference";
|
|
15
|
+
/** Default surface id: one inference choice per tenant and user. */
|
|
16
|
+
export declare const INFERENCE_PREFERENCE_SURFACE = "default";
|
|
17
|
+
/** Authorizes changing the tenant's default inference choices. */
|
|
18
|
+
export declare const CUSTOMIZE_INFERENCE_PERMISSION = "inference.customize";
|
|
19
|
+
/** Authorizes a user to keep their own inference choices. */
|
|
20
|
+
export declare const PERSONALIZE_INFERENCE_PERMISSION = "inference.personalize";
|
|
21
|
+
/** For smrt-users' `registerPermissionDefinitions()`. */
|
|
22
|
+
export declare const INFERENCE_PERMISSION_DEFINITIONS: readonly [{
|
|
23
|
+
readonly slug: "inference.customize";
|
|
24
|
+
readonly category: "inference";
|
|
25
|
+
readonly name: "Customize Inference";
|
|
26
|
+
readonly description: "Change the default inference mode, provider and model everyone in the tenant uses";
|
|
27
|
+
}, {
|
|
28
|
+
readonly slug: "inference.personalize";
|
|
29
|
+
readonly category: "inference";
|
|
30
|
+
readonly name: "Personalize Inference";
|
|
31
|
+
readonly description: "Keep a personal inference mode, provider and model on top of the tenant default";
|
|
32
|
+
}];
|
|
33
|
+
/** The `inference` preference payload. Every member is optional. */
|
|
34
|
+
export interface InferencePreferences {
|
|
35
|
+
mode?: InferenceMode;
|
|
36
|
+
provider?: string;
|
|
37
|
+
baseUrl?: string;
|
|
38
|
+
model?: string;
|
|
39
|
+
defaultTier?: InferenceTier;
|
|
40
|
+
}
|
|
41
|
+
/** Structural copy of smrt-preferences' issue shape. */
|
|
42
|
+
export interface InferencePreferenceIssue {
|
|
43
|
+
path: string | null;
|
|
44
|
+
code: string;
|
|
45
|
+
message: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Validate an `inference` payload: unknown or invalid members are removed
|
|
49
|
+
* and reported, credential-shaped members refuse the whole payload.
|
|
50
|
+
*/
|
|
51
|
+
export declare function validateInferencePreferences(payload: unknown): {
|
|
52
|
+
ok: boolean;
|
|
53
|
+
canonical: InferencePreferences | null;
|
|
54
|
+
issues: InferencePreferenceIssue[];
|
|
55
|
+
};
|
|
56
|
+
/** The kind definition for smrt-preferences' `registerPreferenceKind()`. */
|
|
57
|
+
export declare const inferencePreferenceKind: {
|
|
58
|
+
kind: string;
|
|
59
|
+
formatVersion: number;
|
|
60
|
+
permissions: {
|
|
61
|
+
tenant: string;
|
|
62
|
+
user: string;
|
|
63
|
+
};
|
|
64
|
+
validate(payload: unknown): {
|
|
65
|
+
ok: boolean;
|
|
66
|
+
canonical: InferencePreferences | null;
|
|
67
|
+
issues: InferencePreferenceIssue[];
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
type WriteResult = {
|
|
71
|
+
ok: true;
|
|
72
|
+
revision?: string | null;
|
|
73
|
+
[extra: string]: unknown;
|
|
74
|
+
} | {
|
|
75
|
+
ok: false;
|
|
76
|
+
reason: string;
|
|
77
|
+
[extra: string]: unknown;
|
|
78
|
+
};
|
|
79
|
+
/** The slice of smrt-preferences' `PreferenceStore` this layer uses. */
|
|
80
|
+
export interface InferencePreferenceStoreLike {
|
|
81
|
+
load(kind: string, surfaceId: string): Promise<{
|
|
82
|
+
tenant: {
|
|
83
|
+
payload: unknown;
|
|
84
|
+
revision: string | null;
|
|
85
|
+
};
|
|
86
|
+
user?: {
|
|
87
|
+
payload: unknown;
|
|
88
|
+
revision: string | null;
|
|
89
|
+
} | null;
|
|
90
|
+
issues: InferencePreferenceIssue[];
|
|
91
|
+
canCustomize: {
|
|
92
|
+
tenant: boolean;
|
|
93
|
+
user: boolean;
|
|
94
|
+
};
|
|
95
|
+
}>;
|
|
96
|
+
save(kind: string, surfaceId: string, input: {
|
|
97
|
+
scope: 'tenant' | 'user';
|
|
98
|
+
payload: unknown;
|
|
99
|
+
revision: string | null;
|
|
100
|
+
}): Promise<WriteResult>;
|
|
101
|
+
reset(kind: string, surfaceId: string, input: {
|
|
102
|
+
scope: 'tenant' | 'user';
|
|
103
|
+
revision?: string | null;
|
|
104
|
+
}): Promise<WriteResult>;
|
|
105
|
+
}
|
|
106
|
+
/** What a settings screen reads. */
|
|
107
|
+
export interface InferencePreferenceRead {
|
|
108
|
+
/** Tenant default with the user's choices on top (member by member). */
|
|
109
|
+
choices: InferencePreferences;
|
|
110
|
+
tenant: InferencePreferences | null;
|
|
111
|
+
user: InferencePreferences | null;
|
|
112
|
+
revisions: {
|
|
113
|
+
tenant: string | null;
|
|
114
|
+
user: string | null;
|
|
115
|
+
};
|
|
116
|
+
issues: InferencePreferenceIssue[];
|
|
117
|
+
canCustomize: {
|
|
118
|
+
tenant: boolean;
|
|
119
|
+
user: boolean;
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/** Read and write the `inference` preference over a preference store. */
|
|
123
|
+
export declare function createInferencePreferences(store: InferencePreferenceStoreLike, surfaceId?: string): {
|
|
124
|
+
read(): Promise<InferencePreferenceRead>;
|
|
125
|
+
/** Save choices at a scope (default `user`); `revision` is the one the client loaded. */
|
|
126
|
+
write(choices: InferencePreferences, options: {
|
|
127
|
+
scope?: "tenant" | "user";
|
|
128
|
+
revision: string | null;
|
|
129
|
+
}): Promise<WriteResult>;
|
|
130
|
+
reset(options?: {
|
|
131
|
+
scope?: "tenant" | "user";
|
|
132
|
+
revision?: string | null;
|
|
133
|
+
}): Promise<WriteResult>;
|
|
134
|
+
};
|
|
135
|
+
export type InferencePreferencesApi = ReturnType<typeof createInferencePreferences>;
|
|
136
|
+
export {};
|
|
137
|
+
//# sourceMappingURL=preferences.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preferences.d.ts","sourceRoot":"","sources":["../../src/settings/preferences.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAGL,KAAK,aAAa,EACnB,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,yBAAyB,cAAc,CAAC;AAErD,oEAAoE;AACpE,eAAO,MAAM,4BAA4B,YAAY,CAAC;AAEtD,kEAAkE;AAClE,eAAO,MAAM,8BAA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IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;CAClD;AAED,yEAAyE;AACzE,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,4BAA4B,EACnC,SAAS,GAAE,MAAqC;YAGhC,OAAO,CAAC,uBAAuB,CAAC;IAkB9C,yFAAyF;mBAE9E,oBAAoB,WACpB;QAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAC9D,OAAO,CAAC,WAAW,CAAC;oBASZ;QAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAC/D,OAAO,CAAC,WAAW,CAAC;EAO1B;AAED,MAAM,MAAM,uBAAuB,GAAG,UAAU,CAC9C,OAAO,0BAA0B,CAClC,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An `InferenceResolver` that applies the stored app and tenant bindings
|
|
3
|
+
* (#4754) at call time: config < app row < allowed tenant row. A tier with
|
|
4
|
+
* no stored binding defers to `base` (another resolver, e.g. #4756's
|
|
5
|
+
* per-user one) or to core's built-in config resolution, so an empty table
|
|
6
|
+
* changes nothing.
|
|
7
|
+
*
|
|
8
|
+
* Aliases defined only in app rows are not visible to the executor (it reads
|
|
9
|
+
* the process config), so a stored binding to such an alias is returned as
|
|
10
|
+
* the alias's inline candidate chain, expanded recursively; aliases that the
|
|
11
|
+
* config defines stay references.
|
|
12
|
+
*/
|
|
13
|
+
import { type InferenceResolver, type SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
14
|
+
import { InferenceOverrideCollection } from '../models/InferenceOverrideCollection.js';
|
|
15
|
+
import type { InferenceTenantTargetPolicy } from './override-service.js';
|
|
16
|
+
/** Options for {@link createInferenceOverrideResolver}. */
|
|
17
|
+
export interface InferenceOverrideResolverOptions {
|
|
18
|
+
/** Database options for the override collection (list bounds are stripped). */
|
|
19
|
+
db?: SmrtClassOptions;
|
|
20
|
+
/** An existing collection instead of `db`. */
|
|
21
|
+
overrides?: InferenceOverrideCollection;
|
|
22
|
+
/** Resolver to defer to for tiers with no stored binding. */
|
|
23
|
+
base?: InferenceResolver;
|
|
24
|
+
/** The code half of the tenant allow-list (same hook as the settings service). */
|
|
25
|
+
tenantTargetPolicy?: InferenceTenantTargetPolicy;
|
|
26
|
+
/**
|
|
27
|
+
* How long a tenant's layers are reused, ms. Default 30 000. Any write in
|
|
28
|
+
* this process invalidates immediately; other processes see it after TTL.
|
|
29
|
+
*/
|
|
30
|
+
ttlMs?: number;
|
|
31
|
+
}
|
|
32
|
+
/** See the module doc. */
|
|
33
|
+
export declare function createInferenceOverrideResolver(options?: InferenceOverrideResolverOptions): InferenceResolver;
|
|
34
|
+
//# sourceMappingURL=resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/settings/resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAGL,KAAK,iBAAiB,EAKtB,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0CAA0C,CAAC;AAQvF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAEzE,2DAA2D;AAC3D,MAAM,WAAW,gCAAgC;IAC/C,+EAA+E;IAC/E,EAAE,CAAC,EAAE,gBAAgB,CAAC;IACtB,8CAA8C;IAC9C,SAAS,CAAC,EAAE,2BAA2B,CAAC;IACxC,6DAA6D;IAC7D,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,kFAAkF;IAClF,kBAAkB,CAAC,EAAE,2BAA2B,CAAC;IACjD;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AA0BD,0BAA0B;AAC1B,wBAAgB,+BAA+B,CAC7C,OAAO,GAAE,gCAAqC,GAC7C,iBAAiB,CAqFnB"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { type AiUsageReport, type AiUsageReportDimension, type InferenceAlias, type InferenceCandidate, type InferenceConfig, type InferenceTarget, type InferenceTier, type SmrtClassOptions } from '@happyvertical/smrt-core';
|
|
2
|
+
import { InferenceOverrideCollection, type InferenceOverrideScopeType } from '../models/InferenceOverrideCollection.js';
|
|
3
|
+
import { type InferenceDoctorReport } from '../node.js';
|
|
4
|
+
import type { InferenceConfigIssue } from '../types.js';
|
|
5
|
+
import { type InferenceKeyRecord } from './keys.js';
|
|
6
|
+
import { type InferenceSettingsConfig } from './layers.js';
|
|
7
|
+
import { type InferenceOverrideAuthorizer, type InferenceTenantTargetPolicy } from './override-service.js';
|
|
8
|
+
import { DEFAULT_TIER_BINDING } from './targets.js';
|
|
9
|
+
/** Which level supplied an effective value. */
|
|
10
|
+
export type InferenceSettingsLevel = 'default' | 'config' | 'app' | 'tenant';
|
|
11
|
+
/** One tier, rendered for a settings screen. */
|
|
12
|
+
export interface InferenceTierSettingsRow {
|
|
13
|
+
binding: `tier:${InferenceTier}`;
|
|
14
|
+
tier: InferenceTier;
|
|
15
|
+
/** What the tier resolves to for the requested tenant; `null` is the configured client. */
|
|
16
|
+
effectiveTarget: InferenceTarget | null;
|
|
17
|
+
effectiveLabel: string;
|
|
18
|
+
supplyingLevel: InferenceSettingsLevel;
|
|
19
|
+
/** The `inference` config's binding (code default + config files + env). */
|
|
20
|
+
configTarget: InferenceTarget | null;
|
|
21
|
+
/** The app row's raw value, `null` when none. */
|
|
22
|
+
appTarget: InferenceTarget | null;
|
|
23
|
+
/**
|
|
24
|
+
* The tenant row's raw value, `null` when none or no tenant was requested.
|
|
25
|
+
* Present even when {@link tenantBlocked}: the screen shows why it is not
|
|
26
|
+
* in effect.
|
|
27
|
+
*/
|
|
28
|
+
tenantTarget: InferenceTarget | null;
|
|
29
|
+
/** What reverting the **app** scope produces: the config binding. */
|
|
30
|
+
appRevertTarget: InferenceTarget | null;
|
|
31
|
+
appRevertLabel: string;
|
|
32
|
+
/**
|
|
33
|
+
* What reverting the **tenant** scope produces: config plus the app row.
|
|
34
|
+
* `null` label when no tenant was requested (nothing computed it).
|
|
35
|
+
*/
|
|
36
|
+
inheritedTarget: InferenceTarget | null;
|
|
37
|
+
inheritedLabel: string | null;
|
|
38
|
+
/** The tenant allow-list on the app row (`null`: tenants may bind nothing). */
|
|
39
|
+
tenantAllowList: string[] | null;
|
|
40
|
+
/** A tenant row exists but the allow-list or policy refuses it now. */
|
|
41
|
+
tenantBlocked: boolean;
|
|
42
|
+
}
|
|
43
|
+
/** `auto`'s default tier, rendered for a settings screen. */
|
|
44
|
+
export interface InferenceDefaultTierSetting {
|
|
45
|
+
binding: typeof DEFAULT_TIER_BINDING;
|
|
46
|
+
effectiveTier: InferenceTier;
|
|
47
|
+
supplyingLevel: InferenceSettingsLevel;
|
|
48
|
+
configTier: InferenceTier | null;
|
|
49
|
+
appTier: InferenceTier | null;
|
|
50
|
+
tenantTier: InferenceTier | null;
|
|
51
|
+
/** What reverting the app scope produces (config, else `good`). */
|
|
52
|
+
appRevertTier: InferenceTier;
|
|
53
|
+
/** What reverting the tenant scope produces; `null` when no tenant was requested. */
|
|
54
|
+
inheritedTier: InferenceTier | null;
|
|
55
|
+
tenantAllowList: string[] | null;
|
|
56
|
+
tenantBlocked: boolean;
|
|
57
|
+
}
|
|
58
|
+
/** One alias for the alias editor. */
|
|
59
|
+
export interface InferenceAliasSetting {
|
|
60
|
+
name: string;
|
|
61
|
+
/** Where the effective definition comes from (an app row replaces config whole). */
|
|
62
|
+
source: 'config' | 'app';
|
|
63
|
+
candidates: InferenceCandidate[];
|
|
64
|
+
description?: string;
|
|
65
|
+
/** True when config also defines it (reverting the app row restores that). */
|
|
66
|
+
inConfig: boolean;
|
|
67
|
+
}
|
|
68
|
+
/** One fusion for the fusion list (#4753 owns their meaning). */
|
|
69
|
+
export interface InferenceFusionSetting {
|
|
70
|
+
name: string;
|
|
71
|
+
source: 'registry' | 'config' | 'app';
|
|
72
|
+
/** The definition as JSON-safe data. */
|
|
73
|
+
definition: Record<string, unknown>;
|
|
74
|
+
description?: string;
|
|
75
|
+
/** Config entries (app rows) can be edited as JSON; registry fusions are code. */
|
|
76
|
+
editable: boolean;
|
|
77
|
+
}
|
|
78
|
+
/** One provider choice for the default view. */
|
|
79
|
+
export interface InferenceProviderOption {
|
|
80
|
+
id: string;
|
|
81
|
+
label: string;
|
|
82
|
+
/** `preset` (#4674 endpoint presets) or `provider` (the AI SDK list). */
|
|
83
|
+
kind: 'preset' | 'provider';
|
|
84
|
+
baseUrl?: string;
|
|
85
|
+
requiresApiKey: boolean;
|
|
86
|
+
/** Needs a base URL before a key can be bound (gateways). */
|
|
87
|
+
needsBaseUrl?: boolean;
|
|
88
|
+
/** A loopback server (local discovery applies). */
|
|
89
|
+
local?: boolean;
|
|
90
|
+
}
|
|
91
|
+
/** What Test connection probes. Never carries a key: the host supplies the stored record. */
|
|
92
|
+
export interface InferenceConnectionInput {
|
|
93
|
+
provider?: string;
|
|
94
|
+
preset?: string;
|
|
95
|
+
baseUrl?: string;
|
|
96
|
+
model?: string;
|
|
97
|
+
}
|
|
98
|
+
/** Key-free result of a test. */
|
|
99
|
+
export interface InferenceConnectionResult {
|
|
100
|
+
reachable: boolean;
|
|
101
|
+
skipped?: boolean;
|
|
102
|
+
status?: number;
|
|
103
|
+
durationMs: number;
|
|
104
|
+
detail: string;
|
|
105
|
+
/** Whether a stored key was sent (only ever to its bound origin). */
|
|
106
|
+
keySent: boolean;
|
|
107
|
+
}
|
|
108
|
+
/** A fusion the host's registry knows (soft dependency on #4753's `defineFusion`). */
|
|
109
|
+
export interface RegisteredFusionLike {
|
|
110
|
+
key: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
[member: string]: unknown;
|
|
113
|
+
}
|
|
114
|
+
/** Options for {@link InferenceSettingsService.create}. */
|
|
115
|
+
export interface InferenceSettingsServiceOptions {
|
|
116
|
+
/** Host authorizer. Omit for a read-only (load-function) service: writes fail closed. */
|
|
117
|
+
authorize?: InferenceOverrideAuthorizer;
|
|
118
|
+
/** The code half of the tenant allow-list (#4667 caps hosted tiers here). */
|
|
119
|
+
tenantTargetPolicy?: InferenceTenantTargetPolicy;
|
|
120
|
+
/** The config layer. Default core's merged `getInferenceConfig()`. */
|
|
121
|
+
config?: () => InferenceConfig | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Registered fusions. Default: #4753's process registry (`defineFusion()`).
|
|
124
|
+
*/
|
|
125
|
+
registryFusions?: () => Iterable<RegisteredFusionLike>;
|
|
126
|
+
}
|
|
127
|
+
/** Thrown when a write would leave the layered config invalid. Nothing is written. */
|
|
128
|
+
export declare class InferenceSettingsConfigError extends Error {
|
|
129
|
+
readonly issues: InferenceConfigIssue[];
|
|
130
|
+
readonly status = 400;
|
|
131
|
+
constructor(issues: InferenceConfigIssue[]);
|
|
132
|
+
}
|
|
133
|
+
/** Thrown when removing an alias or fusion that something still names. Nothing is written. */
|
|
134
|
+
export declare class InferenceBindingInUseError extends Error {
|
|
135
|
+
readonly binding: string;
|
|
136
|
+
/** App-scope and config referrers. */
|
|
137
|
+
readonly referrers: string[];
|
|
138
|
+
/** How many tenant rows name it (never which tenants). */
|
|
139
|
+
readonly tenantReferences: number;
|
|
140
|
+
readonly status = 409;
|
|
141
|
+
constructor(binding: string,
|
|
142
|
+
/** App-scope and config referrers. */
|
|
143
|
+
referrers: string[],
|
|
144
|
+
/** How many tenant rows name it (never which tenants). */
|
|
145
|
+
tenantReferences: number);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Read and write side of an inference settings screen. See the module doc.
|
|
149
|
+
*/
|
|
150
|
+
export declare class InferenceSettingsService {
|
|
151
|
+
private readonly overrides;
|
|
152
|
+
private readonly options;
|
|
153
|
+
private readonly writes;
|
|
154
|
+
private readonly readConfig;
|
|
155
|
+
constructor(overrides: InferenceOverrideCollection, options?: InferenceSettingsServiceOptions);
|
|
156
|
+
/** Build a service over the given database options (list bounds stripped). */
|
|
157
|
+
static create(options?: SmrtClassOptions, serviceOptions?: InferenceSettingsServiceOptions): Promise<InferenceSettingsService>;
|
|
158
|
+
private loadLayers;
|
|
159
|
+
/**
|
|
160
|
+
* The effective config for a tenant: config < app rows < allowed tenant
|
|
161
|
+
* rows. What the override resolver binds and the doctor checks.
|
|
162
|
+
* Server-side only: config layers may carry literal keys, so never send
|
|
163
|
+
* this to a browser (the row methods strip them).
|
|
164
|
+
*/
|
|
165
|
+
getEffectiveConfig(options?: {
|
|
166
|
+
tenantId?: string | null;
|
|
167
|
+
}): Promise<InferenceSettingsConfig | undefined>;
|
|
168
|
+
/**
|
|
169
|
+
* One row per tier (`cheap`, `good`, `great`, `best`): the effective
|
|
170
|
+
* target, each scope's raw override, and both revert previews.
|
|
171
|
+
*/
|
|
172
|
+
listInferenceSettings(options?: {
|
|
173
|
+
tenantId?: string | null;
|
|
174
|
+
}): Promise<InferenceTierSettingsRow[]>;
|
|
175
|
+
/** `auto`'s default tier with the same per-scope shape. */
|
|
176
|
+
getDefaultTierSetting(options?: {
|
|
177
|
+
tenantId?: string | null;
|
|
178
|
+
}): Promise<InferenceDefaultTierSetting>;
|
|
179
|
+
/** Every alias: config entries, replaced whole by app rows. Sorted by name. */
|
|
180
|
+
listInferenceAliases(): Promise<InferenceAliasSetting[]>;
|
|
181
|
+
/**
|
|
182
|
+
* Fusions from the host's registry (code, read-only), the config's
|
|
183
|
+
* `inference.fusions`, and app rows (editable JSON). A later source
|
|
184
|
+
* shadows an earlier one by name.
|
|
185
|
+
*/
|
|
186
|
+
listInferenceFusions(): Promise<InferenceFusionSetting[]>;
|
|
187
|
+
/**
|
|
188
|
+
* Bind (or, with `null`, revert) one tier at one scope. Tenant writes must
|
|
189
|
+
* pass the allow-list; every write goes through the authorizer.
|
|
190
|
+
*/
|
|
191
|
+
setTierOverride(request: {
|
|
192
|
+
tier: InferenceTier;
|
|
193
|
+
scopeType: InferenceOverrideScopeType;
|
|
194
|
+
scopeId: string;
|
|
195
|
+
target: InferenceTarget | null;
|
|
196
|
+
}): Promise<void>;
|
|
197
|
+
/** Set (or revert) `auto`'s default tier at one scope. */
|
|
198
|
+
setDefaultTierOverride(request: {
|
|
199
|
+
scopeType: InferenceOverrideScopeType;
|
|
200
|
+
scopeId: string;
|
|
201
|
+
tier: InferenceTier | null;
|
|
202
|
+
}): Promise<void>;
|
|
203
|
+
/** Set (or remove) the tenant allow-list of a tier or of the default tier. */
|
|
204
|
+
setTenantAllowList(request: {
|
|
205
|
+
binding: `tier:${InferenceTier}` | typeof DEFAULT_TIER_BINDING;
|
|
206
|
+
allowList: string[] | null;
|
|
207
|
+
}): Promise<void>;
|
|
208
|
+
/** Define (or, with `null`, remove) an app-level alias. */
|
|
209
|
+
setAlias(request: {
|
|
210
|
+
name: string;
|
|
211
|
+
alias: InferenceAlias | null;
|
|
212
|
+
}): Promise<void>;
|
|
213
|
+
/** Store (or, with `null`, remove) an app-level fusion config entry (#4753 shape). */
|
|
214
|
+
setFusion(request: {
|
|
215
|
+
name: string;
|
|
216
|
+
definition: Record<string, unknown> | null;
|
|
217
|
+
}): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Refuse removing an app alias or fusion that a stored binding (any
|
|
220
|
+
* scope, any tenant) or the config still names, unless config or the
|
|
221
|
+
* registry keeps defining it. Otherwise the removal would leave dangling
|
|
222
|
+
* references that fail at call time.
|
|
223
|
+
*/
|
|
224
|
+
private assertNotReferenced;
|
|
225
|
+
/**
|
|
226
|
+
* Refuse a write that adds a config issue (unknown alias, cycle, key
|
|
227
|
+
* without endpoint, unknown preset) to the layered config it lands in.
|
|
228
|
+
* Issues that already existed do not block unrelated writes.
|
|
229
|
+
*/
|
|
230
|
+
private assertConfigStaysValid;
|
|
231
|
+
/**
|
|
232
|
+
* Test connection for the default view: probe the endpoint's cheapest
|
|
233
|
+
* list call (`./node`'s `probeInferenceCandidate`, 3 s). The stored key
|
|
234
|
+
* record (from the host's `SecretService`) is sent only when the probe URL
|
|
235
|
+
* is on the key's bound origin; no environment key is read.
|
|
236
|
+
*/
|
|
237
|
+
testConnection(input: InferenceConnectionInput, options?: {
|
|
238
|
+
key?: InferenceKeyRecord | null;
|
|
239
|
+
fetch?: typeof fetch;
|
|
240
|
+
timeoutMs?: number;
|
|
241
|
+
}): Promise<InferenceConnectionResult>;
|
|
242
|
+
/**
|
|
243
|
+
* Per-candidate test for the alias editor. A candidate already in the
|
|
244
|
+
* effective config (config file or an app row) reads its key from
|
|
245
|
+
* `apiKeyEnv` (or its provider's variable) exactly as the doctor does,
|
|
246
|
+
* sent only to its own endpoint; any other candidate (an unsaved edit) is
|
|
247
|
+
* probed with no key at all.
|
|
248
|
+
*/
|
|
249
|
+
testCandidate(candidate: InferenceCandidate, options?: {
|
|
250
|
+
env?: Record<string, string | undefined>;
|
|
251
|
+
fetch?: typeof fetch;
|
|
252
|
+
timeoutMs?: number;
|
|
253
|
+
}): Promise<InferenceConnectionResult>;
|
|
254
|
+
private isConfiguredCandidate;
|
|
255
|
+
/** `smrt doctor --ai` over the effective config for a tenant. */
|
|
256
|
+
doctor(options?: {
|
|
257
|
+
tenantId?: string | null;
|
|
258
|
+
probe?: boolean;
|
|
259
|
+
env?: Record<string, string | undefined>;
|
|
260
|
+
fetch?: typeof fetch;
|
|
261
|
+
}): Promise<InferenceDoctorReport>;
|
|
262
|
+
/**
|
|
263
|
+
* The Usage tab: `reportAiUsage()` (#4751) grouped by model, tier and/or
|
|
264
|
+
* prompt key. Pass `by: ['model']` where tier and prompt tags do not exist
|
|
265
|
+
* yet; NULL dimensions are their own bucket, never dropped.
|
|
266
|
+
*/
|
|
267
|
+
usage(options?: {
|
|
268
|
+
by?: Array<Extract<AiUsageReportDimension, 'model' | 'tier' | 'prompt'>>;
|
|
269
|
+
since?: Date;
|
|
270
|
+
until?: Date;
|
|
271
|
+
tenantId?: string | null;
|
|
272
|
+
}): Promise<AiUsageReport>;
|
|
273
|
+
/** Local discovery for the model field (#4674's loopback probe). */
|
|
274
|
+
discoverModels(): Promise<Array<{
|
|
275
|
+
service: string;
|
|
276
|
+
baseUrl: string;
|
|
277
|
+
models: string[];
|
|
278
|
+
}>>;
|
|
279
|
+
/** Provider choices: #4674 presets, then the AI SDK provider list. */
|
|
280
|
+
listProviderOptions(): InferenceProviderOption[];
|
|
281
|
+
}
|
|
282
|
+
//# sourceMappingURL=settings-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"settings-service.d.ts","sourceRoot":"","sources":["../../src/settings/settings-service.ts"],"names":[],"mappings":"AAYA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAK3B,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACpB,KAAK,eAAe,EACpB,KAAK,aAAa,EAGlB,KAAK,gBAAgB,EAEtB,MAAM,0BAA0B,CAAC;AAIlC,OAAO,EACL,2BAA2B,EAC3B,KAAK,0BAA0B,EAChC,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACL,KAAK,kBAAkB,EAGxB,MAAM,WAAW,CAAC;AACnB,OAAO,EAEL,KAAK,uBAAuB,EAG7B,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,2BAA2B,EAEhC,KAAK,2BAA2B,EACjC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,oBAAoB,EAMrB,MAAM,cAAc,CAAC;AAEtB,+CAA+C;AAC/C,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;AAE7E,gDAAgD;AAChD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,QAAQ,aAAa,EAAE,CAAC;IACjC,IAAI,EAAE,aAAa,CAAC;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K,CACH,OAAO,GAAE;QACP,EAAE,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,sBAAsB,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC;QACzE,KAAK,CAAC,EAAE,IAAI,CAAC;QACb,KAAK,CAAC,EAAE,IAAI,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACrB,GACL,OAAO,CAAC,aAAa,CAAC;IAOzB,oEAAoE;IAC9D,cAAc,IAAI,OAAO,CAC7B,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAC9D;IAcD,sEAAsE;IACtE,mBAAmB,IAAI,uBAAuB,EAAE;CA0BjD"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The vocabulary of stored inference bindings (#4754): binding ids, the
|
|
3
|
+
* target shapes a settings write may store, the allow-list references a
|
|
4
|
+
* tenant write is checked against, and key-free labels.
|
|
5
|
+
*
|
|
6
|
+
* Pure and browser-safe: no `node:`, no SDK, no smrt-config.
|
|
7
|
+
*/
|
|
8
|
+
import { type InferenceAlias, type InferenceTarget, type InferenceTier } from '@happyvertical/smrt-core';
|
|
9
|
+
/** How a user or app gets inference. Stored as a user choice, never a binding. */
|
|
10
|
+
export declare const INFERENCE_MODES: readonly ["byo", "local", "hosted", "off"];
|
|
11
|
+
export type InferenceMode = (typeof INFERENCE_MODES)[number];
|
|
12
|
+
/** Binding id of `auto`'s default tier. */
|
|
13
|
+
export declare const DEFAULT_TIER_BINDING = "default-tier";
|
|
14
|
+
/** A binding id stored in `_smrt_inference_overrides.binding`. */
|
|
15
|
+
export type InferenceBindingId = `tier:${InferenceTier}` | typeof DEFAULT_TIER_BINDING | `alias:${string}` | `fusion:${string}`;
|
|
16
|
+
/** `inference.aliases` / fusion names: what a binding id may carry after its prefix. */
|
|
17
|
+
export declare const INFERENCE_BINDING_NAME_PATTERN: RegExp;
|
|
18
|
+
export type InferenceBindingKind = 'tier' | 'default-tier' | 'alias' | 'fusion';
|
|
19
|
+
/** A parsed binding id. */
|
|
20
|
+
export interface ParsedInferenceBinding {
|
|
21
|
+
kind: InferenceBindingKind;
|
|
22
|
+
/** The tier, alias or fusion name (absent for `default-tier`). */
|
|
23
|
+
name?: string;
|
|
24
|
+
}
|
|
25
|
+
/** Thrown for a malformed binding id or an invalid stored value. Nothing is written. */
|
|
26
|
+
export declare class InferenceBindingValueError extends Error {
|
|
27
|
+
readonly binding: string;
|
|
28
|
+
readonly status = 400;
|
|
29
|
+
constructor(binding: string, reason: string);
|
|
30
|
+
}
|
|
31
|
+
/** Parse a binding id, or `null` when it is not one this package stores. */
|
|
32
|
+
export declare function parseInferenceBinding(binding: unknown): ParsedInferenceBinding | null;
|
|
33
|
+
/** The binding id of one tier. */
|
|
34
|
+
export declare function tierBinding(tier: InferenceTier): `tier:${InferenceTier}`;
|
|
35
|
+
/**
|
|
36
|
+
* A deep copy of `value` with every credential-shaped member removed. Used
|
|
37
|
+
* on every config-backed value a settings screen receives: config tiers and
|
|
38
|
+
* alias candidates may legitimately carry a literal `apiKey` (resolvers and
|
|
39
|
+
* endpoint-bound config), and none of it may reach a browser.
|
|
40
|
+
*/
|
|
41
|
+
export declare function stripKeyMembers<T>(value: T): T;
|
|
42
|
+
/** Dotted path of the first key-shaped member anywhere in `value`, or `null`. */
|
|
43
|
+
export declare function findKeyMember(value: unknown, path?: string): string | null;
|
|
44
|
+
/**
|
|
45
|
+
* The tier target a settings write may store. A tier binds exactly one of:
|
|
46
|
+
*
|
|
47
|
+
* - a model: `{ provider?, model }` (no `baseUrl`: an endpoint needs its own
|
|
48
|
+
* key, and keys are never stored here; bind an alias whose candidate names
|
|
49
|
+
* `baseUrl` + `apiKeyEnv` or a preset instead);
|
|
50
|
+
* - an alias: `{ alias }`;
|
|
51
|
+
* - a fusion (#4753): `{ kind: 'fusion', fusion }`.
|
|
52
|
+
*
|
|
53
|
+
* `null` means "same as default" (inherit the lower layer).
|
|
54
|
+
*/
|
|
55
|
+
export declare function normalizeTierTarget(binding: string, value: unknown): InferenceTarget | null;
|
|
56
|
+
/**
|
|
57
|
+
* An alias definition a settings write may store: `{ candidates, description? }`,
|
|
58
|
+
* every candidate exactly one of provider/model, preset/model or alias, and
|
|
59
|
+
* never a literal key (`apiKeyEnv` names a variable and needs `baseUrl`).
|
|
60
|
+
* Structural checks only; cross-references are checked against the layered
|
|
61
|
+
* config by the settings service.
|
|
62
|
+
*/
|
|
63
|
+
export declare function normalizeAliasDefinition(binding: string, value: unknown): InferenceAlias | null;
|
|
64
|
+
/**
|
|
65
|
+
* A fusion config entry (#4753) a settings write may store: a JSON object
|
|
66
|
+
* with no credential members. Its meaning belongs to the fusion interpreter;
|
|
67
|
+
* this package only stores it (app scope only).
|
|
68
|
+
*/
|
|
69
|
+
export declare function normalizeFusionDefinition(binding: string, value: unknown): Record<string, unknown> | null;
|
|
70
|
+
/** `default-tier` stores `{ tier }`. */
|
|
71
|
+
export declare function normalizeDefaultTier(binding: string, value: unknown): InferenceTier | null;
|
|
72
|
+
/**
|
|
73
|
+
* The allow-list reference of a tier target: `model:<provider>/<model>`
|
|
74
|
+
* (`model:default/<model>` without a provider), `alias:<name>` or
|
|
75
|
+
* `fusion:<name>`; for the default tier, `tier:<name>`. Key-free.
|
|
76
|
+
*/
|
|
77
|
+
export declare function inferenceTargetRef(target: InferenceTarget): string;
|
|
78
|
+
/**
|
|
79
|
+
* Whether `ref` matches one allow-list pattern. A pattern is an exact
|
|
80
|
+
* reference, a prefix ending in `*` (`model:openai/*`, `alias:*`), or `*`.
|
|
81
|
+
*/
|
|
82
|
+
export declare function matchesAllowPattern(ref: string, pattern: string): boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The tenant allow-list check: a tenant may bind only a reference the app
|
|
85
|
+
* row's list matches. No list (or an empty one) allows nothing, so a tenant
|
|
86
|
+
* cannot bind a tier the operator has not opened.
|
|
87
|
+
*/
|
|
88
|
+
export declare function isAllowedByList(ref: string, allowList: readonly string[] | null | undefined): boolean;
|
|
89
|
+
/** Validate and normalize an allow-list (patterns are short, key-free references). */
|
|
90
|
+
export declare function normalizeAllowList(binding: string, value: unknown): string[] | null;
|
|
91
|
+
/** Key-free description of a tier target for screens and reports. */
|
|
92
|
+
export declare function describeInferenceTarget(target: InferenceTarget | null | undefined): string;
|
|
93
|
+
//# sourceMappingURL=targets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"targets.d.ts","sourceRoot":"","sources":["../../src/settings/targets.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,EAEL,KAAK,cAAc,EAEnB,KAAK,eAAe,EACpB,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AAElC,kFAAkF;AAClF,eAAO,MAAM,eAAe,4CAA6C,CAAC;AAC1E,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7D,2CAA2C;AAC3C,eAAO,MAAM,oBAAoB,iBAAiB,CAAC;AAEnD,kEAAkE;AAClE,MAAM,MAAM,kBAAkB,GAC1B,QAAQ,aAAa,EAAE,GACvB,OAAO,oBAAoB,GAC3B,SAAS,MAAM,EAAE,GACjB,UAAU,MAAM,EAAE,CAAC;AAEvB,wFAAwF;AACxF,eAAO,MAAM,8BAA8B,QAAiC,CAAC;AAE7E,MAAM,MAAM,oBAAoB,GAAG,MAAM,GAAG,cAAc,GAAG,OAAO,GAAG,QAAQ,CAAC;AAEhF,2BAA2B;AAC3B,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,kEAAkE;IAClE,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wFAAwF;AACxF,qBAAa,0BAA2B,SAAQ,KAAK;IAGjD,QAAQ,CAAC,OAAO,EAAE,MAAM;IAF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