@composable-os/sdk 0.1.0-beta.10 → 0.1.0-beta.13
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/acknowledge.d.ts +38 -0
- package/dist/acknowledge.js +30 -0
- package/dist/agreements.d.ts +80 -0
- package/dist/agreements.js +109 -0
- package/dist/allowance.d.ts +47 -5
- package/dist/allowance.js +59 -4
- package/dist/automation-check.d.ts +6 -1
- package/dist/automation-check.js +93 -8
- package/dist/automation.d.ts +62 -4
- package/dist/automation.js +32 -9
- package/dist/behaviour.js +25 -6
- package/dist/calendar-entry.d.ts +97 -0
- package/dist/calendar-entry.js +180 -0
- package/dist/capacity.d.ts +69 -0
- package/dist/capacity.js +63 -2
- package/dist/checklists.d.ts +41 -0
- package/dist/checklists.js +75 -0
- package/dist/contract.d.ts +527 -26
- package/dist/contract.js +21 -3
- package/dist/discount.d.ts +135 -0
- package/dist/discount.js +281 -0
- package/dist/document.d.ts +2 -1
- package/dist/document.js +2 -1
- package/dist/field-types.d.ts +1 -1
- package/dist/field-types.js +5 -0
- package/dist/formula/compile.d.ts +15 -0
- package/dist/formula/compile.js +9 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +17 -0
- package/dist/intake.d.ts +134 -0
- package/dist/intake.js +239 -0
- package/dist/journey-signals.d.ts +89 -0
- package/dist/journey-signals.js +151 -0
- package/dist/manifest.d.ts +1060 -60
- package/dist/manifest.js +1111 -61
- package/dist/mine.d.ts +45 -0
- package/dist/mine.js +119 -0
- package/dist/occupies.d.ts +64 -0
- package/dist/occupies.js +122 -0
- package/dist/questions.d.ts +179 -0
- package/dist/questions.js +514 -0
- package/dist/recurring.d.ts +33 -4
- package/dist/recurring.js +50 -3
- package/dist/restricted-fields.d.ts +15 -0
- package/dist/restricted-fields.js +97 -0
- package/dist/rich-text.d.ts +22 -0
- package/dist/rich-text.js +91 -0
- package/dist/routine-mail.d.ts +400 -0
- package/dist/routine-mail.js +955 -0
- package/dist/runtime.d.ts +5 -11
- package/dist/runtime.js +21 -11
- package/dist/screens.d.ts +3 -0
- package/dist/screens.js +74 -0
- package/dist/sellable.d.ts +231 -2
- package/dist/sellable.js +342 -1
- package/dist/slug.d.ts +2 -0
- package/dist/slug.js +6 -2
- package/dist/staffed.d.ts +178 -0
- package/dist/staffed.js +287 -0
- package/dist/states.d.ts +74 -4
- package/dist/states.js +154 -58
- package/dist/stock.d.ts +129 -0
- package/dist/stock.js +205 -0
- package/dist/team.d.ts +28 -0
- package/dist/team.js +52 -0
- package/dist/testing.d.ts +22 -1
- package/dist/testing.js +47 -5
- package/dist/worked-on.d.ts +42 -0
- package/dist/worked-on.js +79 -0
- package/package.json +9 -1
- package/src/acknowledge.ts +100 -0
- package/src/agreements.ts +185 -0
- package/src/allowance.ts +98 -8
- package/src/automation-check.ts +120 -9
- package/src/automation.ts +78 -10
- package/src/behaviour.ts +26 -6
- package/src/calendar-entry.ts +258 -0
- package/src/capacity.ts +103 -2
- package/src/checklists.ts +118 -0
- package/src/contract.ts +514 -27
- package/src/discount.ts +408 -0
- package/src/document.ts +4 -2
- package/src/field-types.ts +5 -0
- package/src/formula/compile.ts +10 -0
- package/src/index.ts +17 -0
- package/src/intake.ts +380 -0
- package/src/journey-signals.ts +215 -0
- package/src/manifest.ts +1313 -66
- package/src/mine.ts +161 -0
- package/src/occupies.ts +192 -0
- package/src/questions.ts +681 -0
- package/src/recurring.ts +90 -9
- package/src/restricted-fields.ts +129 -0
- package/src/rich-text.ts +112 -0
- package/src/routine-mail.ts +1272 -0
- package/src/runtime.ts +25 -12
- package/src/screens.ts +91 -0
- package/src/sellable.ts +595 -1
- package/src/slug.ts +7 -2
- package/src/staffed.ts +474 -0
- package/src/states.ts +220 -64
- package/src/stock.ts +332 -0
- package/src/team.ts +83 -0
- package/src/testing.ts +70 -6
- package/src/worked-on.ts +134 -0
package/src/runtime.ts
CHANGED
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
durationMs,
|
|
17
17
|
notificationInput,
|
|
18
18
|
} from "./automation.ts";
|
|
19
|
+
import { DEFAULT_WAIT_TIMEOUT, NOTIFY_OPERATION } from "./automation-check.ts";
|
|
19
20
|
import type {
|
|
20
21
|
AiModule,
|
|
21
22
|
Extension,
|
|
@@ -27,6 +28,7 @@ import type {
|
|
|
27
28
|
StorageModule,
|
|
28
29
|
} from "./contract.ts";
|
|
29
30
|
import { toManifest } from "./manifest.ts";
|
|
31
|
+
import type { RoutineMailModule, RoutineSendResult } from "./routine-mail.ts";
|
|
30
32
|
|
|
31
33
|
type HostFn = (...args: unknown[]) => Promise<unknown>;
|
|
32
34
|
|
|
@@ -36,6 +38,8 @@ export interface RawHostModules {
|
|
|
36
38
|
storage?: { get: HostFn; set: HostFn; del: HostFn; list: HostFn };
|
|
37
39
|
log?: { write: HostFn };
|
|
38
40
|
ai?: { summarise: HostFn; extract: HostFn; classify: HostFn };
|
|
41
|
+
/** `codemode:routine-mail` (ADR 0590). */
|
|
42
|
+
"routine-mail"?: { send: HostFn };
|
|
39
43
|
/** `codemode:<gatekeeper>` modules, by gatekeeper name. */
|
|
40
44
|
[gatekeeper: string]: Record<string, HostFn> | undefined;
|
|
41
45
|
}
|
|
@@ -56,9 +60,7 @@ export type RunResponse =
|
|
|
56
60
|
| { ok: false; error: { code: string; message: string; details?: unknown } };
|
|
57
61
|
|
|
58
62
|
/** What `codemode:ops`'s `call` returns. */
|
|
59
|
-
export type OpsReply =
|
|
60
|
-
| { ok: true; value: unknown }
|
|
61
|
-
| { ok: false; error: { code: string; message: string; details?: unknown } };
|
|
63
|
+
export type OpsReply = RunResponse;
|
|
62
64
|
|
|
63
65
|
/** Thrown by `ctx.ops.call` when the operation fails; `code` is the pipeline's error code. */
|
|
64
66
|
export class OpsCallError extends Error {
|
|
@@ -72,6 +74,13 @@ export class OpsCallError extends Error {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
// The host answers with an envelope so error codes survive the isolate boundary.
|
|
78
|
+
function unwrap(reply: unknown): unknown {
|
|
79
|
+
const r = reply as OpsReply;
|
|
80
|
+
if (r.ok) return r.value;
|
|
81
|
+
throw new OpsCallError(r.error.code, r.error.message, r.error.details);
|
|
82
|
+
}
|
|
83
|
+
|
|
75
84
|
function missing(name: string): never {
|
|
76
85
|
throw new Error(
|
|
77
86
|
`Host module "${name}" is not declared. Add "${name}" to permissions.modules in defineExtension.`,
|
|
@@ -97,10 +106,7 @@ export function buildContext(
|
|
|
97
106
|
const ops: OpsModule = raw.ops
|
|
98
107
|
? {
|
|
99
108
|
call: async (operation, input) => {
|
|
100
|
-
|
|
101
|
-
const reply = (await raw.ops?.call(operation, input ?? {})) as OpsReply;
|
|
102
|
-
if (reply.ok) return reply.value as never;
|
|
103
|
-
throw new OpsCallError(reply.error.code, reply.error.message, reply.error.details);
|
|
109
|
+
return unwrap(await raw.ops?.call(operation, input ?? {})) as never;
|
|
104
110
|
},
|
|
105
111
|
}
|
|
106
112
|
: absent("ops");
|
|
@@ -130,15 +136,21 @@ export function buildContext(
|
|
|
130
136
|
classify: (text, labels) => raw.ai?.classify(text, labels) as Promise<never>,
|
|
131
137
|
}
|
|
132
138
|
: absent("ai");
|
|
139
|
+
const routine = raw["routine-mail"];
|
|
140
|
+
const routineMail: RoutineMailModule = routine?.send
|
|
141
|
+
? {
|
|
142
|
+
send: async (input) => {
|
|
143
|
+
return unwrap(await routine.send?.(input)) as RoutineSendResult;
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
: absent("routine-mail");
|
|
133
147
|
const gatekeeper = (name: string): GatekeeperModule => {
|
|
134
148
|
const mod = raw[name] as Record<string, HostFn> | undefined;
|
|
135
149
|
if (!mod?.call) return absent<GatekeeperModule>(name);
|
|
136
150
|
return {
|
|
137
151
|
connections: () => mod.connections?.() as Promise<never>,
|
|
138
152
|
call: async (connectionId, resource, method, ...args) => {
|
|
139
|
-
|
|
140
|
-
if (reply.ok) return reply.value as never;
|
|
141
|
-
throw new OpsCallError(reply.error.code, reply.error.message, reply.error.details);
|
|
153
|
+
return unwrap(await mod.call?.(connectionId, resource, method, args)) as never;
|
|
142
154
|
},
|
|
143
155
|
types: (connectionId, resource) => mod.types?.(connectionId, resource) as Promise<string>,
|
|
144
156
|
};
|
|
@@ -150,6 +162,7 @@ export function buildContext(
|
|
|
150
162
|
log,
|
|
151
163
|
ai,
|
|
152
164
|
gatekeeper: gatekeeper as ExtensionContext["gatekeeper"],
|
|
165
|
+
routineMail,
|
|
153
166
|
...(caller ? { caller: Object.freeze({ ...caller }) as StartedBy } : {}),
|
|
154
167
|
};
|
|
155
168
|
}
|
|
@@ -262,7 +275,7 @@ export function buildAutomationContext(
|
|
|
262
275
|
const n = (counts.get(step) ?? 0) + 1;
|
|
263
276
|
counts.set(step, n);
|
|
264
277
|
const input = notificationInput(event, to, message, `${step}:${n}`);
|
|
265
|
-
const out = (await base.ops.call(
|
|
278
|
+
const out = (await base.ops.call(NOTIFY_OPERATION as never, input as never)) as {
|
|
266
279
|
sent?: number;
|
|
267
280
|
} | null;
|
|
268
281
|
return { sent: typeof out?.sent === "number" ? out.sent : 0 };
|
|
@@ -380,7 +393,7 @@ export async function runAutomation(
|
|
|
380
393
|
};
|
|
381
394
|
const r = replayed(name, "waitForEvent");
|
|
382
395
|
if (r) return r.value ?? null;
|
|
383
|
-
const timeoutMs = durationMs(declaredWait.timeout ??
|
|
396
|
+
const timeoutMs = durationMs(declaredWait.timeout ?? DEFAULT_WAIT_TIMEOUT);
|
|
384
397
|
if (test) {
|
|
385
398
|
testSteps.push({ name, kind: "waitForEvent", skippedMs: timeoutMs });
|
|
386
399
|
return null;
|
package/src/screens.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// What decides a shipped pack's staff screens (stage 47, ADR 0660), as one string: the screens it
|
|
2
|
+
// declares and everything their gates are judged by (each gate tool's risk, audiences, permissions
|
|
3
|
+
// and `humanOnly`, the pack's restricted and grantable permissions and its roles). The admin's
|
|
4
|
+
// build computes it from each pack in the repository (screens-plugin.ts) and hands the host the
|
|
5
|
+
// list; `screens.mine` lists a pack's screens only when the installed row's manifest gives the same
|
|
6
|
+
// string. So a row that holds a pack's id with another manifest (an org's own extension taking an
|
|
7
|
+
// unlisted pack's id, a copy whose gate tools say less) borrows none of the pack's built screens.
|
|
8
|
+
import type { ExtensionManifest } from "./manifest.ts";
|
|
9
|
+
|
|
10
|
+
/** JSON with object keys sorted, so the same manifest gives the same string. */
|
|
11
|
+
function canonical(value: unknown): string {
|
|
12
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
|
|
13
|
+
if (value && typeof value === "object") {
|
|
14
|
+
const entries = Object.entries(value as Record<string, unknown>)
|
|
15
|
+
.filter(([, v]) => v !== undefined)
|
|
16
|
+
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
|
|
17
|
+
return `{${entries.map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(",")}}`;
|
|
18
|
+
}
|
|
19
|
+
return JSON.stringify(value ?? null);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const sorted = (list: readonly string[] | undefined) => [...(list ?? [])].sort();
|
|
23
|
+
|
|
24
|
+
/** The gate fingerprint of a manifest's screens, or null when it declares none. */
|
|
25
|
+
export function screenGateFingerprint(m: Partial<ExtensionManifest>): string | null {
|
|
26
|
+
const screens = m.screens ?? {};
|
|
27
|
+
if (!Object.keys(screens).length) return null;
|
|
28
|
+
const toolNames = new Set(Object.values(screens).flatMap((s) => s.opens ?? []));
|
|
29
|
+
const tools = Object.fromEntries(
|
|
30
|
+
[...toolNames].sort().map((name) => {
|
|
31
|
+
const tool = m.tools?.[name];
|
|
32
|
+
return [
|
|
33
|
+
name,
|
|
34
|
+
tool
|
|
35
|
+
? {
|
|
36
|
+
risk: tool.risk,
|
|
37
|
+
audiences: sorted(tool.audiences ?? ["staff"]),
|
|
38
|
+
permission: sorted(
|
|
39
|
+
tool.permission === undefined
|
|
40
|
+
? []
|
|
41
|
+
: typeof tool.permission === "string"
|
|
42
|
+
? [tool.permission]
|
|
43
|
+
: tool.permission,
|
|
44
|
+
),
|
|
45
|
+
humanOnly: tool.humanOnly === true,
|
|
46
|
+
grantLiftsRoleLimits: tool.grantLiftsRoleLimits === true,
|
|
47
|
+
// ADR 0652: only when set, so a pack declaring neither keeps its fingerprint.
|
|
48
|
+
...(tool.anyStaff ? { anyStaff: true } : {}),
|
|
49
|
+
...(tool.corePermission ? { corePermission: tool.corePermission } : {}),
|
|
50
|
+
}
|
|
51
|
+
: null,
|
|
52
|
+
];
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
return canonical({
|
|
56
|
+
id: m.id,
|
|
57
|
+
screens: Object.fromEntries(
|
|
58
|
+
Object.entries(screens).map(([key, s]) => [
|
|
59
|
+
key,
|
|
60
|
+
{
|
|
61
|
+
label: s.label,
|
|
62
|
+
block: s.block,
|
|
63
|
+
export: s.export,
|
|
64
|
+
nav: s.nav ? { group: s.nav.group, order: s.nav.order ?? null } : null,
|
|
65
|
+
opens: [...(s.opens ?? [])],
|
|
66
|
+
writes: [...(s.writes ?? [])],
|
|
67
|
+
record: s.record ? { object: s.record.object, as: s.record.as } : null,
|
|
68
|
+
},
|
|
69
|
+
]),
|
|
70
|
+
),
|
|
71
|
+
tools,
|
|
72
|
+
restricted: sorted(m.restricted),
|
|
73
|
+
grantable: sorted(m.grantable),
|
|
74
|
+
roles: Object.fromEntries(
|
|
75
|
+
Object.entries(m.roles ?? {})
|
|
76
|
+
.sort(([a], [b]) => (a < b ? -1 : 1))
|
|
77
|
+
.map(([name, r]) => [
|
|
78
|
+
name,
|
|
79
|
+
{
|
|
80
|
+
permissions: sorted(r.permissions),
|
|
81
|
+
read: sorted(r.read),
|
|
82
|
+
today: r.today ?? null,
|
|
83
|
+
// Left out when absent, so a role without it keeps its fingerprint (ADR 0889).
|
|
84
|
+
looksAfter: r.looksAfter,
|
|
85
|
+
// Left out when absent too (ADR 0755).
|
|
86
|
+
mine: r.mine,
|
|
87
|
+
},
|
|
88
|
+
]),
|
|
89
|
+
),
|
|
90
|
+
});
|
|
91
|
+
}
|