@cat-factory/worker 0.18.6 → 0.20.0
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/infrastructure/config/index.d.ts +2 -2
- package/dist/infrastructure/config/index.d.ts.map +1 -1
- package/dist/infrastructure/config/index.js +1 -2
- package/dist/infrastructure/config/index.js.map +1 -1
- package/dist/infrastructure/config/releaseHealth.d.ts +2 -3
- package/dist/infrastructure/config/releaseHealth.d.ts.map +1 -1
- package/dist/infrastructure/config/releaseHealth.js +2 -12
- package/dist/infrastructure/config/releaseHealth.js.map +1 -1
- package/dist/infrastructure/config/slack.d.ts.map +1 -1
- package/dist/infrastructure/config/slack.js +3 -8
- package/dist/infrastructure/config/slack.js.map +1 -1
- package/dist/infrastructure/config/spending.d.ts +8 -1
- package/dist/infrastructure/config/spending.d.ts.map +1 -1
- package/dist/infrastructure/config/spending.js +10 -34
- package/dist/infrastructure/config/spending.js.map +1 -1
- package/dist/infrastructure/container.d.ts.map +1 -1
- package/dist/infrastructure/container.js +99 -20
- package/dist/infrastructure/container.js.map +1 -1
- package/dist/infrastructure/env.d.ts +8 -16
- package/dist/infrastructure/env.d.ts.map +1 -1
- package/dist/infrastructure/repositories/D1AccountSettingsRepository.d.ts +18 -0
- package/dist/infrastructure/repositories/D1AccountSettingsRepository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/D1AccountSettingsRepository.js +48 -0
- package/dist/infrastructure/repositories/D1AccountSettingsRepository.js.map +1 -0
- package/dist/infrastructure/repositories/D1IncidentEnrichmentConnectionRepository.d.ts +18 -0
- package/dist/infrastructure/repositories/D1IncidentEnrichmentConnectionRepository.d.ts.map +1 -0
- package/dist/infrastructure/repositories/D1IncidentEnrichmentConnectionRepository.js +46 -0
- package/dist/infrastructure/repositories/D1IncidentEnrichmentConnectionRepository.js.map +1 -0
- package/dist/infrastructure/repositories/D1SandboxRepositories.d.ts +47 -0
- package/dist/infrastructure/repositories/D1SandboxRepositories.d.ts.map +1 -0
- package/dist/infrastructure/repositories/D1SandboxRepositories.js +287 -0
- package/dist/infrastructure/repositories/D1SandboxRepositories.js.map +1 -0
- package/dist/infrastructure/repositories/D1TokenUsageRepository.d.ts +1 -0
- package/dist/infrastructure/repositories/D1TokenUsageRepository.d.ts.map +1 -1
- package/dist/infrastructure/repositories/D1TokenUsageRepository.js +16 -0
- package/dist/infrastructure/repositories/D1TokenUsageRepository.js.map +1 -1
- package/dist/infrastructure/repositories/D1WorkspaceSettingsRepository.d.ts.map +1 -1
- package/dist/infrastructure/repositories/D1WorkspaceSettingsRepository.js +21 -14
- package/dist/infrastructure/repositories/D1WorkspaceSettingsRepository.js.map +1 -1
- package/migrations/0012_workspace_budget.sql +14 -0
- package/migrations/0013_incident_enrichment_connections.sql +12 -0
- package/migrations/0014_account_settings.sql +14 -0
- package/package.json +16 -15
- package/sandbox-migrations/0001_init.sql +99 -0
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
1
|
+
function parseJson(raw) {
|
|
2
|
+
if (!raw)
|
|
3
|
+
return null;
|
|
4
|
+
try {
|
|
5
|
+
return JSON.parse(raw);
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return null;
|
|
10
9
|
}
|
|
10
|
+
}
|
|
11
|
+
function rowToSettings(row) {
|
|
11
12
|
return {
|
|
12
13
|
waitingEscalationMinutes: row.waiting_escalation_minutes,
|
|
13
14
|
taskLimitMode: row.task_limit_mode,
|
|
14
15
|
taskLimitShared: row.task_limit_shared,
|
|
15
|
-
taskLimitPerType:
|
|
16
|
+
taskLimitPerType: parseJson(row.task_limit_per_type),
|
|
17
|
+
spendCurrency: row.spend_currency,
|
|
18
|
+
spendMonthlyLimit: row.spend_monthly_limit,
|
|
19
|
+
spendModelPrices: parseJson(row.spend_model_prices),
|
|
16
20
|
};
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
@@ -36,14 +40,17 @@ export class D1WorkspaceSettingsRepository {
|
|
|
36
40
|
await this.db
|
|
37
41
|
.prepare(`INSERT INTO workspace_settings
|
|
38
42
|
(workspace_id, waiting_escalation_minutes, task_limit_mode, task_limit_shared,
|
|
39
|
-
task_limit_per_type)
|
|
40
|
-
VALUES (?, ?, ?, ?, ?)
|
|
43
|
+
task_limit_per_type, spend_currency, spend_monthly_limit, spend_model_prices)
|
|
44
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
41
45
|
ON CONFLICT (workspace_id) DO UPDATE SET
|
|
42
46
|
waiting_escalation_minutes = excluded.waiting_escalation_minutes,
|
|
43
47
|
task_limit_mode = excluded.task_limit_mode,
|
|
44
48
|
task_limit_shared = excluded.task_limit_shared,
|
|
45
|
-
task_limit_per_type = excluded.task_limit_per_type
|
|
46
|
-
|
|
49
|
+
task_limit_per_type = excluded.task_limit_per_type,
|
|
50
|
+
spend_currency = excluded.spend_currency,
|
|
51
|
+
spend_monthly_limit = excluded.spend_monthly_limit,
|
|
52
|
+
spend_model_prices = excluded.spend_model_prices`)
|
|
53
|
+
.bind(workspaceId, settings.waitingEscalationMinutes, settings.taskLimitMode, settings.taskLimitShared, settings.taskLimitPerType ? JSON.stringify(settings.taskLimitPerType) : null, settings.spendCurrency, settings.spendMonthlyLimit, settings.spendModelPrices ? JSON.stringify(settings.spendModelPrices) : null)
|
|
47
54
|
.run();
|
|
48
55
|
}
|
|
49
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"D1WorkspaceSettingsRepository.js","sourceRoot":"","sources":["../../../src/infrastructure/repositories/D1WorkspaceSettingsRepository.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"D1WorkspaceSettingsRepository.js","sourceRoot":"","sources":["../../../src/infrastructure/repositories/D1WorkspaceSettingsRepository.ts"],"names":[],"mappings":"AAmBA,SAAS,SAAS,CAAI,GAAk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AAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,EAC5E,QAAQ,CAAC,aAAa,EACtB,QAAQ,CAAC,iBAAiB,EAC1B,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,IAAI,CAC7E;aACA,GAAG,EAAE,CAAA;IACV,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Per-workspace spend budget. Moved out of the deployment-wide env vars
|
|
2
|
+
-- (SPEND_MONTHLY_LIMIT / SPEND_CURRENCY / SPEND_MODEL_PRICES) onto the workspace
|
|
3
|
+
-- settings row so a budget is tunable per workspace in the UI. All nullable;
|
|
4
|
+
-- NULL ⇒ the built-in DEFAULT_SPEND_PRICING base table.
|
|
5
|
+
ALTER TABLE workspace_settings ADD COLUMN spend_currency TEXT;
|
|
6
|
+
ALTER TABLE workspace_settings ADD COLUMN spend_monthly_limit REAL;
|
|
7
|
+
-- JSON object of per-model price overrides ({ "provider:model": {inputPerMillion, outputPerMillion} }).
|
|
8
|
+
ALTER TABLE workspace_settings ADD COLUMN spend_model_prices TEXT;
|
|
9
|
+
|
|
10
|
+
-- The spend gate now sums a SINGLE workspace's usage since the period start
|
|
11
|
+
-- (`totalsSinceForWorkspace`) on every metered LLM-proxy call + web-search + step,
|
|
12
|
+
-- not just the deployment-wide display rollup. Index (workspace_id, created_at) so that
|
|
13
|
+
-- hot-path aggregate doesn't scan the whole ledger and filter workspace_id row-by-row.
|
|
14
|
+
CREATE INDEX idx_token_usage_workspace ON token_usage (workspace_id, created_at);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Per-workspace incident-enrichment connection (PagerDuty + incident.io). Moved out
|
|
2
|
+
-- of the deployment-wide env vars (PAGERDUTY_API_TOKEN / PAGERDUTY_FROM_EMAIL /
|
|
3
|
+
-- INCIDENTIO_API_KEY) onto a sealed per-workspace row. Both vendors live in ONE sealed
|
|
4
|
+
-- `credentials` blob; `summary` is the non-secret presence map for the UI. Mirrors the
|
|
5
|
+
-- observability_connections shape (migration 0007).
|
|
6
|
+
CREATE TABLE incident_enrichment_connections (
|
|
7
|
+
workspace_id TEXT NOT NULL PRIMARY KEY,
|
|
8
|
+
credentials TEXT NOT NULL, -- sealed JSON { pagerDuty?, incidentIo? }
|
|
9
|
+
summary TEXT NOT NULL DEFAULT '{}', -- non-secret presence JSON
|
|
10
|
+
created_at INTEGER NOT NULL,
|
|
11
|
+
updated_at INTEGER NOT NULL
|
|
12
|
+
);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- Per-account (deployment-wide) settings, moved out of env vars. One row per account.
|
|
2
|
+
-- `config` is non-secret tuning JSON (retention, inline-web-search, enable gates);
|
|
3
|
+
-- `secrets_cipher` is ONE sealed JSON blob grouping every integration credential
|
|
4
|
+
-- (Slack OAuth app, web-search keys, Langfuse keys), domain tag
|
|
5
|
+
-- 'cat-factory:account-settings'; `summary` is non-secret presence JSON for the UI.
|
|
6
|
+
-- A missing row means "all defaults". Mirrors the email_connections per-account shape.
|
|
7
|
+
CREATE TABLE account_settings (
|
|
8
|
+
account_id TEXT NOT NULL PRIMARY KEY,
|
|
9
|
+
config TEXT NOT NULL,
|
|
10
|
+
secrets_cipher TEXT,
|
|
11
|
+
summary TEXT NOT NULL DEFAULT '{}',
|
|
12
|
+
created_at INTEGER NOT NULL,
|
|
13
|
+
updated_at INTEGER NOT NULL
|
|
14
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cat-factory/worker",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.20.0",
|
|
4
4
|
"description": "Reusable Cloudflare Worker library (Hono + D1) exposing the Agent Architecture Board core: the `createApp()` Hono factory, the default fetch/scheduled/queue handler, and the Durable Object + Workflow classes. Deployments (see deploy/backend) supply the wrangler.toml + config and re-export these.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"files": [
|
|
11
11
|
"dist",
|
|
12
|
-
"migrations"
|
|
12
|
+
"migrations",
|
|
13
|
+
"sandbox-migrations"
|
|
13
14
|
],
|
|
14
15
|
"type": "module",
|
|
15
16
|
"main": "./dist/index.js",
|
|
@@ -39,18 +40,18 @@
|
|
|
39
40
|
"pino": "^10.3.1",
|
|
40
41
|
"valibot": "^1.4.1",
|
|
41
42
|
"workers-ai-provider": "^3.2.0",
|
|
42
|
-
"@cat-factory/agents": "0.14.
|
|
43
|
-
"@cat-factory/consensus": "0.7.
|
|
44
|
-
"@cat-factory/contracts": "0.
|
|
45
|
-
"@cat-factory/gates": "0.1.
|
|
46
|
-
"@cat-factory/integrations": "0.
|
|
47
|
-
"@cat-factory/kernel": "0.
|
|
48
|
-
"@cat-factory/observability-langfuse": "0.7.
|
|
49
|
-
"@cat-factory/orchestration": "0.
|
|
50
|
-
"@cat-factory/prompt-fragments": "0.7.
|
|
51
|
-
"@cat-factory/provider-cloudflare": "0.7.
|
|
52
|
-
"@cat-factory/server": "0.
|
|
53
|
-
"@cat-factory/spend": "0.
|
|
43
|
+
"@cat-factory/agents": "0.14.7",
|
|
44
|
+
"@cat-factory/consensus": "0.7.36",
|
|
45
|
+
"@cat-factory/contracts": "0.25.0",
|
|
46
|
+
"@cat-factory/gates": "0.1.4",
|
|
47
|
+
"@cat-factory/integrations": "0.20.0",
|
|
48
|
+
"@cat-factory/kernel": "0.28.0",
|
|
49
|
+
"@cat-factory/observability-langfuse": "0.7.34",
|
|
50
|
+
"@cat-factory/orchestration": "0.21.0",
|
|
51
|
+
"@cat-factory/prompt-fragments": "0.7.22",
|
|
52
|
+
"@cat-factory/provider-cloudflare": "0.7.36",
|
|
53
|
+
"@cat-factory/server": "0.25.0",
|
|
54
|
+
"@cat-factory/spend": "0.9.1"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"@cloudflare/vitest-pool-workers": "^0.16.19",
|
|
@@ -58,7 +59,7 @@
|
|
|
58
59
|
"typescript": "7.0.1-rc",
|
|
59
60
|
"vitest": "^4.1.9",
|
|
60
61
|
"wrangler": "^4.104.0",
|
|
61
|
-
"@cat-factory/conformance": "0.7.
|
|
62
|
+
"@cat-factory/conformance": "0.7.36"
|
|
62
63
|
},
|
|
63
64
|
"scripts": {
|
|
64
65
|
"build": "tsc -b tsconfig.build.json",
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
-- Sandbox (the parallel prompt/model testing surface) — schema for the DEDICATED
|
|
2
|
+
-- `SANDBOX_DB` D1 database (its own binding + migrations lineage, applied separately
|
|
3
|
+
-- from the main DB's `migrations/`). Because this is its own database, the tables are
|
|
4
|
+
-- unprefixed: the database is the namespace. The Node facade mirrors this as a Postgres
|
|
5
|
+
-- `sandbox` schema (Drizzle). Shipped baselines are NOT stored (read live from
|
|
6
|
+
-- `@cat-factory/agents`); only candidate prompt versions are. JSON-shaped fields are
|
|
7
|
+
-- stored as TEXT JSON. See backend/CLAUDE.md "Keep the runtimes symmetric".
|
|
8
|
+
|
|
9
|
+
-- Candidate prompt-version lineages under test (origin always 'candidate').
|
|
10
|
+
CREATE TABLE prompt_versions (
|
|
11
|
+
workspace_id TEXT NOT NULL,
|
|
12
|
+
id TEXT NOT NULL,
|
|
13
|
+
lineage_id TEXT NOT NULL,
|
|
14
|
+
agent_kind TEXT NOT NULL,
|
|
15
|
+
name TEXT NOT NULL,
|
|
16
|
+
origin TEXT NOT NULL,
|
|
17
|
+
system_text TEXT NOT NULL,
|
|
18
|
+
base_prompt_id TEXT,
|
|
19
|
+
version INTEGER NOT NULL,
|
|
20
|
+
parent_id TEXT,
|
|
21
|
+
labels TEXT NOT NULL DEFAULT '[]',
|
|
22
|
+
created_at INTEGER NOT NULL,
|
|
23
|
+
created_by TEXT,
|
|
24
|
+
archived_at INTEGER,
|
|
25
|
+
PRIMARY KEY (workspace_id, id)
|
|
26
|
+
);
|
|
27
|
+
CREATE INDEX idx_sandbox_prompts_kind ON prompt_versions (workspace_id, agent_kind);
|
|
28
|
+
|
|
29
|
+
-- Fixtures (builtins seeded lazily on first list, plus workspace-authored ones).
|
|
30
|
+
CREATE TABLE fixtures (
|
|
31
|
+
workspace_id TEXT NOT NULL,
|
|
32
|
+
id TEXT NOT NULL,
|
|
33
|
+
kind TEXT NOT NULL,
|
|
34
|
+
name TEXT NOT NULL,
|
|
35
|
+
payload TEXT,
|
|
36
|
+
repo_ref TEXT,
|
|
37
|
+
objective TEXT,
|
|
38
|
+
origin TEXT NOT NULL,
|
|
39
|
+
created_at INTEGER NOT NULL,
|
|
40
|
+
PRIMARY KEY (workspace_id, id)
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
-- Experiment definitions (the matrix is a JSON blob).
|
|
44
|
+
CREATE TABLE experiments (
|
|
45
|
+
workspace_id TEXT NOT NULL,
|
|
46
|
+
id TEXT NOT NULL,
|
|
47
|
+
name TEXT NOT NULL,
|
|
48
|
+
agent_kind TEXT NOT NULL,
|
|
49
|
+
judge_model TEXT NOT NULL,
|
|
50
|
+
repeats INTEGER NOT NULL,
|
|
51
|
+
status TEXT NOT NULL,
|
|
52
|
+
matrix TEXT NOT NULL,
|
|
53
|
+
budget_tokens INTEGER,
|
|
54
|
+
created_at INTEGER NOT NULL,
|
|
55
|
+
created_by TEXT,
|
|
56
|
+
PRIMARY KEY (workspace_id, id)
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
-- Individual run cells (the results grid).
|
|
60
|
+
CREATE TABLE runs (
|
|
61
|
+
workspace_id TEXT NOT NULL,
|
|
62
|
+
id TEXT NOT NULL,
|
|
63
|
+
experiment_id TEXT NOT NULL,
|
|
64
|
+
prompt_version_id TEXT NOT NULL,
|
|
65
|
+
model TEXT NOT NULL,
|
|
66
|
+
fixture_id TEXT NOT NULL,
|
|
67
|
+
repeat_index INTEGER NOT NULL,
|
|
68
|
+
status TEXT NOT NULL,
|
|
69
|
+
output_text TEXT,
|
|
70
|
+
usage TEXT,
|
|
71
|
+
latency_ms INTEGER,
|
|
72
|
+
branch TEXT,
|
|
73
|
+
pr_url TEXT,
|
|
74
|
+
diff TEXT,
|
|
75
|
+
error TEXT,
|
|
76
|
+
seed_sha TEXT,
|
|
77
|
+
prompt_label TEXT NOT NULL,
|
|
78
|
+
started_at INTEGER,
|
|
79
|
+
finished_at INTEGER,
|
|
80
|
+
PRIMARY KEY (workspace_id, id)
|
|
81
|
+
);
|
|
82
|
+
CREATE INDEX idx_sandbox_runs_experiment ON runs (workspace_id, experiment_id);
|
|
83
|
+
CREATE INDEX idx_sandbox_runs_queued ON runs (workspace_id, experiment_id, status);
|
|
84
|
+
|
|
85
|
+
-- Per-cell grades (rubric dimension scores + optional objective signal). Grades are
|
|
86
|
+
-- listed per experiment by joining to `runs` on `run_id` (so the row stays a faithful
|
|
87
|
+
-- `SandboxGrade` with no denormalized experiment id).
|
|
88
|
+
CREATE TABLE grades (
|
|
89
|
+
workspace_id TEXT NOT NULL,
|
|
90
|
+
id TEXT NOT NULL,
|
|
91
|
+
run_id TEXT NOT NULL,
|
|
92
|
+
judge_model TEXT NOT NULL,
|
|
93
|
+
scores TEXT NOT NULL DEFAULT '[]',
|
|
94
|
+
weighted_total REAL NOT NULL,
|
|
95
|
+
objective TEXT,
|
|
96
|
+
created_at INTEGER NOT NULL,
|
|
97
|
+
PRIMARY KEY (workspace_id, id)
|
|
98
|
+
);
|
|
99
|
+
CREATE INDEX idx_sandbox_grades_run ON grades (workspace_id, run_id);
|