@composable-os/cli 0.0.0-stage → 0.1.0-beta.11
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/LICENSE +109 -0
- package/README.md +24 -2
- package/dist/accounts-UHYLCLEY.js +45 -0
- package/dist/blocks-5IFU25J6.js +233 -0
- package/dist/chunk-2ABSVMGB.js +13 -0
- package/dist/chunk-2IVEVPMY.js +669 -0
- package/dist/chunk-2TWV3SVB.js +349 -0
- package/dist/chunk-2XC5JLBO.js +1931 -0
- package/dist/chunk-324WJXNP.js +320 -0
- package/dist/chunk-5KSXSK7Y.js +47 -0
- package/dist/chunk-6ELZRNUU.js +116 -0
- package/dist/chunk-6UWRT4VM.js +220 -0
- package/dist/chunk-6WGFA2IV.js +643 -0
- package/dist/chunk-6XTU2MTP.js +11278 -0
- package/dist/chunk-7CQGMVDO.js +63 -0
- package/dist/chunk-7D4GKZOX.js +615 -0
- package/dist/chunk-7OGCMQXG.js +284 -0
- package/dist/chunk-DHS2CV2M.js +139 -0
- package/dist/chunk-DU6OIFOU.js +2358 -0
- package/dist/chunk-E4WCYTCT.js +347 -0
- package/dist/chunk-E64SG24J.js +88 -0
- package/dist/chunk-FJIZGS5Q.js +698 -0
- package/dist/chunk-GYTEW66E.js +50 -0
- package/dist/chunk-HDIOVFAZ.js +544 -0
- package/dist/chunk-K34UKWEI.js +298 -0
- package/dist/chunk-KGHA67HG.js +765 -0
- package/dist/chunk-LAAL4YGR.js +365 -0
- package/dist/chunk-LO6WGU5Y.js +26189 -0
- package/dist/chunk-MBIKVRAC.js +1425 -0
- package/dist/chunk-P6UWZ6QQ.js +426 -0
- package/dist/chunk-PDD2ETVF.js +1302 -0
- package/dist/chunk-UB4I2QKR.js +31575 -0
- package/dist/chunk-WHKJGF36.js +2418 -0
- package/dist/chunk-XIDLW3EP.js +15471 -0
- package/dist/chunk-YFTLIEWU.js +504 -0
- package/dist/chunk-YNUZRTPH.js +182 -0
- package/dist/chunk-ZAWES2UD.js +9364 -0
- package/dist/chunk-ZZFWMVJO.js +704 -0
- package/dist/cli-5UNY5G5L.js +136 -0
- package/dist/cli-UYZMVQMR.js +24534 -0
- package/dist/cli.js +25 -0
- package/dist/client-repo-SE4EKG6W.js +55 -0
- package/dist/create.js +25 -0
- package/dist/fields-FTWWMD7N.js +50 -0
- package/dist/grants-LOW6TSWD.js +32 -0
- package/dist/invoke-6KVT6WJI.js +41 -0
- package/dist/moves-E2HKYCTK.js +41 -0
- package/dist/order-U4KZLLSJ.js +19 -0
- package/dist/person-UHLVBVLR.js +67 -0
- package/dist/plan-on-sale-TJPFCNL7.js +26 -0
- package/dist/platform/migrations/0001_init.sql +59 -0
- package/dist/platform/migrations/0002_users_settings.sql +34 -0
- package/dist/platform/migrations/0003_people_organisations.sql +225 -0
- package/dist/platform/migrations/0004_activities_tasks.sql +88 -0
- package/dist/platform/migrations/0005_views_audit.sql +79 -0
- package/dist/platform/migrations/0006_search.sql +223 -0
- package/dist/platform/migrations/0007_crm_views.sql +141 -0
- package/dist/platform/migrations/0008_audit_redaction.sql +116 -0
- package/dist/platform/migrations/0010_approval_queue.sql +90 -0
- package/dist/platform/migrations/0011_connected_apps.sql +36 -0
- package/dist/platform/migrations/0020_extensions.sql +373 -0
- package/dist/platform/migrations/0030_extension_proposals.sql +29 -0
- package/dist/platform/migrations/0050_live_row_indexes.sql +32 -0
- package/dist/platform/migrations/0060_audit_read_counts.sql +31 -0
- package/dist/platform/migrations/0061_audit_retention.sql +95 -0
- package/dist/platform/migrations/0062_run_history_retention.sql +6 -0
- package/dist/platform/migrations/0063_pending_action_compaction.sql +18 -0
- package/dist/platform/migrations/0064_drop_rate_limit.sql +6 -0
- package/dist/platform/migrations/0065_storage_stats.sql +13 -0
- package/dist/platform/migrations/0070_drop_proposals_ext_idx.sql +9 -0
- package/dist/platform/migrations/0080_views_dashboards.sql +46 -0
- package/dist/platform/migrations/0100_stage_history.sql +54 -0
- package/dist/platform/migrations/0110_integrations.sql +103 -0
- package/dist/platform/migrations/0111_email_calendar_sync.sql +137 -0
- package/dist/platform/migrations/0112_sync_item_occurred_at.sql +8 -0
- package/dist/platform/migrations/0130_automations.sql +113 -0
- package/dist/platform/migrations/0131_notifications.sql +29 -0
- package/dist/platform/migrations/0132_automation_runtime.sql +14 -0
- package/dist/platform/migrations/0150_ai_summaries_embeddings.sql +48 -0
- package/dist/platform/migrations/0160_releases.sql +41 -0
- package/dist/platform/migrations/0161_setup_wizard.sql +30 -0
- package/dist/platform/migrations/0170_automation_connections.sql +32 -0
- package/dist/platform/migrations/0171_automation_outbox.sql +23 -0
- package/dist/platform/migrations/0172_notification_delivery.sql +46 -0
- package/dist/platform/migrations/0200_assistant_conversations.sql +25 -0
- package/dist/platform/migrations/0205_policy_adjudicator.sql +61 -0
- package/dist/platform/migrations/0210_daily_digest.sql +33 -0
- package/dist/platform/migrations/0220_entitlements.sql +13 -0
- package/dist/platform/migrations/0221_support_grants.sql +33 -0
- package/dist/platform/migrations/0250_judge.sql +11 -0
- package/dist/platform/migrations/0251_adjudication_judgement.sql +8 -0
- package/dist/platform/migrations/0252_judge_usage.sql +14 -0
- package/dist/platform/migrations/0255_summary_checks.sql +9 -0
- package/dist/platform/migrations/0256_outbound_check.sql +9 -0
- package/dist/platform/migrations/0260_ai_usage.sql +20 -0
- package/dist/platform/migrations/0270_assistant_conversation_refs.sql +29 -0
- package/dist/platform/migrations/0310_assignment_rules.sql +54 -0
- package/dist/platform/migrations/0320_duplicates.sql +41 -0
- package/dist/platform/migrations/0330_erase_completeness.sql +54 -0
- package/dist/platform/migrations/0350_assistant_thread.sql +38 -0
- package/dist/platform/migrations/0351_assistant_model_roles.sql +26 -0
- package/dist/platform/migrations/0352_assistant_memory.sql +74 -0
- package/dist/platform/migrations/0358_ai_cache_observation.sql +24 -0
- package/dist/platform/migrations/0359_ai_compaction_decision.sql +25 -0
- package/dist/platform/migrations/0360_ai_cache_estimate.sql +35 -0
- package/dist/platform/migrations/0361_voice_preferences.sql +27 -0
- package/dist/platform/migrations/0362_voice_usage.sql +17 -0
- package/dist/platform/migrations/0365_routines.sql +38 -0
- package/dist/platform/migrations/0370_approval_execution.sql +20 -0
- package/dist/platform/migrations/0371_agent_jobs.sql +65 -0
- package/dist/platform/migrations/0380_rec_views.sql +94 -0
- package/dist/platform/migrations/0400_customer_audit_actor.sql +142 -0
- package/dist/platform/migrations/0401_customer_accounts.sql +61 -0
- package/dist/platform/migrations/0402_erase_requests.sql +34 -0
- package/dist/platform/migrations/0410_idempotency_keys.sql +45 -0
- package/dist/platform/migrations/0411_device_sessions.sql +33 -0
- package/dist/platform/migrations/0420_transition_history.sql +100 -0
- package/dist/platform/migrations/0421_orders.sql +134 -0
- package/dist/platform/migrations/0422_order_payments.sql +109 -0
- package/dist/platform/migrations/0440_capacity.sql +100 -0
- package/dist/platform/migrations/0441_capacity_views.sql +40 -0
- package/dist/platform/migrations/0450_order_grants.sql +21 -0
- package/dist/platform/migrations/0451_pack_roles.sql +18 -0
- package/dist/platform/migrations/0460_content.sql +59 -0
- package/dist/platform/migrations/0461_media.sql +52 -0
- package/dist/platform/migrations/0470_publish_versions.sql +36 -0
- package/dist/platform/migrations/0471_permission_grants.sql +18 -0
- package/dist/platform/migrations/0490_staff_invites.sql +40 -0
- package/dist/platform/migrations/0491_sign_in_mail_kind.sql +10 -0
- package/dist/platform/migrations/0492_email_confirmation_and_sign_in_confirm.sql +30 -0
- package/dist/platform/migrations/0500_published_media_field.sql +25 -0
- package/dist/platform/migrations/0501_import_keys.sql +23 -0
- package/dist/platform/migrations/0510_video_and_file_media.sql +109 -0
- package/dist/platform/migrations/0516_order_tax.sql +63 -0
- package/dist/platform/migrations/0520_publish_requests.sql +20 -0
- package/dist/platform/migrations/0530_subscriptions.sql +173 -0
- package/dist/platform/migrations/0531_subscription_trials.sql +56 -0
- package/dist/platform/migrations/0532_subscription_offers.sql +80 -0
- package/dist/platform/migrations/0533_allowances.sql +262 -0
- package/dist/platform/migrations/0560_recurring.sql +75 -0
- package/dist/platform/migrations/0580_subscription_grants.sql +21 -0
- package/dist/platform/migrations/0581_once_per_person.sql +34 -0
- package/dist/platform/migrations/0600_tool_actions_ran_at_queue.sql +22 -0
- package/dist/platform/migrations/0610_waitlists.sql +54 -0
- package/dist/platform/migrations/0630_subscription_changes.sql +122 -0
- package/dist/platform/migrations/0650_person_links.sql +90 -0
- package/dist/platform/migrations/0670_unmoved_guard.sql +52 -0
- package/dist/platform/migrations/0690_sellable_refund_due.sql +98 -0
- package/dist/platform/sdk/allowance.ts +522 -0
- package/dist/platform/sdk/automation-check.ts +534 -0
- package/dist/platform/sdk/automation.ts +743 -0
- package/dist/platform/sdk/behaviour.ts +215 -0
- package/dist/platform/sdk/capacity.ts +303 -0
- package/dist/platform/sdk/contract.ts +909 -0
- package/dist/platform/sdk/document.ts +935 -0
- package/dist/platform/sdk/field-types.ts +111 -0
- package/dist/platform/sdk/formula/ast.ts +72 -0
- package/dist/platform/sdk/formula/compile.ts +454 -0
- package/dist/platform/sdk/formula/index.ts +4 -0
- package/dist/platform/sdk/formula/parser.ts +417 -0
- package/dist/platform/sdk/index.ts +36 -0
- package/dist/platform/sdk/manifest.ts +1785 -0
- package/dist/platform/sdk/media.ts +108 -0
- package/dist/platform/sdk/permissions.ts +60 -0
- package/dist/platform/sdk/recurring.ts +321 -0
- package/dist/platform/sdk/renamed.ts +63 -0
- package/dist/platform/sdk/rich-text-fixture.ts +68 -0
- package/dist/platform/sdk/rich-text.ts +221 -0
- package/dist/platform/sdk/runtime.ts +410 -0
- package/dist/platform/sdk/sellable.ts +1138 -0
- package/dist/platform/sdk/slug.ts +25 -0
- package/dist/platform/sdk/states.ts +598 -0
- package/dist/platform/sdk/testing.ts +847 -0
- package/dist/platform/sdk/unique.ts +81 -0
- package/dist/products-2H5DR232.js +11 -0
- package/dist/run-7P4RQALH.js +648 -0
- package/dist/run-PO3W5BFA.js +508 -0
- package/dist/run-ZCGFMEZF.js +309 -0
- package/dist/src-CRO35DYY.js +46 -0
- package/dist/src-I3IJ4NKC.js +354 -0
- package/dist/token-MOJUA2U6.js +70 -0
- package/dist/token-util-TENRN4V7.js +6 -0
- package/dist/visibility-TVXZ67FD.js +41 -0
- package/package.json +33 -4
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
jsonList,
|
|
4
|
+
notifyStatements
|
|
5
|
+
} from "./chunk-ZZFWMVJO.js";
|
|
6
|
+
import {
|
|
7
|
+
sql
|
|
8
|
+
} from "./chunk-6XTU2MTP.js";
|
|
9
|
+
import {
|
|
10
|
+
automationManifestSchema
|
|
11
|
+
} from "./chunk-LO6WGU5Y.js";
|
|
12
|
+
|
|
13
|
+
// ../core/src/integrations/catalogue.ts
|
|
14
|
+
var CATALOGUE = [
|
|
15
|
+
{
|
|
16
|
+
vendor: "google",
|
|
17
|
+
title: "Google Workspace",
|
|
18
|
+
description: "Gmail, Google Calendar and Drive. Syncs mail and meetings onto timelines.",
|
|
19
|
+
connect: "oauth",
|
|
20
|
+
scopes: ["personal", "org"],
|
|
21
|
+
sync: {
|
|
22
|
+
mail: ["https://mail.google.com/"],
|
|
23
|
+
calendar: ["https://calendar.google.com/"]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
vendor: "microsoft",
|
|
28
|
+
title: "Microsoft 365",
|
|
29
|
+
description: "Outlook mail, Outlook Calendar and SharePoint. Syncs mail and meetings.",
|
|
30
|
+
connect: "oauth",
|
|
31
|
+
scopes: ["personal", "org"],
|
|
32
|
+
sync: {
|
|
33
|
+
mail: ["https://outlook.office.com/"],
|
|
34
|
+
calendar: ["https://outlook.office.com/calendar"]
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
vendor: "slack",
|
|
39
|
+
title: "Slack",
|
|
40
|
+
description: "Read channels and threads, and post messages and DMs (with the Slack posting gatekeeper, through the same Slack app).",
|
|
41
|
+
connect: "oauth",
|
|
42
|
+
scopes: ["personal", "org"],
|
|
43
|
+
companion: "slack-post"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
vendor: "slack-post",
|
|
47
|
+
title: "Slack (post messages)",
|
|
48
|
+
description: "Post to channels and send DMs as the CRM's Slack bot.",
|
|
49
|
+
connect: "oauth",
|
|
50
|
+
scopes: ["org"]
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
vendor: "mcp",
|
|
54
|
+
title: "MCP server",
|
|
55
|
+
description: "Connect any remote MCP server and use its tools through a gatekeeper.",
|
|
56
|
+
connect: "oauth",
|
|
57
|
+
scopes: ["personal", "org"]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
vendor: "email",
|
|
61
|
+
title: "Inbound email",
|
|
62
|
+
description: "Receive mail at a CRM address (Cloudflare Email Routing).",
|
|
63
|
+
connect: "oauth",
|
|
64
|
+
scopes: ["org"]
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
vendor: "email-send",
|
|
68
|
+
title: "Email sending",
|
|
69
|
+
description: "Send email from the CRM's own addresses (Cloudflare Email Service).",
|
|
70
|
+
connect: "auto",
|
|
71
|
+
scopes: ["org"]
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
vendor: "zoominfo",
|
|
75
|
+
title: "ZoomInfo",
|
|
76
|
+
description: "Manual, approved 'Enrich now' on people and organisations. No polling.",
|
|
77
|
+
connect: "oauth",
|
|
78
|
+
scopes: ["org"]
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
vendor: "websearch",
|
|
82
|
+
title: "Web search",
|
|
83
|
+
description: "Search the public web (Cloudflare Web Search). Searches are observations.",
|
|
84
|
+
connect: "auto",
|
|
85
|
+
scopes: ["personal", "org"],
|
|
86
|
+
singleton: true
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
vendor: "webhook",
|
|
90
|
+
title: "Inbound webhooks",
|
|
91
|
+
description: "External systems post signed events to the CRM. Bad signatures are rejected; good ones become typed events for automations.",
|
|
92
|
+
connect: "auto",
|
|
93
|
+
scopes: ["org"]
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
vendor: "payments",
|
|
97
|
+
title: "Payments",
|
|
98
|
+
description: "Take payment for orders on the provider's own page (Stripe), into your own account. Keys stay in the gatekeeper; card details never reach the CRM.",
|
|
99
|
+
connect: "auto",
|
|
100
|
+
scopes: ["org"]
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
vendor: "fake",
|
|
104
|
+
title: "Fake provider (development)",
|
|
105
|
+
description: "A fake OAuth provider with a mailbox and calendar, for development and tests.",
|
|
106
|
+
connect: "oauth",
|
|
107
|
+
scopes: ["personal", "org"],
|
|
108
|
+
sync: { mail: ["fake://mailbox/"], calendar: ["fake://calendar/"] },
|
|
109
|
+
devOnly: true
|
|
110
|
+
}
|
|
111
|
+
];
|
|
112
|
+
function catalogueEntry(vendor) {
|
|
113
|
+
return CATALOGUE.find((entry) => entry.vendor === vendor);
|
|
114
|
+
}
|
|
115
|
+
function syncKindOf(vendor, url) {
|
|
116
|
+
const entry = catalogueEntry(vendor);
|
|
117
|
+
for (const kind of ["calendar", "mail"]) {
|
|
118
|
+
if (entry?.sync?.[kind]?.some((prefix) => url.startsWith(prefix))) return kind;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// ../core/src/automations/bindings.ts
|
|
124
|
+
var WAITING_FOR_CONNECTIONS = "Waiting for connections";
|
|
125
|
+
var CONNECTION_REVOKED_PREFIX = "Connection revoked";
|
|
126
|
+
function toBinding(row) {
|
|
127
|
+
return {
|
|
128
|
+
automationId: row.automation_id,
|
|
129
|
+
slot: row.slot,
|
|
130
|
+
gatekeeper: row.gatekeeper,
|
|
131
|
+
purpose: row.purpose,
|
|
132
|
+
connectionId: row.connection_id,
|
|
133
|
+
boundBy: row.bound_by,
|
|
134
|
+
boundAt: row.bound_at,
|
|
135
|
+
revokedAt: row.revoked_at,
|
|
136
|
+
revokedBy: row.revoked_by,
|
|
137
|
+
revokeReason: row.revoke_reason
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function declaredConnections(spec) {
|
|
141
|
+
return spec.connections ?? [];
|
|
142
|
+
}
|
|
143
|
+
function connectionServes(vendor, gatekeeper) {
|
|
144
|
+
return vendor === gatekeeper || catalogueEntry(vendor)?.companion === gatekeeper;
|
|
145
|
+
}
|
|
146
|
+
async function loadBindings(db, automationIds) {
|
|
147
|
+
if (!automationIds.length) return [];
|
|
148
|
+
const rows = await db.selectFrom("core_automation_binding").selectAll().where("automation_id", "in", jsonList([...new Set(automationIds)])).execute();
|
|
149
|
+
return rows.map(toBinding);
|
|
150
|
+
}
|
|
151
|
+
function unboundSlots(spec, bindings) {
|
|
152
|
+
return declaredConnections(spec).filter(
|
|
153
|
+
(c) => !bindings.some((b) => b.slot === c.id && b.revokedAt === null)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
async function revokeBindingsPlan(db, target, input) {
|
|
157
|
+
let connectionIds;
|
|
158
|
+
if ("connectionId" in target) {
|
|
159
|
+
connectionIds = [target.connectionId];
|
|
160
|
+
} else {
|
|
161
|
+
const owned = await db.selectFrom("core_integration_connection").select("id").where("owner_user_id", "=", target.ownerUserId).execute();
|
|
162
|
+
connectionIds = owned.map((r) => r.id);
|
|
163
|
+
}
|
|
164
|
+
if (!connectionIds.length) return { statements: [], automationIds: [], revoked: 0 };
|
|
165
|
+
const live = await db.selectFrom("core_automation_binding as b").innerJoin("core_automations as a", "a.id", "b.automation_id").select(["b.automation_id", "b.slot", "a.label", "a.paused_reason"]).where("b.connection_id", "in", jsonList(connectionIds)).where("b.revoked_at", "is", null).execute();
|
|
166
|
+
if (!live.length) return { statements: [], automationIds: [], revoked: 0 };
|
|
167
|
+
const statements = [
|
|
168
|
+
db.updateTable("core_automation_binding").set({ revoked_at: input.now, revoked_by: input.by, revoke_reason: input.reason }).where("connection_id", "in", jsonList(connectionIds)).where("revoked_at", "is", null)
|
|
169
|
+
];
|
|
170
|
+
const automations = /* @__PURE__ */ new Map();
|
|
171
|
+
for (const row of live) {
|
|
172
|
+
automations.set(row.automation_id, { label: row.label, paused: row.paused_reason !== null });
|
|
173
|
+
}
|
|
174
|
+
const pauseReason = `${CONNECTION_REVOKED_PREFIX}: ${input.reason}`;
|
|
175
|
+
statements.push(
|
|
176
|
+
db.updateTable("core_automations").set({ paused_reason: pauseReason, paused_at: input.now, updated_at: input.now }).where("id", "in", jsonList([...automations.keys()])).where(sql`(paused_reason IS NULL OR paused_reason = ${WAITING_FOR_CONNECTIONS})`)
|
|
177
|
+
);
|
|
178
|
+
for (const [id, a] of automations) {
|
|
179
|
+
const plan = await notifyStatements(
|
|
180
|
+
db,
|
|
181
|
+
{
|
|
182
|
+
to: [{ role: "admin" }],
|
|
183
|
+
type: "automation.paused",
|
|
184
|
+
title: `\u201C${a.label}\u201D was paused`,
|
|
185
|
+
body: `${input.reason}. Bind another connection on the automation page, then enable it again.`,
|
|
186
|
+
link: { kind: "automation", automationId: id },
|
|
187
|
+
dedupeKey: `revoked:${id}:${input.now}`,
|
|
188
|
+
source: { actor: "automation", automationId: id }
|
|
189
|
+
},
|
|
190
|
+
input.now
|
|
191
|
+
);
|
|
192
|
+
statements.push(...plan.statements);
|
|
193
|
+
}
|
|
194
|
+
return { statements, automationIds: [...automations.keys()], revoked: live.length };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// ../core/src/automations/types.ts
|
|
198
|
+
var MAX_CASCADE_DEPTH = 3;
|
|
199
|
+
var EVENT_CHANGES_PER_MESSAGE = 100;
|
|
200
|
+
var QUEUE_MESSAGE_MAX_BYTES = 12e4;
|
|
201
|
+
var AUTOMATION_SETTINGS = {
|
|
202
|
+
/** boolean. Human admins only (automation.killSwitch). Pauses every automation at once. */
|
|
203
|
+
killSwitch: "automations_kill_switch",
|
|
204
|
+
/** IANA timezone schedules and date-relative triggers are evaluated in. Default "UTC". */
|
|
205
|
+
timezone: "automation_timezone",
|
|
206
|
+
/** Seconds within which `updated` events for one record coalesce. Default 30. */
|
|
207
|
+
debounceSeconds: "automation_debounce_seconds"
|
|
208
|
+
};
|
|
209
|
+
var DEFAULT_RAILS = {
|
|
210
|
+
maxRunsPerMinute: 60,
|
|
211
|
+
maxWritesPerHour: 500,
|
|
212
|
+
debounceSeconds: 30
|
|
213
|
+
};
|
|
214
|
+
var RUN_STATUSES = [
|
|
215
|
+
/** Row written, Workflow not yet running. */
|
|
216
|
+
"queued",
|
|
217
|
+
"running",
|
|
218
|
+
/** In a step.sleep or step.waitForEvent. */
|
|
219
|
+
"waiting",
|
|
220
|
+
/** Paused on a pending action (review) until a person decides. */
|
|
221
|
+
"review",
|
|
222
|
+
"completed",
|
|
223
|
+
"failed",
|
|
224
|
+
/** Stopped: rejected (onRejected stop), cancelled by a person, or the kill switch. */
|
|
225
|
+
"cancelled",
|
|
226
|
+
/** Its pending action expired. */
|
|
227
|
+
"expired",
|
|
228
|
+
/** Not started: a rail dropped it (depth, cycle, budget, rate, paused, kill switch). */
|
|
229
|
+
"skipped"
|
|
230
|
+
];
|
|
231
|
+
var DRAFT_TARGET_ERRORS = ["unknown_automation", "evaluate_failed"];
|
|
232
|
+
|
|
233
|
+
// ../core/src/automations/registry.ts
|
|
234
|
+
function triggerObject(spec) {
|
|
235
|
+
const t = spec.trigger;
|
|
236
|
+
return "object" in t && typeof t.object === "string" ? t.object : null;
|
|
237
|
+
}
|
|
238
|
+
function automationSyncStatements(db, input) {
|
|
239
|
+
const statements = [];
|
|
240
|
+
const ids = [];
|
|
241
|
+
for (const [key, spec] of Object.entries(input.automations)) {
|
|
242
|
+
const id = `${input.extensionId}.${key}`;
|
|
243
|
+
ids.push(id);
|
|
244
|
+
const values = {
|
|
245
|
+
label: spec.label,
|
|
246
|
+
trigger_type: spec.trigger.type,
|
|
247
|
+
trigger_object: triggerObject(spec),
|
|
248
|
+
spec: JSON.stringify(spec),
|
|
249
|
+
commit_oid: input.commit,
|
|
250
|
+
removed_at: null,
|
|
251
|
+
updated_at: input.now
|
|
252
|
+
};
|
|
253
|
+
statements.push(
|
|
254
|
+
db.insertInto("core_automations").values({
|
|
255
|
+
id,
|
|
256
|
+
extension_id: input.extensionId,
|
|
257
|
+
key,
|
|
258
|
+
...values,
|
|
259
|
+
// Shipped turned off (ADR 0246) until a person turns it on.
|
|
260
|
+
enabled: spec.enabled === false ? 0 : 1,
|
|
261
|
+
// An automation that needs connections waits until a person binds them (ADR 0170).
|
|
262
|
+
paused_reason: spec.connections?.length ? WAITING_FOR_CONNECTIONS : null,
|
|
263
|
+
paused_at: spec.connections?.length ? input.now : null,
|
|
264
|
+
created_at: input.now
|
|
265
|
+
}).onConflict((oc) => oc.column("id").doUpdateSet(values))
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
let removed = db.updateTable("core_automations").set({ removed_at: input.now, updated_at: input.now }).where("extension_id", "=", input.extensionId).where("removed_at", "is", null);
|
|
269
|
+
if (ids.length) removed = removed.where("id", "not in", jsonList(ids));
|
|
270
|
+
statements.push(removed);
|
|
271
|
+
return statements;
|
|
272
|
+
}
|
|
273
|
+
function parseSpec(json) {
|
|
274
|
+
try {
|
|
275
|
+
const parsed = automationManifestSchema.safeParse(JSON.parse(json));
|
|
276
|
+
return parsed.success ? parsed.data : null;
|
|
277
|
+
} catch {
|
|
278
|
+
return null;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
async function loadAutomationSettings(db) {
|
|
282
|
+
const rows = await db.selectFrom("core_settings").select(["key", "value"]).where("key", "in", [
|
|
283
|
+
AUTOMATION_SETTINGS.killSwitch,
|
|
284
|
+
AUTOMATION_SETTINGS.timezone,
|
|
285
|
+
AUTOMATION_SETTINGS.debounceSeconds
|
|
286
|
+
]).execute();
|
|
287
|
+
const value = (key) => {
|
|
288
|
+
const row = rows.find((r) => r.key === key);
|
|
289
|
+
if (!row) return void 0;
|
|
290
|
+
try {
|
|
291
|
+
return JSON.parse(row.value);
|
|
292
|
+
} catch {
|
|
293
|
+
return void 0;
|
|
294
|
+
}
|
|
295
|
+
};
|
|
296
|
+
const tz = value(AUTOMATION_SETTINGS.timezone);
|
|
297
|
+
const debounce = value(AUTOMATION_SETTINGS.debounceSeconds);
|
|
298
|
+
return {
|
|
299
|
+
// Engaged only when the stored value is exactly true.
|
|
300
|
+
killSwitch: value(AUTOMATION_SETTINGS.killSwitch) === true,
|
|
301
|
+
timezone: typeof tz === "string" && isTimeZone(tz) ? tz : "UTC",
|
|
302
|
+
debounceSeconds: typeof debounce === "number" && debounce >= 0 ? debounce : DEFAULT_RAILS.debounceSeconds
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
function isTimeZone(tz) {
|
|
306
|
+
try {
|
|
307
|
+
new Intl.DateTimeFormat("en-US", { timeZone: tz });
|
|
308
|
+
return true;
|
|
309
|
+
} catch {
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function effectiveRails(spec, settings) {
|
|
314
|
+
return {
|
|
315
|
+
maxRunsPerMinute: Math.min(
|
|
316
|
+
spec.rails?.maxRunsPerMinute ?? DEFAULT_RAILS.maxRunsPerMinute,
|
|
317
|
+
DEFAULT_RAILS.maxRunsPerMinute
|
|
318
|
+
),
|
|
319
|
+
maxWritesPerHour: Math.min(
|
|
320
|
+
spec.rails?.maxWritesPerHour ?? DEFAULT_RAILS.maxWritesPerHour,
|
|
321
|
+
DEFAULT_RAILS.maxWritesPerHour
|
|
322
|
+
),
|
|
323
|
+
debounceSeconds: spec.rails?.debounceSeconds ?? settings.debounceSeconds
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export {
|
|
328
|
+
CATALOGUE,
|
|
329
|
+
catalogueEntry,
|
|
330
|
+
syncKindOf,
|
|
331
|
+
WAITING_FOR_CONNECTIONS,
|
|
332
|
+
declaredConnections,
|
|
333
|
+
connectionServes,
|
|
334
|
+
loadBindings,
|
|
335
|
+
unboundSlots,
|
|
336
|
+
revokeBindingsPlan,
|
|
337
|
+
MAX_CASCADE_DEPTH,
|
|
338
|
+
EVENT_CHANGES_PER_MESSAGE,
|
|
339
|
+
QUEUE_MESSAGE_MAX_BYTES,
|
|
340
|
+
AUTOMATION_SETTINGS,
|
|
341
|
+
RUN_STATUSES,
|
|
342
|
+
DRAFT_TARGET_ERRORS,
|
|
343
|
+
triggerObject,
|
|
344
|
+
automationSyncStatements,
|
|
345
|
+
parseSpec,
|
|
346
|
+
loadAutomationSettings,
|
|
347
|
+
isTimeZone,
|
|
348
|
+
effectiveRails
|
|
349
|
+
};
|