@composable-os/sdk 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/dist/allowance.d.ts +198 -0
- package/dist/allowance.js +374 -0
- package/dist/automation-check.d.ts +38 -0
- package/dist/automation-check.js +454 -0
- package/dist/automation.d.ts +767 -0
- package/dist/automation.js +303 -0
- package/dist/behaviour.d.ts +3 -0
- package/dist/behaviour.js +153 -0
- package/dist/capacity.d.ts +146 -0
- package/dist/capacity.js +189 -0
- package/dist/contract.d.ts +851 -0
- package/dist/contract.js +42 -0
- package/dist/document.d.ts +211 -0
- package/dist/document.js +726 -0
- package/dist/field-types.d.ts +11 -0
- package/dist/field-types.js +98 -0
- package/dist/formula/ast.d.ts +67 -0
- package/dist/formula/ast.js +22 -0
- package/dist/formula/compile.d.ts +37 -0
- package/dist/formula/compile.js +379 -0
- package/dist/formula/index.d.ts +3 -0
- package/dist/formula/index.js +4 -0
- package/dist/formula/parser.d.ts +13 -0
- package/dist/formula/parser.js +365 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +24 -0
- package/dist/manifest.d.ts +1708 -0
- package/dist/manifest.js +1494 -0
- package/dist/media.d.ts +41 -0
- package/dist/media.js +90 -0
- package/dist/permissions.d.ts +17 -0
- package/dist/permissions.js +44 -0
- package/dist/recurring.d.ts +114 -0
- package/dist/recurring.js +173 -0
- package/dist/renamed.d.ts +16 -0
- package/dist/renamed.js +59 -0
- package/dist/rich-text-fixture.d.ts +121 -0
- package/dist/rich-text-fixture.js +67 -0
- package/dist/rich-text.d.ts +48 -0
- package/dist/rich-text.js +184 -0
- package/dist/runtime.d.ts +95 -0
- package/dist/runtime.js +312 -0
- package/dist/sellable.d.ts +331 -0
- package/dist/sellable.js +746 -0
- package/dist/slug.d.ts +11 -0
- package/dist/slug.js +23 -0
- package/dist/states.d.ts +292 -0
- package/dist/states.js +383 -0
- package/dist/testing.d.ts +151 -0
- package/dist/testing.js +679 -0
- package/dist/unique.d.ts +20 -0
- package/dist/unique.js +58 -0
- package/package.json +34 -4
- package/src/allowance.ts +522 -0
- package/src/automation-check.ts +534 -0
- package/src/automation.ts +743 -0
- package/src/behaviour.ts +215 -0
- package/src/capacity.ts +303 -0
- package/src/contract.ts +909 -0
- package/src/document.ts +935 -0
- package/src/field-types.ts +111 -0
- package/src/formula/ast.ts +72 -0
- package/src/formula/compile.ts +454 -0
- package/src/formula/index.ts +4 -0
- package/src/formula/parser.ts +417 -0
- package/src/index.ts +36 -0
- package/src/manifest.ts +1785 -0
- package/src/media.ts +108 -0
- package/src/permissions.ts +60 -0
- package/src/recurring.ts +321 -0
- package/src/renamed.ts +63 -0
- package/src/rich-text-fixture.ts +68 -0
- package/src/rich-text.ts +221 -0
- package/src/runtime.ts +410 -0
- package/src/sellable.ts +1138 -0
- package/src/slug.ts +25 -0
- package/src/states.ts +598 -0
- package/src/testing.ts +847 -0
- package/src/unique.ts +81 -0
- package/README.md +0 -3
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** A media id in the fixture; replace it with a real one before storing. */
|
|
2
|
+
export declare const RICH_TEXT_FIXTURE_MEDIA = "med_01FIXTURE0000000000000000";
|
|
3
|
+
export declare const RICH_TEXT_FIXTURE: {
|
|
4
|
+
readonly blocks: readonly [{
|
|
5
|
+
readonly type: "heading";
|
|
6
|
+
readonly level: 2;
|
|
7
|
+
readonly content: readonly [{
|
|
8
|
+
readonly type: "text";
|
|
9
|
+
readonly text: "Summer at the hall";
|
|
10
|
+
}];
|
|
11
|
+
}, {
|
|
12
|
+
readonly type: "paragraph";
|
|
13
|
+
readonly content: readonly [{
|
|
14
|
+
readonly type: "text";
|
|
15
|
+
readonly text: "Doors open at ";
|
|
16
|
+
}, {
|
|
17
|
+
readonly type: "text";
|
|
18
|
+
readonly text: "seven";
|
|
19
|
+
readonly bold: true;
|
|
20
|
+
}, {
|
|
21
|
+
readonly type: "text";
|
|
22
|
+
readonly text: ", the bar a little ";
|
|
23
|
+
}, {
|
|
24
|
+
readonly type: "text";
|
|
25
|
+
readonly text: "earlier";
|
|
26
|
+
readonly italic: true;
|
|
27
|
+
}, {
|
|
28
|
+
readonly type: "text";
|
|
29
|
+
readonly text: ". Bring ";
|
|
30
|
+
}, {
|
|
31
|
+
readonly type: "text";
|
|
32
|
+
readonly text: "ID";
|
|
33
|
+
readonly code: true;
|
|
34
|
+
}, {
|
|
35
|
+
readonly type: "break";
|
|
36
|
+
}, {
|
|
37
|
+
readonly type: "text";
|
|
38
|
+
readonly text: "Tickets are on the ";
|
|
39
|
+
readonly bold: true;
|
|
40
|
+
readonly italic: true;
|
|
41
|
+
}, {
|
|
42
|
+
readonly type: "text";
|
|
43
|
+
readonly text: "events page";
|
|
44
|
+
readonly href: "/events";
|
|
45
|
+
}, {
|
|
46
|
+
readonly type: "text";
|
|
47
|
+
readonly text: " or by ";
|
|
48
|
+
}, {
|
|
49
|
+
readonly type: "text";
|
|
50
|
+
readonly text: "email";
|
|
51
|
+
readonly href: "mailto:hello@example.com";
|
|
52
|
+
}, {
|
|
53
|
+
readonly type: "text";
|
|
54
|
+
readonly text: ".";
|
|
55
|
+
}];
|
|
56
|
+
}, {
|
|
57
|
+
readonly type: "list";
|
|
58
|
+
readonly style: "bullet";
|
|
59
|
+
readonly items: readonly [{
|
|
60
|
+
readonly content: readonly [{
|
|
61
|
+
readonly type: "text";
|
|
62
|
+
readonly text: "Friday: open mic";
|
|
63
|
+
}];
|
|
64
|
+
}, {
|
|
65
|
+
readonly content: readonly [{
|
|
66
|
+
readonly type: "text";
|
|
67
|
+
readonly text: "Saturday: two bands";
|
|
68
|
+
}];
|
|
69
|
+
readonly list: {
|
|
70
|
+
readonly style: "ordered";
|
|
71
|
+
readonly items: readonly [{
|
|
72
|
+
readonly content: readonly [{
|
|
73
|
+
readonly type: "text";
|
|
74
|
+
readonly text: "The first";
|
|
75
|
+
}];
|
|
76
|
+
}, {
|
|
77
|
+
readonly content: readonly [{
|
|
78
|
+
readonly type: "text";
|
|
79
|
+
readonly text: "The second";
|
|
80
|
+
}];
|
|
81
|
+
}];
|
|
82
|
+
};
|
|
83
|
+
}];
|
|
84
|
+
}, {
|
|
85
|
+
readonly type: "quote";
|
|
86
|
+
readonly content: readonly [{
|
|
87
|
+
readonly type: "text";
|
|
88
|
+
readonly text: "Best night of the year.";
|
|
89
|
+
}];
|
|
90
|
+
readonly attribution: "A regular";
|
|
91
|
+
}, {
|
|
92
|
+
readonly type: "image";
|
|
93
|
+
readonly media: "med_01FIXTURE0000000000000000";
|
|
94
|
+
readonly alt: "The hall from the stage, full";
|
|
95
|
+
readonly caption: readonly [{
|
|
96
|
+
readonly type: "text";
|
|
97
|
+
readonly text: "Last summer, ";
|
|
98
|
+
}, {
|
|
99
|
+
readonly type: "text";
|
|
100
|
+
readonly text: "sold out";
|
|
101
|
+
readonly bold: true;
|
|
102
|
+
}];
|
|
103
|
+
}, {
|
|
104
|
+
readonly type: "divider";
|
|
105
|
+
}, {
|
|
106
|
+
readonly type: "embed";
|
|
107
|
+
readonly url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
|
|
108
|
+
readonly caption: "The trailer";
|
|
109
|
+
}, {
|
|
110
|
+
readonly type: "callout";
|
|
111
|
+
readonly tone: "warning";
|
|
112
|
+
readonly content: readonly [{
|
|
113
|
+
readonly type: "text";
|
|
114
|
+
readonly text: "Under 18s with an adult only.";
|
|
115
|
+
}];
|
|
116
|
+
}, {
|
|
117
|
+
readonly type: "button";
|
|
118
|
+
readonly label: "Get tickets";
|
|
119
|
+
readonly href: "https://tickets.example.com/summer";
|
|
120
|
+
}];
|
|
121
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// One rich text document with every block type and every mark (stage 28, ADR 0440): what the
|
|
2
|
+
// host's tests store and what both renderers (web and native, stage 28 step 6) must draw in full.
|
|
3
|
+
// The picture names a media item by an id of the right shape; the host refuses one that is not a
|
|
4
|
+
// live media item, so a test that stores this replaces it (or leaves the image out).
|
|
5
|
+
/** A media id in the fixture; replace it with a real one before storing. */
|
|
6
|
+
export const RICH_TEXT_FIXTURE_MEDIA = "med_01FIXTURE0000000000000000";
|
|
7
|
+
export const RICH_TEXT_FIXTURE = {
|
|
8
|
+
blocks: [
|
|
9
|
+
{ type: "heading", level: 2, content: [{ type: "text", text: "Summer at the hall" }] },
|
|
10
|
+
{
|
|
11
|
+
type: "paragraph",
|
|
12
|
+
content: [
|
|
13
|
+
{ type: "text", text: "Doors open at " },
|
|
14
|
+
{ type: "text", text: "seven", bold: true },
|
|
15
|
+
{ type: "text", text: ", the bar a little " },
|
|
16
|
+
{ type: "text", text: "earlier", italic: true },
|
|
17
|
+
{ type: "text", text: ". Bring " },
|
|
18
|
+
{ type: "text", text: "ID", code: true },
|
|
19
|
+
{ type: "break" },
|
|
20
|
+
{ type: "text", text: "Tickets are on the ", bold: true, italic: true },
|
|
21
|
+
{ type: "text", text: "events page", href: "/events" },
|
|
22
|
+
{ type: "text", text: " or by " },
|
|
23
|
+
{ type: "text", text: "email", href: "mailto:hello@example.com" },
|
|
24
|
+
{ type: "text", text: "." },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
type: "list",
|
|
29
|
+
style: "bullet",
|
|
30
|
+
items: [
|
|
31
|
+
{ content: [{ type: "text", text: "Friday: open mic" }] },
|
|
32
|
+
{
|
|
33
|
+
content: [{ type: "text", text: "Saturday: two bands" }],
|
|
34
|
+
list: {
|
|
35
|
+
style: "ordered",
|
|
36
|
+
items: [
|
|
37
|
+
{ content: [{ type: "text", text: "The first" }] },
|
|
38
|
+
{ content: [{ type: "text", text: "The second" }] },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "quote",
|
|
46
|
+
content: [{ type: "text", text: "Best night of the year." }],
|
|
47
|
+
attribution: "A regular",
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: "image",
|
|
51
|
+
media: RICH_TEXT_FIXTURE_MEDIA,
|
|
52
|
+
alt: "The hall from the stage, full",
|
|
53
|
+
caption: [
|
|
54
|
+
{ type: "text", text: "Last summer, " },
|
|
55
|
+
{ type: "text", text: "sold out", bold: true },
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
{ type: "divider" },
|
|
59
|
+
{ type: "embed", url: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", caption: "The trailer" },
|
|
60
|
+
{
|
|
61
|
+
type: "callout",
|
|
62
|
+
tone: "warning",
|
|
63
|
+
content: [{ type: "text", text: "Under 18s with an adult only." }],
|
|
64
|
+
},
|
|
65
|
+
{ type: "button", label: "Get tickets", href: "https://tickets.example.com/summer" },
|
|
66
|
+
],
|
|
67
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { DocumentNode, DocumentObjectNode, DocumentSchema } from "./document.ts";
|
|
2
|
+
/** The block types, in the order a renderer lists them. */
|
|
3
|
+
export declare const RICH_TEXT_BLOCKS: readonly ["paragraph", "heading", "list", "quote", "image", "divider", "embed", "callout", "button"];
|
|
4
|
+
export type RichTextBlockType = (typeof RICH_TEXT_BLOCKS)[number];
|
|
5
|
+
/** The marks a run of text may carry. A link is `href`. */
|
|
6
|
+
export declare const RICH_TEXT_MARKS: readonly ["bold", "italic", "code", "href"];
|
|
7
|
+
/** A richText field that declares no `maxBytes`. At most DOCUMENT_MAX_BYTES. */
|
|
8
|
+
export declare const RICH_TEXT_DEFAULT_BYTES = 131072;
|
|
9
|
+
/** The object a picture's `media` names: the media library's (stage 28, step 4). */
|
|
10
|
+
export declare const RICH_TEXT_MEDIA_OBJECT = "media";
|
|
11
|
+
/** The one schema of every richText field. */
|
|
12
|
+
export declare const RICH_TEXT_SCHEMA: DocumentSchema;
|
|
13
|
+
/**
|
|
14
|
+
* The `image` field type (stage 28, ADR 0444): a picture from the media library, with its alt
|
|
15
|
+
* text and the point to keep in view when a client crops it (0 to 1 from the left and the top).
|
|
16
|
+
*/
|
|
17
|
+
export declare const IMAGE_SCHEMA: DocumentSchema;
|
|
18
|
+
/** The most an image field's value may be, in bytes of its JSON. */
|
|
19
|
+
export declare const IMAGE_MAX_BYTES = 2048;
|
|
20
|
+
/**
|
|
21
|
+
* A video from the media library (stage 42, ADR 0475), as a node a declared document may use: the
|
|
22
|
+
* video (a ready one, checked on write) and, optionally, a picture to show before it plays.
|
|
23
|
+
*/
|
|
24
|
+
export declare const VIDEO_NODE: DocumentObjectNode;
|
|
25
|
+
/** A downloadable file from the media library (a PDF), as a node a declared document may use. */
|
|
26
|
+
export declare const FILE_NODE: DocumentNode;
|
|
27
|
+
/** The `video` field type (stage 42, ADR 0475): `{ media, poster? }`. */
|
|
28
|
+
export declare const VIDEO_SCHEMA: DocumentSchema;
|
|
29
|
+
/** The most a video field's value may be, in bytes of its JSON. */
|
|
30
|
+
export declare const VIDEO_MAX_BYTES = 1024;
|
|
31
|
+
/**
|
|
32
|
+
* The field types whose value is a document (ADR 0445): `document`, `richText`, `image` and
|
|
33
|
+
* `video`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isDocumentType(type: string | undefined): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* The schema a document-valued field is checked against: its declared one, or richText's. Not a
|
|
38
|
+
* document type: undefined.
|
|
39
|
+
*/
|
|
40
|
+
export declare function documentSchemaOf(field: {
|
|
41
|
+
type?: string | undefined;
|
|
42
|
+
schema?: unknown;
|
|
43
|
+
}): DocumentSchema | undefined;
|
|
44
|
+
/** The size limit of a document-valued field: its declared one, or its type's default. */
|
|
45
|
+
export declare function documentMaxBytesOf(field: {
|
|
46
|
+
type?: string | undefined;
|
|
47
|
+
maxBytes?: number | undefined;
|
|
48
|
+
}): number | undefined;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/** The block types, in the order a renderer lists them. */
|
|
2
|
+
export const RICH_TEXT_BLOCKS = [
|
|
3
|
+
"paragraph",
|
|
4
|
+
"heading",
|
|
5
|
+
"list",
|
|
6
|
+
"quote",
|
|
7
|
+
"image",
|
|
8
|
+
"divider",
|
|
9
|
+
"embed",
|
|
10
|
+
"callout",
|
|
11
|
+
"button",
|
|
12
|
+
];
|
|
13
|
+
/** The marks a run of text may carry. A link is `href`. */
|
|
14
|
+
export const RICH_TEXT_MARKS = ["bold", "italic", "code", "href"];
|
|
15
|
+
/** A richText field that declares no `maxBytes`. At most DOCUMENT_MAX_BYTES. */
|
|
16
|
+
export const RICH_TEXT_DEFAULT_BYTES = 131_072;
|
|
17
|
+
/** The object a picture's `media` names: the media library's (stage 28, step 4). */
|
|
18
|
+
export const RICH_TEXT_MEDIA_OBJECT = "media";
|
|
19
|
+
const prose = (max, extra = {}) => ({ type: "text", max, noMarkup: true, ...extra });
|
|
20
|
+
const optional = (node) => ({ ...node, optional: true });
|
|
21
|
+
const inlines = { type: "use", def: "inlines" };
|
|
22
|
+
const object = (fields) => ({
|
|
23
|
+
type: "object",
|
|
24
|
+
fields,
|
|
25
|
+
});
|
|
26
|
+
const listShape = () => object({
|
|
27
|
+
style: { type: "choice", options: ["bullet", "ordered"] },
|
|
28
|
+
items: { type: "array", min: 1, max: 200, of: { type: "use", def: "listItem" } },
|
|
29
|
+
});
|
|
30
|
+
const blocks = {
|
|
31
|
+
paragraph: object({ content: inlines }),
|
|
32
|
+
heading: object({
|
|
33
|
+
level: { type: "number", integer: true, min: 1, max: 6 },
|
|
34
|
+
content: inlines,
|
|
35
|
+
}),
|
|
36
|
+
list: listShape(),
|
|
37
|
+
quote: object({ content: inlines, attribution: optional(prose(300)) }),
|
|
38
|
+
image: object({
|
|
39
|
+
media: {
|
|
40
|
+
type: "ref",
|
|
41
|
+
to: RICH_TEXT_MEDIA_OBJECT,
|
|
42
|
+
media: "image",
|
|
43
|
+
description: "The picture, from media",
|
|
44
|
+
},
|
|
45
|
+
alt: prose(500, { description: "What the picture shows, for people who cannot see it" }),
|
|
46
|
+
caption: optional(inlines),
|
|
47
|
+
}),
|
|
48
|
+
divider: object({}),
|
|
49
|
+
embed: object({
|
|
50
|
+
url: {
|
|
51
|
+
type: "text",
|
|
52
|
+
max: 2000,
|
|
53
|
+
href: "web",
|
|
54
|
+
description: "A video or post to show (YouTube, Vimeo): the client decides how",
|
|
55
|
+
},
|
|
56
|
+
caption: optional(prose(500)),
|
|
57
|
+
}),
|
|
58
|
+
callout: object({
|
|
59
|
+
tone: { type: "choice", options: ["info", "note", "success", "warning"] },
|
|
60
|
+
content: inlines,
|
|
61
|
+
}),
|
|
62
|
+
button: object({
|
|
63
|
+
label: prose(80, { min: 1 }),
|
|
64
|
+
href: { type: "text", max: 2000, href: "link" },
|
|
65
|
+
}),
|
|
66
|
+
};
|
|
67
|
+
/** The one schema of every richText field. */
|
|
68
|
+
export const RICH_TEXT_SCHEMA = {
|
|
69
|
+
root: object({
|
|
70
|
+
blocks: {
|
|
71
|
+
type: "array",
|
|
72
|
+
max: 1000,
|
|
73
|
+
of: {
|
|
74
|
+
type: "union",
|
|
75
|
+
tag: "type",
|
|
76
|
+
variants: blocks,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
defs: {
|
|
81
|
+
inlines: {
|
|
82
|
+
type: "array",
|
|
83
|
+
max: 500,
|
|
84
|
+
of: {
|
|
85
|
+
type: "union",
|
|
86
|
+
tag: "type",
|
|
87
|
+
variants: {
|
|
88
|
+
text: object({
|
|
89
|
+
text: prose(5000, { min: 1 }),
|
|
90
|
+
bold: optional({ type: "boolean" }),
|
|
91
|
+
italic: optional({ type: "boolean" }),
|
|
92
|
+
code: optional({ type: "boolean" }),
|
|
93
|
+
href: optional({ type: "text", max: 2000, href: "link" }),
|
|
94
|
+
}),
|
|
95
|
+
break: object({}),
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
listItem: object({ content: inlines, list: optional({ type: "use", def: "list" }) }),
|
|
100
|
+
list: listShape(),
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* The `image` field type (stage 28, ADR 0444): a picture from the media library, with its alt
|
|
105
|
+
* text and the point to keep in view when a client crops it (0 to 1 from the left and the top).
|
|
106
|
+
*/
|
|
107
|
+
export const IMAGE_SCHEMA = {
|
|
108
|
+
root: object({
|
|
109
|
+
media: {
|
|
110
|
+
type: "ref",
|
|
111
|
+
to: RICH_TEXT_MEDIA_OBJECT,
|
|
112
|
+
media: "image",
|
|
113
|
+
description: "The picture, from media",
|
|
114
|
+
},
|
|
115
|
+
alt: prose(500, { description: "What the picture shows, for people who cannot see it" }),
|
|
116
|
+
focal: optional(object({
|
|
117
|
+
x: { type: "number", min: 0, max: 1 },
|
|
118
|
+
y: { type: "number", min: 0, max: 1 },
|
|
119
|
+
})),
|
|
120
|
+
}),
|
|
121
|
+
};
|
|
122
|
+
/** The most an image field's value may be, in bytes of its JSON. */
|
|
123
|
+
export const IMAGE_MAX_BYTES = 2048;
|
|
124
|
+
/**
|
|
125
|
+
* A video from the media library (stage 42, ADR 0475), as a node a declared document may use: the
|
|
126
|
+
* video (a ready one, checked on write) and, optionally, a picture to show before it plays.
|
|
127
|
+
*/
|
|
128
|
+
export const VIDEO_NODE = object({
|
|
129
|
+
media: {
|
|
130
|
+
type: "ref",
|
|
131
|
+
to: RICH_TEXT_MEDIA_OBJECT,
|
|
132
|
+
media: "video",
|
|
133
|
+
description: "The video, from media (a ready one)",
|
|
134
|
+
},
|
|
135
|
+
poster: optional({
|
|
136
|
+
type: "ref",
|
|
137
|
+
to: RICH_TEXT_MEDIA_OBJECT,
|
|
138
|
+
media: "image",
|
|
139
|
+
description: "A picture shown before it plays",
|
|
140
|
+
}),
|
|
141
|
+
});
|
|
142
|
+
/** A downloadable file from the media library (a PDF), as a node a declared document may use. */
|
|
143
|
+
export const FILE_NODE = {
|
|
144
|
+
type: "ref",
|
|
145
|
+
to: RICH_TEXT_MEDIA_OBJECT,
|
|
146
|
+
media: "file",
|
|
147
|
+
description: "The file, from media",
|
|
148
|
+
};
|
|
149
|
+
/** The `video` field type (stage 42, ADR 0475): `{ media, poster? }`. */
|
|
150
|
+
export const VIDEO_SCHEMA = { root: VIDEO_NODE };
|
|
151
|
+
/** The most a video field's value may be, in bytes of its JSON. */
|
|
152
|
+
export const VIDEO_MAX_BYTES = 1024;
|
|
153
|
+
/**
|
|
154
|
+
* The field types whose value is a document (ADR 0445): `document`, `richText`, `image` and
|
|
155
|
+
* `video`.
|
|
156
|
+
*/
|
|
157
|
+
export function isDocumentType(type) {
|
|
158
|
+
return type === "document" || type === "richText" || type === "image" || type === "video";
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The schema a document-valued field is checked against: its declared one, or richText's. Not a
|
|
162
|
+
* document type: undefined.
|
|
163
|
+
*/
|
|
164
|
+
export function documentSchemaOf(field) {
|
|
165
|
+
if (field.type === "richText")
|
|
166
|
+
return RICH_TEXT_SCHEMA;
|
|
167
|
+
if (field.type === "image")
|
|
168
|
+
return IMAGE_SCHEMA;
|
|
169
|
+
if (field.type === "video")
|
|
170
|
+
return VIDEO_SCHEMA;
|
|
171
|
+
if (field.type === "document")
|
|
172
|
+
return field.schema;
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
/** The size limit of a document-valued field: its declared one, or its type's default. */
|
|
176
|
+
export function documentMaxBytesOf(field) {
|
|
177
|
+
if (field.type === "image")
|
|
178
|
+
return IMAGE_MAX_BYTES;
|
|
179
|
+
if (field.type === "video")
|
|
180
|
+
return VIDEO_MAX_BYTES;
|
|
181
|
+
if (field.maxBytes !== undefined)
|
|
182
|
+
return field.maxBytes;
|
|
183
|
+
return field.type === "richText" ? RICH_TEXT_DEFAULT_BYTES : undefined;
|
|
184
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { type AutomationAdvance, type AutomationContext, type AutomationEvent, type AutomationRunRequest, type AutomationTestStep } from "./automation.ts";
|
|
2
|
+
import type { Extension, ExtensionContext, StartedBy } from "./contract.ts";
|
|
3
|
+
type HostFn = (...args: unknown[]) => Promise<unknown>;
|
|
4
|
+
/** The raw `codemode:*` modules, as imported in the entry module. */
|
|
5
|
+
export interface RawHostModules {
|
|
6
|
+
ops?: {
|
|
7
|
+
call: HostFn;
|
|
8
|
+
};
|
|
9
|
+
storage?: {
|
|
10
|
+
get: HostFn;
|
|
11
|
+
set: HostFn;
|
|
12
|
+
del: HostFn;
|
|
13
|
+
list: HostFn;
|
|
14
|
+
};
|
|
15
|
+
log?: {
|
|
16
|
+
write: HostFn;
|
|
17
|
+
};
|
|
18
|
+
ai?: {
|
|
19
|
+
summarise: HostFn;
|
|
20
|
+
extract: HostFn;
|
|
21
|
+
classify: HostFn;
|
|
22
|
+
};
|
|
23
|
+
/** `codemode:<gatekeeper>` modules, by gatekeeper name. */
|
|
24
|
+
[gatekeeper: string]: Record<string, HostFn> | undefined;
|
|
25
|
+
}
|
|
26
|
+
export type RunRequest = {
|
|
27
|
+
kind: "manifest";
|
|
28
|
+
} | {
|
|
29
|
+
kind: "tool";
|
|
30
|
+
tool: string;
|
|
31
|
+
input: unknown;
|
|
32
|
+
version?: string;
|
|
33
|
+
/** Who started the tool, from the host (ADR 0436). */
|
|
34
|
+
caller?: StartedBy;
|
|
35
|
+
};
|
|
36
|
+
export type RunResponse = {
|
|
37
|
+
ok: true;
|
|
38
|
+
value: unknown;
|
|
39
|
+
} | {
|
|
40
|
+
ok: false;
|
|
41
|
+
error: {
|
|
42
|
+
code: string;
|
|
43
|
+
message: string;
|
|
44
|
+
details?: unknown;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/** What `codemode:ops`'s `call` returns. */
|
|
48
|
+
export type OpsReply = {
|
|
49
|
+
ok: true;
|
|
50
|
+
value: unknown;
|
|
51
|
+
} | {
|
|
52
|
+
ok: false;
|
|
53
|
+
error: {
|
|
54
|
+
code: string;
|
|
55
|
+
message: string;
|
|
56
|
+
details?: unknown;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
/** Thrown by `ctx.ops.call` when the operation fails; `code` is the pipeline's error code. */
|
|
60
|
+
export declare class OpsCallError extends Error {
|
|
61
|
+
readonly code: string;
|
|
62
|
+
readonly details?: unknown | undefined;
|
|
63
|
+
name: string;
|
|
64
|
+
constructor(code: string, message: string, details?: unknown | undefined);
|
|
65
|
+
}
|
|
66
|
+
/** Builds the `ctx` tools receive from raw host modules. Exported for the testing harness. */
|
|
67
|
+
export declare function buildContext(extension: {
|
|
68
|
+
id: string;
|
|
69
|
+
version: string;
|
|
70
|
+
}, raw: RawHostModules, pending?: Promise<unknown>[], caller?: StartedBy): ExtensionContext;
|
|
71
|
+
/** Dispatches one run request inside the sandbox. */
|
|
72
|
+
export declare function runExtension(extension: Extension, request: RunRequest, raw: RawHostModules): Promise<RunResponse>;
|
|
73
|
+
/** What `runAutomation` returns in `value`: an advance, or (test mode) every step. */
|
|
74
|
+
export type AutomationRunValue = AutomationAdvance | {
|
|
75
|
+
kind: "test";
|
|
76
|
+
steps: AutomationTestStep[];
|
|
77
|
+
value: unknown;
|
|
78
|
+
};
|
|
79
|
+
/** A step call that does not match the declarations (the declarations are the contract). */
|
|
80
|
+
export declare class AutomationStepError extends Error {
|
|
81
|
+
name: string;
|
|
82
|
+
readonly code = "undeclared_step";
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds the automation `ctx`: the extension context plus `notify`, which calls
|
|
86
|
+
* `notification.send` with `notificationInput`. Its dedupe key is `<step>:<n>` (the n-th notify
|
|
87
|
+
* of that step), so a step retried or replayed never notifies twice.
|
|
88
|
+
*/
|
|
89
|
+
export declare function buildAutomationContext(extension: {
|
|
90
|
+
id: string;
|
|
91
|
+
version: string;
|
|
92
|
+
}, raw: RawHostModules, event: AutomationEvent, pending?: Promise<unknown>[], currentStep?: () => string | null): AutomationContext;
|
|
93
|
+
/** Runs one advance (or a whole test run) of an automation inside the sandbox. */
|
|
94
|
+
export declare function runAutomation(extension: Extension, request: AutomationRunRequest, raw: RawHostModules): Promise<RunResponse>;
|
|
95
|
+
export {};
|