@capybara-hq/kernel 0.1.0-rc.130 → 0.1.0-rc.132
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/dist/admin/account-erasures.d.ts +37 -0
- package/dist/admin/account-erasures.js +119 -0
- package/dist/admin/admin.controller.d.ts +35 -2
- package/dist/admin/admin.controller.js +75 -18
- package/dist/admin/admin.module.js +10 -0
- package/dist/admin/admin.schemas.d.ts +51 -0
- package/dist/admin/admin.schemas.js +20 -0
- package/dist/admin/erasure-dispositions.d.ts +23 -0
- package/dist/admin/erasure-dispositions.js +76 -0
- package/dist/admin/health.service.d.ts +6 -0
- package/dist/admin/health.service.js +27 -1
- package/dist/admin/usage.service.d.ts +5 -0
- package/dist/admin/usage.service.js +21 -2
- package/dist/agents/agents.service.d.ts +1 -1
- package/dist/catalog/plugin-import.d.ts +3 -1
- package/dist/catalog/plugin-import.js +19 -15
- package/dist/channels/connections.service.d.ts +1 -1
- package/dist/client/client-reports.service.js +12 -0
- package/dist/config/schema.d.ts +9 -1
- package/dist/config/schema.js +51 -1
- package/dist/conversations/conversations.service.d.ts +9 -1
- package/dist/conversations/conversations.service.js +112 -15
- package/dist/conversations/event-log.d.ts +2 -0
- package/dist/conversations/event-log.js +77 -0
- package/dist/conversations/events.d.ts +11 -0
- package/dist/conversations/events.js +13 -1
- package/dist/conversations/prompt-suggestions.js +4 -0
- package/dist/conversations/titles.js +3 -2
- package/dist/ctx/create-ctx.d.ts +3 -2
- package/dist/ctx/create-ctx.js +10 -7
- package/dist/db/extension-db.d.ts +30 -0
- package/dist/db/extension-db.js +91 -0
- package/dist/db/extension-schema-transfer.d.ts +6 -0
- package/dist/db/extension-schema-transfer.js +141 -0
- package/dist/db/kernel-schema.d.ts +73 -12
- package/dist/db/migrator.d.ts +6 -0
- package/dist/db/migrator.js +39 -4
- package/dist/db/pool.d.ts +4 -0
- package/dist/db/pool.js +36 -1
- package/dist/devices/devices.service.d.ts +13 -1
- package/dist/devices/devices.service.js +122 -9
- package/dist/erasure/account-batches.d.ts +9 -0
- package/dist/erasure/account-batches.js +567 -0
- package/dist/erasure/account-files.d.ts +34 -0
- package/dist/erasure/account-files.js +217 -0
- package/dist/erasure/account-residual.d.ts +15 -0
- package/dist/erasure/account-residual.js +149 -0
- package/dist/erasure/account-worker.d.ts +32 -0
- package/dist/erasure/account-worker.js +392 -0
- package/dist/erasure/device-cleanup.d.ts +23 -0
- package/dist/erasure/device-cleanup.js +221 -0
- package/dist/erasure/erasure.module.d.ts +2 -0
- package/dist/{conversations/event-org-backfill.module.js → erasure/erasure.module.js} +6 -10
- package/dist/erasure/external-evidence.d.ts +4 -0
- package/dist/erasure/external-evidence.js +28 -0
- package/dist/erasure/jobs.d.ts +5 -0
- package/dist/erasure/jobs.js +20 -0
- package/dist/erasure/org-batches.d.ts +11 -0
- package/dist/erasure/org-batches.js +159 -0
- package/dist/erasure/org-catalog.d.ts +2 -0
- package/dist/erasure/org-catalog.js +34 -0
- package/dist/erasure/org-rules.d.ts +14 -0
- package/dist/erasure/org-rules.js +227 -0
- package/dist/erasure/org-worker.d.ts +38 -0
- package/dist/erasure/org-worker.js +501 -0
- package/dist/erasure/requests.d.ts +61 -0
- package/dist/erasure/requests.js +180 -0
- package/dist/erasure/sweep.job.d.ts +19 -0
- package/dist/erasure/sweep.job.js +130 -0
- package/dist/erasure/worker.d.ts +17 -0
- package/dist/erasure/worker.js +110 -0
- package/dist/errors.d.ts +4 -0
- package/dist/errors.js +4 -0
- package/dist/evals/judge.d.ts +5 -0
- package/dist/evals/judge.js +16 -1
- package/dist/evals/run-replay.js +12 -1
- package/dist/evals/step-replay.d.ts +5 -3
- package/dist/evals/step-replay.js +9 -5
- package/dist/evals/worker.d.ts +2 -0
- package/dist/evals/worker.js +60 -16
- package/dist/extensions/admin-ops.d.ts +3 -1
- package/dist/extensions/admin-ops.js +11 -7
- package/dist/extensions/extensions.module.js +3 -0
- package/dist/extensions/host.d.ts +4 -1
- package/dist/extensions/host.js +29 -6
- package/dist/extensions/instance.d.ts +3 -0
- package/dist/extensions/instance.js +3 -1
- package/dist/extensions/migrate-lock.d.ts +4 -1
- package/dist/extensions/migrate-lock.js +19 -2
- package/dist/files/blob-objects.d.ts +7 -3
- package/dist/files/blob-objects.js +39 -22
- package/dist/files/blob-sweep.job.d.ts +11 -0
- package/dist/files/blob-sweep.job.js +67 -6
- package/dist/http/api.module.js +5 -1
- package/dist/identity/accounts.js +3 -0
- package/dist/identity/api-tokens.js +5 -0
- package/dist/identity/auth.guard.d.ts +1 -0
- package/dist/identity/auth.guard.js +1 -0
- package/dist/identity/erasure-admission.d.ts +3 -0
- package/dist/identity/erasure-admission.js +14 -0
- package/dist/identity/external.js +5 -0
- package/dist/identity/sessions.js +5 -0
- package/dist/identity/settings.d.ts +86 -1
- package/dist/identity/settings.js +38 -4
- package/dist/infra/config/kernel-config.service.js +1 -0
- package/dist/infra/metrics/kernel-metrics.d.ts +18 -0
- package/dist/infra/metrics/kernel-metrics.js +54 -0
- package/dist/infra/metrics/operational-metrics.d.ts +31 -0
- package/dist/infra/metrics/operational-metrics.js +188 -0
- package/dist/infra/outbox/registry.d.ts +23 -14
- package/dist/infra/outbox/registry.js +12 -15
- package/dist/infra/throttler/credential-throttler.js +8 -1
- package/dist/infra/throttler/named-throttlers.d.ts +6 -0
- package/dist/infra/throttler/named-throttlers.js +6 -0
- package/dist/infra/throttler/principal-throttler.guard.d.ts +10 -0
- package/dist/infra/throttler/principal-throttler.guard.js +50 -0
- package/dist/infra/throttler/redis-throttler-storage.d.ts +1 -0
- package/dist/infra/throttler/redis-throttler-storage.js +27 -5
- package/dist/infra/throttler/throttler.guard.d.ts +2 -3
- package/dist/infra/throttler/throttler.guard.js +2 -3
- package/dist/infra/throttler/throttler.module.js +3 -2
- package/dist/kernel.js +4 -0
- package/dist/lifecycle/kernel-lifecycle.d.ts +3 -1
- package/dist/lifecycle/kernel-lifecycle.js +26 -21
- package/dist/models/budget-admission.d.ts +31 -0
- package/dist/models/budget-admission.js +149 -0
- package/dist/models/budget-counters.d.ts +28 -0
- package/dist/models/budget-counters.js +117 -0
- package/dist/models/budget-policy.d.ts +88 -0
- package/dist/models/budget-policy.js +78 -0
- package/dist/models/embeddings.js +13 -2
- package/dist/models/images.js +12 -2
- package/dist/models/purposes.d.ts +5 -2
- package/dist/models/purposes.js +9 -5
- package/dist/orgs/invitations.service.d.ts +1 -1
- package/dist/orgs/members.service.d.ts +28 -1
- package/dist/orgs/members.service.js +74 -11
- package/dist/orgs/offboarding.js +4 -6
- package/dist/orgs/org-owner.d.ts +2 -0
- package/dist/orgs/org-owner.js +21 -6
- package/dist/orgs/orgs.controller.d.ts +22 -0
- package/dist/orgs/orgs.controller.js +24 -0
- package/dist/orgs/orgs.module.js +4 -0
- package/dist/orgs/orgs.schemas.js +7 -0
- package/dist/orgs/orgs.service.d.ts +5 -1
- package/dist/orgs/orgs.service.js +28 -3
- package/dist/orgs/settings.controller.js +6 -1
- package/dist/orgs/settings.service.d.ts +58 -1
- package/dist/orgs/settings.service.js +74 -9
- package/dist/platform/exclusions.js +20 -1
- package/dist/platform/ops/accounts.ops.js +58 -1
- package/dist/platform/ops/admin.ops.js +13 -5
- package/dist/platform/ops/org-settings.ops.js +11 -4
- package/dist/platform/ops/orgs.ops.js +28 -0
- package/dist/platform/ops/retention.d.ts +16 -0
- package/dist/platform/ops/retention.js +21 -0
- package/dist/retention/jobs.d.ts +21 -0
- package/dist/retention/jobs.js +48 -0
- package/dist/retention/policy.d.ts +70 -0
- package/dist/retention/policy.js +103 -0
- package/dist/retention/purge-batch.d.ts +17 -0
- package/dist/retention/purge-batch.js +355 -0
- package/dist/retention/report-obligations.d.ts +12 -0
- package/dist/retention/report-obligations.js +71 -0
- package/dist/retention/sweep.job.d.ts +17 -0
- package/dist/retention/sweep.job.js +95 -0
- package/dist/retention/worker.d.ts +29 -0
- package/dist/retention/worker.js +306 -0
- package/dist/roles/worker.module.js +12 -8
- package/dist/runtime/maintenance.d.ts +5 -3
- package/dist/runtime/maintenance.js +19 -12
- package/dist/runtime/model-call.d.ts +3 -1
- package/dist/runtime/model-call.js +25 -3
- package/dist/runtime/providers.d.ts +7 -2
- package/dist/runtime/providers.js +76 -10
- package/dist/runtime/quota.d.ts +12 -12
- package/dist/runtime/quota.js +42 -37
- package/dist/runtime/run-finish.js +2 -0
- package/dist/runtime/run-principal.d.ts +9 -0
- package/dist/runtime/run-principal.js +18 -0
- package/dist/runtime/run-worker.js +48 -10
- package/dist/runtime/usage-report-jobs.d.ts +4 -1
- package/dist/runtime/usage-report-jobs.js +36 -13
- package/dist/runtime/usage-report.d.ts +5 -3
- package/dist/runtime/usage-report.js +37 -19
- package/dist/sandbox/review/classifier.d.ts +2 -2
- package/dist/sandbox/review/classifier.js +6 -2
- package/dist/sandbox/sandbox.service.js +18 -7
- package/dist/storage/purge.js +5 -1
- package/dist/storage/storage.service.d.ts +17 -1
- package/dist/storage/storage.service.js +75 -4
- package/dist/tools/builtins/vision/read-image.js +3 -0
- package/dist/tools/builtins/web/extract.js +3 -0
- package/dist/tools/pipeline.js +5 -1
- package/package.json +3 -1
- package/src/migrations/0216_model_budget_counters.sql +24 -0
- package/src/migrations/0217_retention.sql +44 -0
- package/src/migrations/0218_data_erasure.sql +41 -0
- package/src/migrations/0219_event_org_constraint_check.sql +29 -0
- package/src/migrations/0220_require_event_org.sql +18 -0
- package/src/migrations/0221_drop_connector_declaration_policy.sql +2 -0
- package/dist/conversations/event-org-backfill.d.ts +0 -111
- package/dist/conversations/event-org-backfill.js +0 -264
- package/dist/conversations/event-org-backfill.module.d.ts +0 -3
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { PriceCurrency } from "./price-snapshot.js";
|
|
3
|
+
const SpendSchema = z.strictObject({
|
|
4
|
+
amount: z.string().regex(/^\d{1,30}(?:\.\d{1,18})?$/),
|
|
5
|
+
currency: PriceCurrency,
|
|
6
|
+
});
|
|
7
|
+
export const ModelBudgetSchema = z.strictObject({
|
|
8
|
+
tokens: z.number().int().nonnegative().optional(),
|
|
9
|
+
spend: SpendSchema.optional(),
|
|
10
|
+
});
|
|
11
|
+
export const PlatformModelBudgetsSchema = z.strictObject({
|
|
12
|
+
orgDefault: ModelBudgetSchema.optional(),
|
|
13
|
+
orgCeiling: ModelBudgetSchema.optional(),
|
|
14
|
+
memberDefault: ModelBudgetSchema.optional(),
|
|
15
|
+
memberCeiling: ModelBudgetSchema.optional(),
|
|
16
|
+
});
|
|
17
|
+
export const OrgModelBudgetsSchema = z.strictObject({
|
|
18
|
+
org: ModelBudgetSchema.optional(),
|
|
19
|
+
memberDefault: ModelBudgetSchema.optional(),
|
|
20
|
+
});
|
|
21
|
+
export const MemberBudgetBody = z.strictObject({ budget: ModelBudgetSchema.nullable() });
|
|
22
|
+
export const PLATFORM_MODEL_BUDGET_CACHE_KEY = "model-budget:platform";
|
|
23
|
+
export const orgModelBudgetCacheKey = (orgId) => `model-budget:org:${orgId}`;
|
|
24
|
+
export async function readPlatformModelBudgets(db, opts) {
|
|
25
|
+
const row = await db
|
|
26
|
+
.selectFrom("deployment_settings")
|
|
27
|
+
.select("value")
|
|
28
|
+
.where("key", "=", "modelBudgets")
|
|
29
|
+
.executeTakeFirst();
|
|
30
|
+
if (!row)
|
|
31
|
+
return {};
|
|
32
|
+
if (opts?.strict)
|
|
33
|
+
return PlatformModelBudgetsSchema.parse(row.value);
|
|
34
|
+
return PlatformModelBudgetsSchema.safeParse(row.value).data ?? {};
|
|
35
|
+
}
|
|
36
|
+
/** Compare unsigned decimal strings from settings or PostgreSQL without rounding. */
|
|
37
|
+
export function compareBudgetAmounts(a, b) {
|
|
38
|
+
const [aWhole, aFraction = ""] = a.split(".");
|
|
39
|
+
const [bWhole, bFraction = ""] = b.split(".");
|
|
40
|
+
const scale = Math.max(aFraction.length, bFraction.length);
|
|
41
|
+
const left = BigInt(aWhole + aFraction.padEnd(scale, "0"));
|
|
42
|
+
const right = BigInt(bWhole + bFraction.padEnd(scale, "0"));
|
|
43
|
+
return left < right ? -1 : left > right ? 1 : 0;
|
|
44
|
+
}
|
|
45
|
+
function constrain(budget, ceiling = {}) {
|
|
46
|
+
const result = { ...budget };
|
|
47
|
+
if (ceiling.tokens !== undefined)
|
|
48
|
+
result.tokens = Math.min(budget.tokens ?? ceiling.tokens, ceiling.tokens);
|
|
49
|
+
if (ceiling.spend) {
|
|
50
|
+
if (budget.spend && budget.spend.currency !== ceiling.spend.currency)
|
|
51
|
+
result.currencyConflict = true;
|
|
52
|
+
else if (!budget.spend || compareBudgetAmounts(ceiling.spend.amount, budget.spend.amount) < 0)
|
|
53
|
+
result.spend = ceiling.spend;
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
export const StoredMemberBudgetsSchema = z
|
|
58
|
+
.custom((v) => v !== null && typeof v === "object" && !Array.isArray(v))
|
|
59
|
+
.optional();
|
|
60
|
+
const StoredFields = z.object({
|
|
61
|
+
modelBudgets: OrgModelBudgetsSchema.optional(),
|
|
62
|
+
memberModelBudgets: StoredMemberBudgetsSchema,
|
|
63
|
+
});
|
|
64
|
+
export function readMemberBudget(raw, accountId) {
|
|
65
|
+
return budgetForAccount(StoredFields.parse(raw ?? {}).memberModelBudgets, accountId);
|
|
66
|
+
}
|
|
67
|
+
function budgetForAccount(map, accountId) {
|
|
68
|
+
return map && Object.hasOwn(map, accountId) ? ModelBudgetSchema.parse(map[accountId]) : null;
|
|
69
|
+
}
|
|
70
|
+
/** Resolves the member default when the caller supplies no account. Org-only admission ignores it. */
|
|
71
|
+
export function resolveModelBudgets(platform, raw, accountId) {
|
|
72
|
+
const { modelBudgets, memberModelBudgets } = StoredFields.parse(raw ?? {});
|
|
73
|
+
const individual = accountId ? budgetForAccount(memberModelBudgets, accountId) : null;
|
|
74
|
+
return {
|
|
75
|
+
org: constrain({ ...platform.orgDefault, ...modelBudgets?.org }, platform.orgCeiling),
|
|
76
|
+
member: constrain({ ...platform.memberDefault, ...modelBudgets?.memberDefault, ...individual }, platform.memberCeiling),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -22,6 +22,8 @@ import { embeddingDeniedAudit } from "../runtime/hook-calls.js";
|
|
|
22
22
|
import { modelDeniedText } from "../runtime/model-call.js";
|
|
23
23
|
import { ModelRequestDenied, ProviderRegistry, prepareEmbedding, supportsEmbedding, } from "../runtime/providers.js";
|
|
24
24
|
import { UsageReportJobs } from "../runtime/usage-report-jobs.js";
|
|
25
|
+
import { readModelBudgetAccount } from "./budget-admission.js";
|
|
26
|
+
import { recordSettledModelUsage } from "./budget-counters.js";
|
|
25
27
|
import { readPriceSnapshot } from "./price-snapshot.js";
|
|
26
28
|
import { ModelPurposesService } from "./purposes.js";
|
|
27
29
|
/** Most texts one `ctx.models.embed` call may carry (the kernel splits them by `maxBatch`). */
|
|
@@ -244,6 +246,7 @@ let ModelEmbeddings = class ModelEmbeddings {
|
|
|
244
246
|
async record(plugin, orgId, purpose, model, inputTokens) {
|
|
245
247
|
const ref = { provider: model.provider, model: model.id };
|
|
246
248
|
const priceSnapshot = await readPriceSnapshot(this.kdb.db, ref);
|
|
249
|
+
const tokens = Math.round(inputTokens);
|
|
247
250
|
const row = await this.kdb.db
|
|
248
251
|
.insertInto("model_usage")
|
|
249
252
|
.values({
|
|
@@ -253,10 +256,18 @@ let ModelEmbeddings = class ModelEmbeddings {
|
|
|
253
256
|
purpose,
|
|
254
257
|
provider: model.provider,
|
|
255
258
|
model: model.id,
|
|
256
|
-
input_tokens:
|
|
259
|
+
input_tokens: tokens,
|
|
257
260
|
})
|
|
258
|
-
.returning("id")
|
|
261
|
+
.returning(["id", "occurred_at"])
|
|
259
262
|
.executeTakeFirstOrThrow();
|
|
263
|
+
await recordSettledModelUsage(this.kdb.db, {
|
|
264
|
+
orgId,
|
|
265
|
+
accountId: await readModelBudgetAccount(this.kdb.db, orgId),
|
|
266
|
+
usageSourceId: row.id,
|
|
267
|
+
at: row.occurred_at,
|
|
268
|
+
usage: { inputTokens: tokens, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 },
|
|
269
|
+
snapshot: priceSnapshot,
|
|
270
|
+
});
|
|
260
271
|
await this.usage.oweModelUsage(row.id, orgId);
|
|
261
272
|
}
|
|
262
273
|
};
|
package/dist/models/images.js
CHANGED
|
@@ -22,6 +22,8 @@ import { base64Bytes, fireObserve, imageDeniedAudit, } from "../runtime/hook-cal
|
|
|
22
22
|
import { modelDeniedText, trustedUsage } from "../runtime/model-call.js";
|
|
23
23
|
import { ModelRequestDenied, ProviderRegistry, prepareImageGeneration, } from "../runtime/providers.js";
|
|
24
24
|
import { UsageReportJobs } from "../runtime/usage-report-jobs.js";
|
|
25
|
+
import { readModelBudgetAccount } from "./budget-admission.js";
|
|
26
|
+
import { recordSettledModelUsage } from "./budget-counters.js";
|
|
25
27
|
import { imageInputCaps } from "./image-usable.js";
|
|
26
28
|
import { readPriceSnapshot } from "./price-snapshot.js";
|
|
27
29
|
import { ModelPurposesService } from "./purposes.js";
|
|
@@ -200,8 +202,16 @@ let ModelImages = class ModelImages {
|
|
|
200
202
|
}),
|
|
201
203
|
output_images: billedImages(res),
|
|
202
204
|
})
|
|
203
|
-
.returning("id")
|
|
205
|
+
.returning(["id", "occurred_at"])
|
|
204
206
|
.executeTakeFirstOrThrow();
|
|
207
|
+
await recordSettledModelUsage(this.kdb.db, {
|
|
208
|
+
orgId,
|
|
209
|
+
accountId: await readModelBudgetAccount(this.kdb.db, orgId),
|
|
210
|
+
usageSourceId: row.id,
|
|
211
|
+
at: row.occurred_at,
|
|
212
|
+
usage: res.usage,
|
|
213
|
+
snapshot: priceSnapshot,
|
|
214
|
+
});
|
|
205
215
|
await this.usage.oweModelUsage(row.id, orgId);
|
|
206
216
|
}
|
|
207
217
|
async prepare(orgId, purpose, input) {
|
|
@@ -286,7 +296,7 @@ let ModelImages = class ModelImages {
|
|
|
286
296
|
size: base64Bytes(r.data),
|
|
287
297
|
})),
|
|
288
298
|
...identity,
|
|
289
|
-
}), hooks, signal, ref);
|
|
299
|
+
}), hooks, signal, ref, who.kind === "conversation" ? (who.scope ?? undefined) : undefined);
|
|
290
300
|
const sentAt = Date.now();
|
|
291
301
|
// the caller measures the latency once, so the hook payload and the result report the same value
|
|
292
302
|
const respond = (r, latencyMs) => {
|
|
@@ -10,6 +10,7 @@ import { OrgLock } from "../orgs/org-lock.js";
|
|
|
10
10
|
import type { HookDenial } from "../runtime/hook-calls.js";
|
|
11
11
|
import { type ChatRequestSite, ProviderRegistry } from "../runtime/providers.js";
|
|
12
12
|
import { StorageService } from "../storage/storage.service.js";
|
|
13
|
+
import type { ModelBudgetSite } from "./budget-admission.js";
|
|
13
14
|
/**
|
|
14
15
|
* 模型用途映射(C9):内核与插件按「用途」取模型,不在代码里写死模型。
|
|
15
16
|
* - 用途 = 内核用途 {@link KERNEL_PURPOSES}(目前只有评委 `eval`),或已加载插件 `permissions.models` 声明的;
|
|
@@ -122,10 +123,11 @@ export declare class PurposePutDto extends PurposePutDto_base {
|
|
|
122
123
|
*/
|
|
123
124
|
export declare class PurposeAttemptError extends Error {
|
|
124
125
|
readonly cause: unknown;
|
|
125
|
-
readonly tokens: number;
|
|
126
126
|
readonly provider: string;
|
|
127
127
|
readonly model: string;
|
|
128
|
-
|
|
128
|
+
readonly usage: ModelUsage;
|
|
129
|
+
get tokens(): number;
|
|
130
|
+
constructor(cause: unknown, inputTokens: number, provider: string, model: string, outputTokens?: number);
|
|
129
131
|
}
|
|
130
132
|
/**
|
|
131
133
|
* The model purposes (one provider). Extension-declared purposes come from the manifests in the
|
|
@@ -223,6 +225,7 @@ export declare class ModelPurposesService {
|
|
|
223
225
|
fallback?: PurposeTarget;
|
|
224
226
|
hooks: ChatRequestSite["hooks"];
|
|
225
227
|
scope?: ChatRequestSite["scope"];
|
|
228
|
+
budgetSite?: ModelBudgetSite;
|
|
226
229
|
step?: number;
|
|
227
230
|
onDenied?: (verdict: HookDenial) => Promise<void>;
|
|
228
231
|
beforeSend?: (target: ModelRef, request: ModelRequest) => Promise<void>;
|
package/dist/models/purposes.js
CHANGED
|
@@ -183,15 +183,18 @@ export class PurposePutDto extends createZodDto(PURPOSE_PUT, "ModelPurposePut")
|
|
|
183
183
|
*/
|
|
184
184
|
export class PurposeAttemptError extends Error {
|
|
185
185
|
cause;
|
|
186
|
-
tokens;
|
|
187
186
|
provider;
|
|
188
187
|
model;
|
|
189
|
-
|
|
188
|
+
usage;
|
|
189
|
+
get tokens() {
|
|
190
|
+
return this.usage.inputTokens + this.usage.outputTokens;
|
|
191
|
+
}
|
|
192
|
+
constructor(cause, inputTokens, provider, model, outputTokens = 0) {
|
|
190
193
|
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
191
194
|
this.cause = cause;
|
|
192
|
-
this.tokens = tokens;
|
|
193
195
|
this.provider = provider;
|
|
194
196
|
this.model = model;
|
|
197
|
+
this.usage = { inputTokens, outputTokens, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
195
198
|
this.name = "PurposeAttemptError";
|
|
196
199
|
}
|
|
197
200
|
}
|
|
@@ -547,6 +550,7 @@ let ModelPurposesService = class ModelPurposesService {
|
|
|
547
550
|
purpose,
|
|
548
551
|
hooks: opts.hooks,
|
|
549
552
|
scope: opts.scope,
|
|
553
|
+
budgetSite: opts.budgetSite,
|
|
550
554
|
step: opts.step ?? 0,
|
|
551
555
|
attempt: 1,
|
|
552
556
|
}, signal, this.log).catch(async (error) => {
|
|
@@ -569,8 +573,8 @@ let ModelPurposesService = class ModelPurposesService {
|
|
|
569
573
|
};
|
|
570
574
|
}
|
|
571
575
|
catch (err) {
|
|
572
|
-
const
|
|
573
|
-
throw new PurposeAttemptError(err,
|
|
576
|
+
const input = estimateTokens(request.messages, request.system, request.tools);
|
|
577
|
+
throw new PurposeAttemptError(err, input, target.model.provider, target.model.model, Math.ceil(chars / 4));
|
|
574
578
|
}
|
|
575
579
|
}
|
|
576
580
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
2
2
|
import type { Account } from "../identity/accounts.js";
|
|
3
|
+
import { CacheService } from "../infra/cache/cache.service.js";
|
|
3
4
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
4
5
|
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
6
|
+
import { type ModelBudget } from "../models/budget-policy.js";
|
|
5
7
|
import { Offboarding } from "./offboarding.js";
|
|
6
8
|
import { OrgLock } from "./org-lock.js";
|
|
7
9
|
import type { OrgRole } from "./roles.js";
|
|
@@ -41,9 +43,34 @@ export declare class MembersService {
|
|
|
41
43
|
private readonly orgLock;
|
|
42
44
|
/** Removing and leaving go through offboarding. */
|
|
43
45
|
private readonly offboarding;
|
|
46
|
+
private readonly budgetCache?;
|
|
44
47
|
constructor(db: KernelDb, txHost: TransactionHost, orgLock: OrgLock,
|
|
45
48
|
/** Removing and leaving go through offboarding. */
|
|
46
|
-
offboarding: Offboarding);
|
|
49
|
+
offboarding: Offboarding, budgetCache?: CacheService | undefined);
|
|
50
|
+
private budgetSettings;
|
|
51
|
+
private budgetView;
|
|
52
|
+
modelBudget(orgId: string, targetId: string): Promise<{
|
|
53
|
+
budget: {
|
|
54
|
+
tokens?: number | undefined;
|
|
55
|
+
spend?: {
|
|
56
|
+
amount: string;
|
|
57
|
+
currency: string;
|
|
58
|
+
} | undefined;
|
|
59
|
+
} | null;
|
|
60
|
+
effective: ModelBudget;
|
|
61
|
+
modelBudgetUsage: import("../models/budget-counters.js").SettledModelUsage;
|
|
62
|
+
}>;
|
|
63
|
+
setModelBudget(orgId: string, targetId: string, budget: ModelBudget | null, actorAccountId: string, actorTokenId?: string, auditDetail?: Record<string, unknown>): Promise<{
|
|
64
|
+
budget: {
|
|
65
|
+
tokens?: number | undefined;
|
|
66
|
+
spend?: {
|
|
67
|
+
amount: string;
|
|
68
|
+
currency: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
} | null;
|
|
71
|
+
effective: ModelBudget;
|
|
72
|
+
}>;
|
|
73
|
+
private setModelBudgetIn;
|
|
47
74
|
list(orgId: string): Promise<Member[]>;
|
|
48
75
|
/**
|
|
49
76
|
* 加入成员(邀请接受等,手动加入的唯一入口);已是成员 → `member.already_exists`;匿名访客 → `member.anonymous_guest`。
|
|
@@ -7,16 +7,21 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
8
8
|
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
9
|
};
|
|
10
|
-
import { Inject, Injectable } from "@nestjs/common";
|
|
10
|
+
import { Inject, Injectable, Optional } from "@nestjs/common";
|
|
11
11
|
import { ApiError } from "../errors.js";
|
|
12
12
|
import { avatarColumns, personAvatarUrl } from "../identity/account-avatar.js";
|
|
13
13
|
import { audit } from "../identity/audit.js";
|
|
14
|
+
import { lockAccountForAdmission } from "../identity/erasure-admission.js";
|
|
15
|
+
import { CacheService } from "../infra/cache/cache.service.js";
|
|
14
16
|
import { afterCommit } from "../infra/database/after-commit.js";
|
|
15
17
|
import { KernelDb } from "../infra/database/kernel-db.js";
|
|
16
|
-
import { TransactionHost } from "../infra/database/transaction-host.js";
|
|
18
|
+
import { TransactionHost, withOrderedLocks } from "../infra/database/transaction-host.js";
|
|
17
19
|
import { Transactional } from "../infra/database/transactional.decorator.js";
|
|
20
|
+
import { readSettledModelUsage } from "../models/budget-counters.js";
|
|
21
|
+
import { orgModelBudgetCacheKey, readMemberBudget, readPlatformModelBudgets, resolveModelBudgets, StoredMemberBudgetsSchema, } from "../models/budget-policy.js";
|
|
18
22
|
import { Offboarding } from "./offboarding.js";
|
|
19
23
|
import { OrgLock } from "./org-lock.js";
|
|
24
|
+
import { survivingOwners } from "./org-owner.js";
|
|
20
25
|
/**
|
|
21
26
|
* 账号是不是某个组织的匿名访客(`org_anonymous_accounts`)。匿名访客没有登录方式,只能以 guest 身份
|
|
22
27
|
* 代表 IM 里未绑定的人:不能被授予别的角色、成为 owner、指派为 agent 负责人、加入别的组织或被移出。
|
|
@@ -46,13 +51,67 @@ let MembersService = class MembersService {
|
|
|
46
51
|
txHost;
|
|
47
52
|
orgLock;
|
|
48
53
|
offboarding;
|
|
54
|
+
budgetCache;
|
|
49
55
|
constructor(db, txHost, orgLock,
|
|
50
56
|
/** Removing and leaving go through offboarding. */
|
|
51
|
-
offboarding) {
|
|
57
|
+
offboarding, budgetCache) {
|
|
52
58
|
this.db = db;
|
|
53
59
|
this.txHost = txHost;
|
|
54
60
|
this.orgLock = orgLock;
|
|
55
61
|
this.offboarding = offboarding;
|
|
62
|
+
this.budgetCache = budgetCache;
|
|
63
|
+
}
|
|
64
|
+
async budgetSettings(orgId, targetId) {
|
|
65
|
+
await this.requireMember(orgId, targetId);
|
|
66
|
+
const row = await this.db
|
|
67
|
+
.selectFrom("orgs")
|
|
68
|
+
.select("settings")
|
|
69
|
+
.where("id", "=", orgId)
|
|
70
|
+
.executeTakeFirstOrThrow();
|
|
71
|
+
return row.settings;
|
|
72
|
+
}
|
|
73
|
+
async budgetView(settings, targetId) {
|
|
74
|
+
const platform = await readPlatformModelBudgets(this.db.db);
|
|
75
|
+
return {
|
|
76
|
+
budget: readMemberBudget(settings, targetId),
|
|
77
|
+
effective: resolveModelBudgets(platform, settings, targetId).member,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
async modelBudget(orgId, targetId) {
|
|
81
|
+
const view = await this.budgetView(await this.budgetSettings(orgId, targetId), targetId);
|
|
82
|
+
return {
|
|
83
|
+
...view,
|
|
84
|
+
modelBudgetUsage: await readSettledModelUsage(this.db.db, orgId, targetId, new Date()),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
async setModelBudget(orgId, targetId, budget, actorAccountId, actorTokenId, auditDetail) {
|
|
88
|
+
return withOrderedLocks(() => this.orgLock.lockFor(orgId, actorAccountId, "org.members.manage"), () => this.setModelBudgetIn(orgId, targetId, budget, actorAccountId, actorTokenId, auditDetail));
|
|
89
|
+
}
|
|
90
|
+
async setModelBudgetIn(orgId, targetId, budget, actorAccountId, actorTokenId, auditDetail) {
|
|
91
|
+
await this.orgLock.lockAndAuthorize(orgId, actorAccountId, "org.members.manage");
|
|
92
|
+
const stored = await this.budgetSettings(orgId, targetId);
|
|
93
|
+
const overrides = { ...StoredMemberBudgetsSchema.parse(stored.memberModelBudgets) };
|
|
94
|
+
const previous = Object.hasOwn(overrides, targetId) ? overrides[targetId] : null;
|
|
95
|
+
if (budget === null)
|
|
96
|
+
delete overrides[targetId];
|
|
97
|
+
else
|
|
98
|
+
overrides[targetId] = budget;
|
|
99
|
+
const updated = { ...stored, memberModelBudgets: overrides };
|
|
100
|
+
await this.db
|
|
101
|
+
.updateTable("orgs")
|
|
102
|
+
.set({ settings: JSON.stringify(updated) })
|
|
103
|
+
.where("id", "=", orgId)
|
|
104
|
+
.execute();
|
|
105
|
+
afterCommit(() => this.budgetCache?.del(orgModelBudgetCacheKey(orgId)));
|
|
106
|
+
await audit(this.db.db, {
|
|
107
|
+
actorAccountId,
|
|
108
|
+
...(actorTokenId !== undefined && { actorTokenId }),
|
|
109
|
+
orgId,
|
|
110
|
+
action: "org.member.model_budget_updated",
|
|
111
|
+
target: targetId,
|
|
112
|
+
detail: { before: previous, after: budget, ...auditDetail },
|
|
113
|
+
});
|
|
114
|
+
return this.budgetView(updated, targetId);
|
|
56
115
|
}
|
|
57
116
|
async list(orgId) {
|
|
58
117
|
const rows = await this.db
|
|
@@ -93,6 +152,7 @@ let MembersService = class MembersService {
|
|
|
93
152
|
*/
|
|
94
153
|
async add(orgId, accountId, role, actorAccountId) {
|
|
95
154
|
await this.orgLock.lock(orgId);
|
|
155
|
+
await lockAccountForAdmission(this.db, accountId);
|
|
96
156
|
await rejectAnonymousGuest(this.db.db, accountId);
|
|
97
157
|
if (await this.roleIn(orgId, accountId)) {
|
|
98
158
|
throw new ApiError("member.already_exists", "Account is already a member");
|
|
@@ -220,6 +280,7 @@ let MembersService = class MembersService {
|
|
|
220
280
|
await rejectAnonymousGuest(this.db.db, toAccountId);
|
|
221
281
|
await this.setRole(orgId, toAccountId, "owner");
|
|
222
282
|
await this.setRole(orgId, fromAccountId, "admin");
|
|
283
|
+
await this.assertHasOwner(orgId);
|
|
223
284
|
await audit(this.db.db, {
|
|
224
285
|
actorAccountId: fromAccountId,
|
|
225
286
|
...(actorTokenId !== undefined && { actorTokenId }),
|
|
@@ -250,6 +311,8 @@ let MembersService = class MembersService {
|
|
|
250
311
|
return role;
|
|
251
312
|
}
|
|
252
313
|
async setRole(orgId, accountId, role) {
|
|
314
|
+
if (role === "owner")
|
|
315
|
+
await lockAccountForAdmission(this.db, accountId);
|
|
253
316
|
await this.db
|
|
254
317
|
.updateTable("memberships")
|
|
255
318
|
.set({ role, updated_at: new Date() })
|
|
@@ -258,17 +321,15 @@ let MembersService = class MembersService {
|
|
|
258
321
|
.execute();
|
|
259
322
|
}
|
|
260
323
|
async assertHasOwner(orgId) {
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
.select((eb) => eb.fn.countAll().as("n"))
|
|
264
|
-
.where("org_id", "=", orgId)
|
|
265
|
-
.where("role", "=", "owner")
|
|
266
|
-
.executeTakeFirstOrThrow();
|
|
267
|
-
if (Number(r.n) === 0) {
|
|
324
|
+
const owner = await survivingOwners(this.db.db, orgId).select("accounts.id").executeTakeFirst();
|
|
325
|
+
if (!owner) {
|
|
268
326
|
throw new ApiError("org.last_owner", "An organization must keep at least one owner");
|
|
269
327
|
}
|
|
270
328
|
}
|
|
271
329
|
};
|
|
330
|
+
__decorate([
|
|
331
|
+
Transactional()
|
|
332
|
+
], MembersService.prototype, "setModelBudgetIn", null);
|
|
272
333
|
__decorate([
|
|
273
334
|
Transactional()
|
|
274
335
|
], MembersService.prototype, "add", null);
|
|
@@ -289,6 +350,8 @@ MembersService = __decorate([
|
|
|
289
350
|
__param(0, Inject(KernelDb)),
|
|
290
351
|
__param(1, Inject(TransactionHost)),
|
|
291
352
|
__param(2, Inject(OrgLock)),
|
|
292
|
-
__param(3, Inject(Offboarding))
|
|
353
|
+
__param(3, Inject(Offboarding)),
|
|
354
|
+
__param(4, Optional()),
|
|
355
|
+
__param(4, Inject(CacheService))
|
|
293
356
|
], MembersService);
|
|
294
357
|
export { MembersService };
|
package/dist/orgs/offboarding.js
CHANGED
|
@@ -36,6 +36,7 @@ import { ApprovalsService } from "../tools/approvals.service.js";
|
|
|
36
36
|
import { Credentials } from "../tools/credentials.js";
|
|
37
37
|
import { QuestionsService } from "../tools/questions.service.js";
|
|
38
38
|
import { OrgLock } from "./org-lock.js";
|
|
39
|
+
import { survivingOwners } from "./org-owner.js";
|
|
39
40
|
/**
|
|
40
41
|
* The stop of a departed member's run (transactional outbox spec §8.1), owed by the offboard
|
|
41
42
|
* transaction on the maintenance queue under {@link runStopJobId}; `MaintenanceProcessor` runs
|
|
@@ -170,12 +171,9 @@ let Offboarding = class Offboarding {
|
|
|
170
171
|
...questionConvs,
|
|
171
172
|
]);
|
|
172
173
|
const isLocked = new Set(locked);
|
|
173
|
-
const owner = await this.db
|
|
174
|
-
.
|
|
175
|
-
.
|
|
176
|
-
.where("org_id", "=", orgId)
|
|
177
|
-
.where("role", "=", "owner")
|
|
178
|
-
.orderBy("created_at")
|
|
174
|
+
const owner = await survivingOwners(this.db.db, orgId)
|
|
175
|
+
.select("memberships.account_id")
|
|
176
|
+
.orderBy("memberships.created_at")
|
|
179
177
|
.orderBy("account_id")
|
|
180
178
|
.limit(1)
|
|
181
179
|
.executeTakeFirst();
|
package/dist/orgs/org-owner.d.ts
CHANGED
|
@@ -5,3 +5,5 @@ import type { KernelSchemaDb } from "../db/kernel-schema.js";
|
|
|
5
5
|
* `created_by` is null, ruling R17) when its org credential lists tools. Undefined: no owner.
|
|
6
6
|
*/
|
|
7
7
|
export declare function firstOrgOwner(db: KernelSchemaDb, orgId: string): Promise<string | undefined>;
|
|
8
|
+
/** While an owner awaits erasure, ownership decisions must preserve a live successor. */
|
|
9
|
+
export declare function survivingOwners(db: KernelSchemaDb, orgId: string): import("kysely").SelectQueryBuilder<import("../db/kernel-schema.js").KernelDatabase, "accounts" | "memberships", {}>;
|
package/dist/orgs/org-owner.js
CHANGED
|
@@ -4,13 +4,28 @@
|
|
|
4
4
|
* `created_by` is null, ruling R17) when its org credential lists tools. Undefined: no owner.
|
|
5
5
|
*/
|
|
6
6
|
export async function firstOrgOwner(db, orgId) {
|
|
7
|
-
const row = await db
|
|
8
|
-
.
|
|
9
|
-
.
|
|
10
|
-
.where("org_id", "=", orgId)
|
|
11
|
-
.where("role", "=", "owner")
|
|
12
|
-
.orderBy("created_at")
|
|
7
|
+
const row = await survivingOwners(db, orgId)
|
|
8
|
+
.select("memberships.account_id")
|
|
9
|
+
.orderBy("memberships.created_at")
|
|
13
10
|
.orderBy("account_id")
|
|
14
11
|
.executeTakeFirst();
|
|
15
12
|
return row?.account_id;
|
|
16
13
|
}
|
|
14
|
+
/** While an owner awaits erasure, ownership decisions must preserve a live successor. */
|
|
15
|
+
export function survivingOwners(db, orgId) {
|
|
16
|
+
return db
|
|
17
|
+
.selectFrom("memberships")
|
|
18
|
+
.innerJoin("accounts", "accounts.id", "memberships.account_id")
|
|
19
|
+
.where("memberships.org_id", "=", orgId)
|
|
20
|
+
.where("memberships.role", "=", "owner")
|
|
21
|
+
.where("accounts.erasure_requested", "=", false)
|
|
22
|
+
.where(({ or, eb, not, exists, selectFrom }) => or([
|
|
23
|
+
eb("accounts.status", "=", "active"),
|
|
24
|
+
not(exists(selectFrom("memberships as pending")
|
|
25
|
+
.innerJoin("accounts as a", "a.id", "pending.account_id")
|
|
26
|
+
.select("a.id")
|
|
27
|
+
.where("pending.org_id", "=", orgId)
|
|
28
|
+
.where("pending.role", "=", "owner")
|
|
29
|
+
.where("a.erasure_requested", "=", true))),
|
|
30
|
+
]));
|
|
31
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { type ApiTokenRecord, ApiTokenService } from "../identity/api-tokens.js";
|
|
3
3
|
import { type Principal } from "../identity/principal.js";
|
|
4
|
+
import { MemberBudgetBody } from "../models/budget-policy.js";
|
|
4
5
|
import { type Member, MembersService } from "./members.service.js";
|
|
5
6
|
import { OrgNetworkAllowances } from "./network-allowances.service.js";
|
|
6
7
|
import { type OrgContext } from "./org.guard.js";
|
|
@@ -59,6 +60,27 @@ export declare class OrgsController {
|
|
|
59
60
|
listNetworkAllowances(org: OrgContext): Promise<{
|
|
60
61
|
allowances: NetworkAllowanceView[];
|
|
61
62
|
}>;
|
|
63
|
+
modelBudget(org: OrgContext, { accountId }: z.infer<typeof MemberParams>): Promise<{
|
|
64
|
+
budget: {
|
|
65
|
+
tokens?: number | undefined;
|
|
66
|
+
spend?: {
|
|
67
|
+
amount: string;
|
|
68
|
+
currency: string;
|
|
69
|
+
} | undefined;
|
|
70
|
+
} | null;
|
|
71
|
+
effective: import("../models/budget-policy.js").ModelBudget;
|
|
72
|
+
modelBudgetUsage: import("../models/budget-counters.js").SettledModelUsage;
|
|
73
|
+
}>;
|
|
74
|
+
setModelBudget(principal: Principal, org: OrgContext, { accountId }: z.infer<typeof MemberParams>, body: z.infer<typeof MemberBudgetBody>): Promise<{
|
|
75
|
+
budget: {
|
|
76
|
+
tokens?: number | undefined;
|
|
77
|
+
spend?: {
|
|
78
|
+
amount: string;
|
|
79
|
+
currency: string;
|
|
80
|
+
} | undefined;
|
|
81
|
+
} | null;
|
|
82
|
+
effective: import("../models/budget-policy.js").ModelBudget;
|
|
83
|
+
}>;
|
|
62
84
|
changeRole(principal: Principal, org: OrgContext, { accountId }: z.infer<typeof MemberParams>, body: z.infer<typeof MemberRoleBody>): Promise<{
|
|
63
85
|
accountId: string;
|
|
64
86
|
role: OrgRole;
|
|
@@ -14,6 +14,7 @@ import { ApiTokenService, FutureIsoDate } from "../identity/api-tokens.js";
|
|
|
14
14
|
import { CurrentPrincipal, patTokenId, requireUser, SessionOnly, } from "../identity/principal.js";
|
|
15
15
|
import { createZodDto } from "../infra/validation/create-zod-dto.js";
|
|
16
16
|
import { ZBody, ZParam } from "../infra/validation/zod-params.js";
|
|
17
|
+
import { MemberBudgetBody } from "../models/budget-policy.js";
|
|
17
18
|
import { MembersService } from "./members.service.js";
|
|
18
19
|
import { OrgNetworkAllowances } from "./network-allowances.service.js";
|
|
19
20
|
import { CurrentOrg, OrgAction } from "./org.guard.js";
|
|
@@ -37,6 +38,8 @@ const ServiceTokenSchema = z.object({
|
|
|
37
38
|
});
|
|
38
39
|
class ServiceTokenBody extends createZodDto(ServiceTokenSchema, "ServiceTokenBody") {
|
|
39
40
|
}
|
|
41
|
+
class MemberBudgetDto extends createZodDto(MemberBudgetBody, "MemberBudget") {
|
|
42
|
+
}
|
|
40
43
|
class MemberRoleBodyDto extends createZodDto(MemberRoleBody, "MemberRoleBody") {
|
|
41
44
|
}
|
|
42
45
|
class MemberParamsDto extends createZodDto(MemberParams, "MemberParams") {
|
|
@@ -94,6 +97,13 @@ let OrgsController = class OrgsController {
|
|
|
94
97
|
async listNetworkAllowances(org) {
|
|
95
98
|
return { allowances: (await this.allowances.list(org.orgId)).map(networkAllowanceView) };
|
|
96
99
|
}
|
|
100
|
+
modelBudget(org, { accountId }) {
|
|
101
|
+
return this.members.modelBudget(org.orgId, accountId);
|
|
102
|
+
}
|
|
103
|
+
setModelBudget(principal, org, { accountId }, body) {
|
|
104
|
+
const person = requireUser(principal);
|
|
105
|
+
return this.members.setModelBudget(org.orgId, accountId, body.budget, person.account.id, patTokenId(person));
|
|
106
|
+
}
|
|
97
107
|
async changeRole(principal, org, { accountId }, body) {
|
|
98
108
|
const p = requireUser(principal);
|
|
99
109
|
await this.members.changeRole(org.orgId, accountId, body.role, p.account.id, patTokenId(p));
|
|
@@ -168,6 +178,20 @@ __decorate([
|
|
|
168
178
|
OrgAction("org.update"),
|
|
169
179
|
__param(0, CurrentOrg())
|
|
170
180
|
], OrgsController.prototype, "listNetworkAllowances", null);
|
|
181
|
+
__decorate([
|
|
182
|
+
Get(":orgId/members/:accountId/model-budget"),
|
|
183
|
+
OrgAction("org.members.manage"),
|
|
184
|
+
__param(0, CurrentOrg()),
|
|
185
|
+
__param(1, ZParam(MemberParamsDto))
|
|
186
|
+
], OrgsController.prototype, "modelBudget", null);
|
|
187
|
+
__decorate([
|
|
188
|
+
Patch(":orgId/members/:accountId/model-budget"),
|
|
189
|
+
OrgAction("org.members.manage"),
|
|
190
|
+
__param(0, CurrentPrincipal()),
|
|
191
|
+
__param(1, CurrentOrg()),
|
|
192
|
+
__param(2, ZParam(MemberParamsDto)),
|
|
193
|
+
__param(3, ZBody(MemberBudgetDto))
|
|
194
|
+
], OrgsController.prototype, "setModelBudget", null);
|
|
171
195
|
__decorate([
|
|
172
196
|
Patch(":orgId/members/:accountId"),
|
|
173
197
|
OrgAction("org.members.manage"),
|
package/dist/orgs/orgs.module.js
CHANGED
|
@@ -7,6 +7,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
7
7
|
import { Module } from "@nestjs/common";
|
|
8
8
|
import { CatalogModule } from "../catalog/catalog.module.js";
|
|
9
9
|
import { EventLogModule } from "../conversations/event-log.js";
|
|
10
|
+
import { ErasureModule } from "../erasure/erasure.module.js";
|
|
10
11
|
import { EvalBudgetModule } from "../evals/budget.js";
|
|
11
12
|
import { ExtensionsModule } from "../extensions/extensions.module.js";
|
|
12
13
|
import { LifecycleHooksModule } from "../extensions/lifecycle-hooks.js";
|
|
@@ -16,6 +17,7 @@ import { PlatformModule } from "../platform/platform.module.js";
|
|
|
16
17
|
import { MAINTENANCE_QUEUE_NAME } from "../runtime/maintenance-queue.js";
|
|
17
18
|
import { RuntimeModule } from "../runtime/runtime.module.js";
|
|
18
19
|
import { SandboxModule } from "../sandbox/sandbox.module.js";
|
|
20
|
+
import { StorageModule } from "../storage/storage.module.js";
|
|
19
21
|
import { ToolsModule } from "../tools/tools.module.js";
|
|
20
22
|
import { DirectorySync } from "./directory-sync.js";
|
|
21
23
|
import { InvitationsService } from "./invitations.service.js";
|
|
@@ -37,6 +39,8 @@ OrgsModule = __decorate([
|
|
|
37
39
|
Module({
|
|
38
40
|
imports: [
|
|
39
41
|
IdentityModule,
|
|
42
|
+
ErasureModule,
|
|
43
|
+
StorageModule,
|
|
40
44
|
// offboarding publishes the events it cancelled
|
|
41
45
|
EventLogModule,
|
|
42
46
|
OrgLockModule,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { MemberBudgetBody } from "../models/budget-policy.js";
|
|
2
3
|
import { INVITABLE_ROLES, MAX_INVITATION_HOURS } from "./invitations.service.js";
|
|
3
4
|
import { ORG_ROLES } from "./roles.js";
|
|
4
5
|
import { OrgSecurityPatchSchema, OrgSecurityQuerySchema } from "./security-settings.service.js";
|
|
@@ -32,6 +33,12 @@ export const ORG_ROUTES = [
|
|
|
32
33
|
params: MemberParams,
|
|
33
34
|
body: MemberRoleBody,
|
|
34
35
|
},
|
|
36
|
+
{ route: "GET /api/v1/orgs/:orgId/members/:accountId/model-budget", params: MemberParams },
|
|
37
|
+
{
|
|
38
|
+
route: "PATCH /api/v1/orgs/:orgId/members/:accountId/model-budget",
|
|
39
|
+
params: MemberParams,
|
|
40
|
+
body: MemberBudgetBody,
|
|
41
|
+
},
|
|
35
42
|
{ route: "DELETE /api/v1/orgs/:orgId/members/:accountId", params: MemberParams },
|
|
36
43
|
{ route: "POST /api/v1/orgs/:orgId/invitations", body: InvitationCreateBody },
|
|
37
44
|
{ route: "GET /api/v1/orgs/:orgId/invitations" },
|