@artieeez/cf-core 0.0.0-stage → 0.1.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/README.md +4 -2
- package/dist/agent.d.ts +77 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +114 -0
- package/dist/agent.js.map +1 -0
- package/dist/artifact.d.ts +52 -0
- package/dist/artifact.d.ts.map +1 -0
- package/dist/artifact.js +97 -0
- package/dist/artifact.js.map +1 -0
- package/dist/errors.d.ts +18 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +2 -0
- package/dist/errors.js.map +1 -0
- package/dist/events.d.ts +43 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +36 -0
- package/dist/events.js.map +1 -0
- package/dist/form.d.ts +62 -0
- package/dist/form.d.ts.map +1 -0
- package/dist/form.js +124 -0
- package/dist/form.js.map +1 -0
- package/dist/gate.d.ts +79 -0
- package/dist/gate.d.ts.map +1 -0
- package/dist/gate.js +31 -0
- package/dist/gate.js.map +1 -0
- package/dist/ids.d.ts +13 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +37 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/insights.d.ts +53 -0
- package/dist/insights.d.ts.map +1 -0
- package/dist/insights.js +128 -0
- package/dist/insights.js.map +1 -0
- package/dist/manifest.d.ts +343 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +651 -0
- package/dist/manifest.js.map +1 -0
- package/dist/plugin.d.ts +77 -0
- package/dist/plugin.d.ts.map +1 -0
- package/dist/plugin.js +34 -0
- package/dist/plugin.js.map +1 -0
- package/dist/refs.d.ts +78 -0
- package/dist/refs.d.ts.map +1 -0
- package/dist/refs.js +147 -0
- package/dist/refs.js.map +1 -0
- package/dist/roles.d.ts +18 -0
- package/dist/roles.d.ts.map +1 -0
- package/dist/roles.js +5 -0
- package/dist/roles.js.map +1 -0
- package/dist/run-meta.d.ts +22 -0
- package/dist/run-meta.d.ts.map +1 -0
- package/dist/run-meta.js +35 -0
- package/dist/run-meta.js.map +1 -0
- package/dist/trigger.d.ts +43 -0
- package/dist/trigger.d.ts.map +1 -0
- package/dist/trigger.js +105 -0
- package/dist/trigger.js.map +1 -0
- package/dist/workspace.d.ts +73 -0
- package/dist/workspace.d.ts.map +1 -0
- package/dist/workspace.js +54 -0
- package/dist/workspace.js.map +1 -0
- package/package.json +67 -3
- package/src/agent.ts +120 -0
- package/src/artifact.ts +111 -0
- package/src/errors.ts +67 -0
- package/src/events.ts +71 -0
- package/src/form.ts +148 -0
- package/src/gate.ts +38 -0
- package/src/ids.ts +42 -0
- package/src/index.ts +15 -0
- package/src/insights.ts +177 -0
- package/src/manifest.ts +675 -0
- package/src/plugin.ts +70 -0
- package/src/refs.ts +165 -0
- package/src/roles.ts +13 -0
- package/src/run-meta.ts +39 -0
- package/src/trigger.ts +114 -0
- package/src/workspace.ts +69 -0
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Pure types and schemas: manifest, events, run/unit state machines, IDs, refs. No IO.
|
|
4
|
+
|
|
5
|
+
See [docs/design](../../docs/design/README.md).
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Longest `agent.message` text the server accepts; runners cut longer text to fit, ending in `…`. */
|
|
3
|
+
export declare const AGENT_TEXT_MAX = 2000;
|
|
4
|
+
/** Longest tool input or result summary the server accepts. */
|
|
5
|
+
export declare const AGENT_SUMMARY_MAX = 200;
|
|
6
|
+
/** Data of each standard `agent.*` event at `v: 1` (agent-steps door 1). Extra keys are refused. */
|
|
7
|
+
export declare const AGENT_EVENT_DATA: {
|
|
8
|
+
readonly 'agent.started': z.ZodObject<{
|
|
9
|
+
runner: z.ZodString;
|
|
10
|
+
role: z.ZodString;
|
|
11
|
+
model: z.ZodOptional<z.ZodString>;
|
|
12
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
13
|
+
attempt: z.ZodNumber;
|
|
14
|
+
account: z.ZodOptional<z.ZodString>;
|
|
15
|
+
resumed: z.ZodOptional<z.ZodBoolean>;
|
|
16
|
+
}, z.core.$strict>;
|
|
17
|
+
readonly 'agent.message': z.ZodObject<{
|
|
18
|
+
role: z.ZodLiteral<"assistant">;
|
|
19
|
+
text: z.ZodString;
|
|
20
|
+
}, z.core.$strict>;
|
|
21
|
+
readonly 'agent.tool_call': z.ZodObject<{
|
|
22
|
+
tool: z.ZodString;
|
|
23
|
+
inputSummary: z.ZodString;
|
|
24
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
25
|
+
}, z.core.$strict>;
|
|
26
|
+
readonly 'agent.tool_result': z.ZodObject<{
|
|
27
|
+
tool: z.ZodString;
|
|
28
|
+
ok: z.ZodBoolean;
|
|
29
|
+
summary: z.ZodString;
|
|
30
|
+
toolUseId: z.ZodOptional<z.ZodString>;
|
|
31
|
+
denied: z.ZodOptional<z.ZodBoolean>;
|
|
32
|
+
}, z.core.$strict>;
|
|
33
|
+
readonly 'agent.usage': z.ZodObject<{
|
|
34
|
+
inputTokens: z.ZodNumber;
|
|
35
|
+
outputTokens: z.ZodNumber;
|
|
36
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
37
|
+
cacheCreationTokens: z.ZodOptional<z.ZodNumber>;
|
|
38
|
+
costUsd: z.ZodOptional<z.ZodNumber>;
|
|
39
|
+
quota: z.ZodOptional<z.ZodObject<{
|
|
40
|
+
fiveHour: z.ZodOptional<z.ZodNumber>;
|
|
41
|
+
sevenDay: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
resetsAt: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
}, z.core.$strict>>;
|
|
44
|
+
}, z.core.$strict>;
|
|
45
|
+
readonly 'agent.finished': z.ZodObject<{
|
|
46
|
+
status: z.ZodEnum<{
|
|
47
|
+
error: "error";
|
|
48
|
+
completed: "completed";
|
|
49
|
+
limit: "limit";
|
|
50
|
+
cancelled: "cancelled";
|
|
51
|
+
}>;
|
|
52
|
+
turns: z.ZodNumber;
|
|
53
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
54
|
+
transcriptRef: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strict>;
|
|
56
|
+
readonly 'agent.question': z.ZodObject<{
|
|
57
|
+
question: z.ZodString;
|
|
58
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
};
|
|
61
|
+
export type AgentEventType = keyof typeof AGENT_EVENT_DATA;
|
|
62
|
+
export declare const AGENT_EVENT_TYPES: AgentEventType[];
|
|
63
|
+
export type AgentEventData<T extends AgentEventType> = z.infer<(typeof AGENT_EVENT_DATA)[T]>;
|
|
64
|
+
export type AgentStatus = AgentEventData<'agent.finished'>['status'];
|
|
65
|
+
/**
|
|
66
|
+
* Cuts `text` to at most `max` chars, ending in `…` when it was cut. It never splits a surrogate
|
|
67
|
+
* pair: a lone surrogate is not valid in a jsonb string, so the server could not store the event.
|
|
68
|
+
*/
|
|
69
|
+
export declare function cut(text: string, max: number): string;
|
|
70
|
+
/** Problems with an `agent.*` event's data, each as `<type>: <field>: <message>`; empty when it is valid. */
|
|
71
|
+
export declare function agentEventProblems(type: AgentEventType, data: unknown): string[];
|
|
72
|
+
/**
|
|
73
|
+
* Problems with a worker event's data, each as `<type>: <field>: <message>`; empty when it is
|
|
74
|
+
* valid. `log` data is not checked; a type with no schema is the caller's to refuse.
|
|
75
|
+
*/
|
|
76
|
+
export declare function workerEventProblems(type: string, data: unknown): string[];
|
|
77
|
+
//# sourceMappingURL=agent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB,sGAAsG;AACtG,eAAO,MAAM,cAAc,OAAO,CAAC;AACnC,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAKrC,oGAAoG;AACpG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsDnB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,MAAM,OAAO,gBAAgB,CAAC;AAC3D,eAAO,MAAM,iBAAiB,EAAoC,cAAc,EAAE,CAAC;AACnF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,cAAc,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7F,MAAM,MAAM,WAAW,GAAG,cAAc,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,CAAC;AAErE;;;GAGG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAMrD;AAED,6GAA6G;AAC7G,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAEhF;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAYzE"}
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ARTIFACT_EVENT_DATA, SHA256 } from "./artifact.js";
|
|
3
|
+
import { GATE_EVENT_DATA } from "./gate.js";
|
|
4
|
+
import { EFFECT_EVENT_DATA, PLUGIN_EVENT_DATA } from "./plugin.js";
|
|
5
|
+
import { WORKSPACE_EVENT_DATA } from "./workspace.js";
|
|
6
|
+
/** Longest `agent.message` text the server accepts; runners cut longer text to fit, ending in `…`. */
|
|
7
|
+
export const AGENT_TEXT_MAX = 2000;
|
|
8
|
+
/** Longest tool input or result summary the server accepts. */
|
|
9
|
+
export const AGENT_SUMMARY_MAX = 200;
|
|
10
|
+
const count = z.number().int().nonnegative();
|
|
11
|
+
const name = z.string().min(1);
|
|
12
|
+
/** Data of each standard `agent.*` event at `v: 1` (agent-steps door 1). Extra keys are refused. */
|
|
13
|
+
export const AGENT_EVENT_DATA = {
|
|
14
|
+
'agent.started': z.strictObject({
|
|
15
|
+
runner: name,
|
|
16
|
+
role: name,
|
|
17
|
+
model: z.string().optional(),
|
|
18
|
+
sessionId: z.string().optional(),
|
|
19
|
+
/** 1, or 2 for the retry after an output contract failure */
|
|
20
|
+
attempt: z.number().int().min(1),
|
|
21
|
+
/** the server account the session runs on (agent-accounts door 6); absent with the worker's own login */
|
|
22
|
+
account: z.string().optional(),
|
|
23
|
+
/** true when resumed from a prior session, false on fresh fallback; absent when resume was not requested (AD-066) */
|
|
24
|
+
resumed: z.boolean().optional(),
|
|
25
|
+
}),
|
|
26
|
+
'agent.message': z.strictObject({
|
|
27
|
+
role: z.literal('assistant'),
|
|
28
|
+
text: z.string().max(AGENT_TEXT_MAX),
|
|
29
|
+
}),
|
|
30
|
+
'agent.tool_call': z.strictObject({
|
|
31
|
+
tool: name,
|
|
32
|
+
inputSummary: z.string().max(AGENT_SUMMARY_MAX),
|
|
33
|
+
toolUseId: z.string().optional(),
|
|
34
|
+
}),
|
|
35
|
+
'agent.tool_result': z.strictObject({
|
|
36
|
+
tool: name,
|
|
37
|
+
ok: z.boolean(),
|
|
38
|
+
summary: z.string().max(AGENT_SUMMARY_MAX),
|
|
39
|
+
toolUseId: z.string().optional(),
|
|
40
|
+
denied: z.boolean().optional(),
|
|
41
|
+
}),
|
|
42
|
+
'agent.usage': z.strictObject({
|
|
43
|
+
inputTokens: count,
|
|
44
|
+
outputTokens: count,
|
|
45
|
+
cacheReadTokens: count.optional(),
|
|
46
|
+
cacheCreationTokens: count.optional(),
|
|
47
|
+
costUsd: z.number().nonnegative().optional(),
|
|
48
|
+
quota: z
|
|
49
|
+
.strictObject({
|
|
50
|
+
fiveHour: z.number().optional(),
|
|
51
|
+
sevenDay: z.number().optional(),
|
|
52
|
+
resetsAt: z.number().optional(),
|
|
53
|
+
})
|
|
54
|
+
.optional(),
|
|
55
|
+
}),
|
|
56
|
+
'agent.finished': z.strictObject({
|
|
57
|
+
status: z.enum(['completed', 'limit', 'error', 'cancelled']),
|
|
58
|
+
turns: count,
|
|
59
|
+
reason: z.string().optional(),
|
|
60
|
+
/** sha256 of the session's transcript artifact (artifact-store door 7) */
|
|
61
|
+
transcriptRef: z.string().regex(SHA256, 'must be 64 lowercase hex chars').optional(),
|
|
62
|
+
}),
|
|
63
|
+
'agent.question': z.strictObject({
|
|
64
|
+
question: z.string().min(1).max(AGENT_TEXT_MAX),
|
|
65
|
+
options: z.array(z.string().min(1).max(AGENT_SUMMARY_MAX)).min(1).optional(),
|
|
66
|
+
}),
|
|
67
|
+
};
|
|
68
|
+
export const AGENT_EVENT_TYPES = Object.keys(AGENT_EVENT_DATA);
|
|
69
|
+
/**
|
|
70
|
+
* Cuts `text` to at most `max` chars, ending in `…` when it was cut. It never splits a surrogate
|
|
71
|
+
* pair: a lone surrogate is not valid in a jsonb string, so the server could not store the event.
|
|
72
|
+
*/
|
|
73
|
+
export function cut(text, max) {
|
|
74
|
+
if (text.length <= max)
|
|
75
|
+
return text;
|
|
76
|
+
let end = max - 1;
|
|
77
|
+
const last = text.charCodeAt(end - 1);
|
|
78
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
79
|
+
end -= 1;
|
|
80
|
+
return text.slice(0, end) + '…';
|
|
81
|
+
}
|
|
82
|
+
/** Problems with an `agent.*` event's data, each as `<type>: <field>: <message>`; empty when it is valid. */
|
|
83
|
+
export function agentEventProblems(type, data) {
|
|
84
|
+
return schemaProblems(type, AGENT_EVENT_DATA[type], data);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Problems with a worker event's data, each as `<type>: <field>: <message>`; empty when it is
|
|
88
|
+
* valid. `log` data is not checked; a type with no schema is the caller's to refuse.
|
|
89
|
+
*/
|
|
90
|
+
export function workerEventProblems(type, data) {
|
|
91
|
+
const schemas = {
|
|
92
|
+
...AGENT_EVENT_DATA,
|
|
93
|
+
...GATE_EVENT_DATA,
|
|
94
|
+
...WORKSPACE_EVENT_DATA,
|
|
95
|
+
...ARTIFACT_EVENT_DATA,
|
|
96
|
+
...PLUGIN_EVENT_DATA,
|
|
97
|
+
...EFFECT_EVENT_DATA,
|
|
98
|
+
};
|
|
99
|
+
const schema = schemas[type];
|
|
100
|
+
if (schema === undefined)
|
|
101
|
+
return [];
|
|
102
|
+
return schemaProblems(type, schema, data);
|
|
103
|
+
}
|
|
104
|
+
function schemaProblems(type, schema, data) {
|
|
105
|
+
const r = schema.safeParse(data);
|
|
106
|
+
if (r.success)
|
|
107
|
+
return [];
|
|
108
|
+
return r.error.issues.map((i) => {
|
|
109
|
+
const keys = i.code === 'unrecognized_keys' ? i.keys : [];
|
|
110
|
+
const field = [...i.path, ...keys].join('.') || '(data)';
|
|
111
|
+
return `${type}: ${field}: ${i.message}`;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,C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pB,GAAG,iBAAiB;KACrB,CAAC;IACF,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7B,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,SAAS,cAAc,CAAC,IAAY,EAAE,MAAiB,EAAE,IAAa;IACpE,MAAM,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,CAAC,CAAC,OAAO;QAAE,OAAO,EAAE,CAAC;IACzB,OAAO,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;QAC9B,MAAM,IAAI,GAAG,CAAC,CAAC,IAAI,KAAK,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC;QACzD,OAAO,GAAG,IAAI,KAAK,KAAK,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;IAC3C,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Longest artifact path (artifact-store door 3), as for a task `wd`. */
|
|
3
|
+
export declare const ARTIFACT_PATH_MAX = 200;
|
|
4
|
+
/** A content address: sha256 as 64 lowercase hex chars (door 1). */
|
|
5
|
+
export declare const SHA256: RegExp;
|
|
6
|
+
/**
|
|
7
|
+
* A media type the server can send back as `content-type`: printable ASCII (no CR, LF or other
|
|
8
|
+
* control char), no leading or trailing space, 1 to 200 chars.
|
|
9
|
+
*/
|
|
10
|
+
export declare const MEDIA_TYPE: RegExp;
|
|
11
|
+
/** Default `CF_ARTIFACT_MAX_BYTES`: the largest artifact the server stores (100 MiB). */
|
|
12
|
+
export declare const ARTIFACT_MAX_BYTES = 104857600;
|
|
13
|
+
/** Largest task `output` or answer `data`, as UTF-8 bytes of its JSON (door 6, AD-012). */
|
|
14
|
+
export declare const OUTPUT_MAX_BYTES = 65536;
|
|
15
|
+
/** Largest domain event `data`, as UTF-8 bytes of its JSON (door 5). */
|
|
16
|
+
export declare const DOMAIN_EVENT_MAX_BYTES = 8192;
|
|
17
|
+
/** Longest `progress` label (door 4). */
|
|
18
|
+
export declare const PROGRESS_LABEL_MAX = 200;
|
|
19
|
+
/** Problems with an artifact path: relative, segments of `[A-Za-z0-9._-]`, no `.`, `..` or empty one. */
|
|
20
|
+
export declare function artifactPathProblems(path: string): string[];
|
|
21
|
+
/** UTF-8 bytes of `JSON.stringify(value)`; 0 for `undefined`. */
|
|
22
|
+
export declare function outputBytes(value: unknown): number;
|
|
23
|
+
/** The output cap's message, or `undefined` when `output` fits (door 6). */
|
|
24
|
+
export declare function outputProblem(output: unknown): string | undefined;
|
|
25
|
+
/** Data of `progress` and `artifact.created` at `v: 1` (artifact-store door 4). Extra keys are refused. */
|
|
26
|
+
export declare const ARTIFACT_EVENT_DATA: {
|
|
27
|
+
readonly progress: z.ZodObject<{
|
|
28
|
+
label: z.ZodString;
|
|
29
|
+
pct: z.ZodOptional<z.ZodNumber>;
|
|
30
|
+
}, z.core.$strict>;
|
|
31
|
+
readonly 'artifact.created': z.ZodObject<{
|
|
32
|
+
path: z.ZodString;
|
|
33
|
+
sha256: z.ZodString;
|
|
34
|
+
size: z.ZodNumber;
|
|
35
|
+
mediaType: z.ZodString;
|
|
36
|
+
}, z.core.$strict>;
|
|
37
|
+
};
|
|
38
|
+
/** What `ctx.artifacts.put` resolves with (door 3). */
|
|
39
|
+
export interface ArtifactRef {
|
|
40
|
+
path: string;
|
|
41
|
+
sha256: string;
|
|
42
|
+
size: number;
|
|
43
|
+
mediaType: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Workflow ids that name a standard event family: such a workflow may declare no domain events,
|
|
47
|
+
* since `<id>.*` would collide with the platform's own types (door 5).
|
|
48
|
+
*/
|
|
49
|
+
export declare const RESERVED_FAMILIES: readonly ["run", "unit", "step", "control", "intervention", "worker", "log", "progress", "artifact", "effect", "hook", "workspace", "agent", "gate", "signal", "plugin", "map"];
|
|
50
|
+
/** Problems with a domain event type declared by workflow `workflowId` (door 5). */
|
|
51
|
+
export declare function eventTypeProblems(workflowId: string, type: string): string[];
|
|
52
|
+
//# sourceMappingURL=artifact.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.d.ts","sourceRoot":"","sources":["../src/artifact.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAGrC,oEAAoE;AACpE,eAAO,MAAM,MAAM,QAAmB,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,UAAU,QAAyC,CAAC;AAEjE,yFAAyF;AACzF,eAAO,MAAM,kBAAkB,YAAc,CAAC;AAE9C,2FAA2F;AAC3F,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC,wEAAwE;AACxE,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,yCAAyC;AACzC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,yGAAyG;AACzG,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ3D;AAED,iEAAiE;AACjE,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGlD;AAED,4EAA4E;AAC5E,wBAAgB,aAAa,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKjE;AAED,2GAA2G;AAC3G,eAAO,MAAM,mBAAmB;;;;;;;;;;;CAWtB,CAAC;AAEX,uDAAuD;AACvD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,iLAkBpB,CAAC;AAIX,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAS5E"}
|
package/dist/artifact.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/** Longest artifact path (artifact-store door 3), as for a task `wd`. */
|
|
3
|
+
export const ARTIFACT_PATH_MAX = 200;
|
|
4
|
+
const SEGMENT = /^[A-Za-z0-9._-]+$/;
|
|
5
|
+
/** A content address: sha256 as 64 lowercase hex chars (door 1). */
|
|
6
|
+
export const SHA256 = /^[0-9a-f]{64}$/;
|
|
7
|
+
/**
|
|
8
|
+
* A media type the server can send back as `content-type`: printable ASCII (no CR, LF or other
|
|
9
|
+
* control char), no leading or trailing space, 1 to 200 chars.
|
|
10
|
+
*/
|
|
11
|
+
export const MEDIA_TYPE = /^(?=.{1,200}$)[!-~](?:[ -~]*[!-~])?$/;
|
|
12
|
+
/** Default `CF_ARTIFACT_MAX_BYTES`: the largest artifact the server stores (100 MiB). */
|
|
13
|
+
export const ARTIFACT_MAX_BYTES = 104_857_600;
|
|
14
|
+
/** Largest task `output` or answer `data`, as UTF-8 bytes of its JSON (door 6, AD-012). */
|
|
15
|
+
export const OUTPUT_MAX_BYTES = 65_536;
|
|
16
|
+
/** Largest domain event `data`, as UTF-8 bytes of its JSON (door 5). */
|
|
17
|
+
export const DOMAIN_EVENT_MAX_BYTES = 8192;
|
|
18
|
+
/** Longest `progress` label (door 4). */
|
|
19
|
+
export const PROGRESS_LABEL_MAX = 200;
|
|
20
|
+
/** Problems with an artifact path: relative, segments of `[A-Za-z0-9._-]`, no `.`, `..` or empty one. */
|
|
21
|
+
export function artifactPathProblems(path) {
|
|
22
|
+
if (path.length === 0)
|
|
23
|
+
return ['is empty'];
|
|
24
|
+
if (path.length > ARTIFACT_PATH_MAX)
|
|
25
|
+
return [`longer than ${ARTIFACT_PATH_MAX} chars`];
|
|
26
|
+
if (path.startsWith('/'))
|
|
27
|
+
return ['must be relative'];
|
|
28
|
+
const bad = path.split('/').find((s) => s === '' || s === '.' || s === '..' || !SEGMENT.test(s));
|
|
29
|
+
if (bad === undefined)
|
|
30
|
+
return [];
|
|
31
|
+
if (bad === '' || bad === '.' || bad === '..')
|
|
32
|
+
return [`has a "${bad}" segment`];
|
|
33
|
+
return [`segment "${bad}" has a character outside [A-Za-z0-9._-]`];
|
|
34
|
+
}
|
|
35
|
+
/** UTF-8 bytes of `JSON.stringify(value)`; 0 for `undefined`. */
|
|
36
|
+
export function outputBytes(value) {
|
|
37
|
+
const json = JSON.stringify(value);
|
|
38
|
+
return json === undefined ? 0 : new TextEncoder().encode(json).length;
|
|
39
|
+
}
|
|
40
|
+
/** The output cap's message, or `undefined` when `output` fits (door 6). */
|
|
41
|
+
export function outputProblem(output) {
|
|
42
|
+
const n = outputBytes(output);
|
|
43
|
+
return n > OUTPUT_MAX_BYTES
|
|
44
|
+
? `output is ${n} bytes, more than ${OUTPUT_MAX_BYTES}; put large data in ctx.artifacts`
|
|
45
|
+
: undefined;
|
|
46
|
+
}
|
|
47
|
+
/** Data of `progress` and `artifact.created` at `v: 1` (artifact-store door 4). Extra keys are refused. */
|
|
48
|
+
export const ARTIFACT_EVENT_DATA = {
|
|
49
|
+
progress: z.strictObject({
|
|
50
|
+
label: z.string().min(1).max(PROGRESS_LABEL_MAX),
|
|
51
|
+
pct: z.number().min(0).max(100).optional(),
|
|
52
|
+
}),
|
|
53
|
+
'artifact.created': z.strictObject({
|
|
54
|
+
path: z.string().refine((p) => artifactPathProblems(p).length === 0, 'is not a valid artifact path'),
|
|
55
|
+
sha256: z.string().regex(SHA256, 'must be 64 lowercase hex chars'),
|
|
56
|
+
size: z.number().int().nonnegative(),
|
|
57
|
+
mediaType: z.string().regex(MEDIA_TYPE, 'must be printable ASCII of 1 to 200 chars'),
|
|
58
|
+
}),
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Workflow ids that name a standard event family: such a workflow may declare no domain events,
|
|
62
|
+
* since `<id>.*` would collide with the platform's own types (door 5).
|
|
63
|
+
*/
|
|
64
|
+
export const RESERVED_FAMILIES = [
|
|
65
|
+
'run',
|
|
66
|
+
'unit',
|
|
67
|
+
'step',
|
|
68
|
+
'control',
|
|
69
|
+
'intervention',
|
|
70
|
+
'worker',
|
|
71
|
+
'log',
|
|
72
|
+
'progress',
|
|
73
|
+
'artifact',
|
|
74
|
+
'effect',
|
|
75
|
+
'hook',
|
|
76
|
+
'workspace',
|
|
77
|
+
'agent',
|
|
78
|
+
'gate',
|
|
79
|
+
'signal',
|
|
80
|
+
'plugin',
|
|
81
|
+
'map',
|
|
82
|
+
];
|
|
83
|
+
const NAME = /^[a-z][a-z0-9-]*$/;
|
|
84
|
+
/** Problems with a domain event type declared by workflow `workflowId` (door 5). */
|
|
85
|
+
export function eventTypeProblems(workflowId, type) {
|
|
86
|
+
if (RESERVED_FAMILIES.includes(workflowId)) {
|
|
87
|
+
return [`workflow id "${workflowId}" is a standard event family and may declare no events`];
|
|
88
|
+
}
|
|
89
|
+
const prefix = `${workflowId}.`;
|
|
90
|
+
if (!type.startsWith(prefix))
|
|
91
|
+
return [`must start with "${prefix}"`];
|
|
92
|
+
const rest = type.slice(prefix.length).split('.');
|
|
93
|
+
if (rest.some((s) => !NAME.test(s)))
|
|
94
|
+
return ['each part after the workflow id must match [a-z][a-z0-9-]*'];
|
|
95
|
+
return [];
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=artifact.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"artifact.js","sourceRoot":"","sources":["../src/artifact.ts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ory/invalid_input' | 'code_factory/invalid_manifest' | 'code_factory/workflow_not_found' | 'code_factory/run_not_found' | 'code_factory/unauthorized' | 'code_factory/workflow_not_allowed' | 'code_factory/manifest_conflict' | 'code_factory/lease_mismatch' | 'code_factory/lease_expired' | 'code_factory/run_ended' | 'code_factory/unit_cancelled' | 'code_factory/intervention_not_found' | 'code_factory/intervention_closed' | 'code_factory/not_found' | 'code_factory/artifact_not_found' | 'code_factory/digest_mismatch' | 'code_factory/too_large' | 'code_factory/invalid_signature' | 'code_factory/payload_too_large' | 'code_factory/plugin_unavailable' | 'code_factory/unknown_action' | 'code_factory/plugin_action_failed' | 'code_factory/manual_not_allowed' | 'code_factory/active_run' | 'code_factory/agent_account_exists' | 'code_factory/agent_account_rejected' | 'code_factory/agent_account_check_failed' | 'code_factory/agent_account_unavailable' | 'code_factory/secrets_key_missing' | 'code_factory/unauthenticated' | 'code_factory/forbidden' | 'code_factory/csrf_required' | 'code_factory/login_failed' | 'code_factory/worker_not_found' | 'code_factory/key_taken' | 'code_factory/instance_exists' | 'code_factory/public_url_missing' | 'code_factory/instance_not_found' | 'code_factory/instance_from_env' | 'code_factory/instance_in_use' | 'code_factory/repo_not_in_installation' | 'code_factory/github_key_rejected' | 'code_factory/installation_not_found' | 'code_factory/linear_key_rejected' | 'code_factory/linear_team_not_found' | 'code_factory/setup_expired' | 'code_factory/github_conversion_failed';
|
|
2
|
+
/** Body of every error response. */
|
|
3
|
+
export interface ErrorBody {
|
|
4
|
+
/**
|
|
5
|
+
* `retryAt`: `agent_account_unavailable` only, the earliest cooldown end as ISO or null;
|
|
6
|
+
* `role`: `forbidden` only, the role the route needs (oidc-login AC 16);
|
|
7
|
+
* `workflows`: `instance_in_use` only; `repos`: `repo_not_in_installation` only
|
|
8
|
+
*/
|
|
9
|
+
error: {
|
|
10
|
+
code: ErrorCode;
|
|
11
|
+
message: string;
|
|
12
|
+
retryAt?: string | null;
|
|
13
|
+
role?: 'viewer' | 'operator' | 'admin';
|
|
14
|
+
workflows?: string[];
|
|
15
|
+
repos?: string[];
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GACjB,4BAA4B,GAC5B,+BAA+B,GAC/B,iCAAiC,GACjC,4BAA4B,GAC5B,2BAA2B,GAC3B,mCAAmC,GACnC,gCAAgC,GAChC,6BAA6B,GAC7B,4BAA4B,GAC5B,wBAAwB,GACxB,6BAA6B,GAC7B,qCAAqC,GACrC,kCAAkC,GAClC,wBAAwB,GAExB,iCAAiC,GACjC,8BAA8B,GAC9B,wBAAwB,GAExB,gCAAgC,GAChC,gCAAgC,GAChC,iCAAiC,GAEjC,6BAA6B,GAC7B,mCAAmC,GAEnC,iCAAiC,GACjC,yBAAyB,GAEzB,mCAAmC,GACnC,qCAAqC,GACrC,yCAAyC,GACzC,wCAAwC,GACxC,kCAAkC,GAElC,8BAA8B,GAC9B,wBAAwB,GACxB,4BAA4B,GAC5B,2BAA2B,GAE3B,+BAA+B,GAE/B,wBAAwB,GAExB,8BAA8B,GAC9B,iCAAiC,GACjC,iCAAiC,GACjC,gCAAgC,GAChC,8BAA8B,GAC9B,uCAAuC,GACvC,kCAAkC,GAClC,qCAAqC,GACrC,kCAAkC,GAClC,oCAAoC,GACpC,4BAA4B,GAC5B,uCAAuC,CAAC;AAE5C,oCAAoC;AACpC,MAAM,WAAW,SAAS;IACxB;;;;OAIG;IACH,KAAK,EAAE;QAAE,IAAI,EAAE,SAAS,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,OAAO,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CACtJ"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":""}
|
package/dist/events.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export type ActorKind = 'human' | 'signal' | 'worker' | 'engine' | 'code' | 'agent';
|
|
2
|
+
export interface Actor {
|
|
3
|
+
kind: ActorKind;
|
|
4
|
+
id: string;
|
|
5
|
+
onBehalfOf?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface CfEvent<D = Record<string, unknown>> {
|
|
8
|
+
id: string;
|
|
9
|
+
seq: number;
|
|
10
|
+
type: string;
|
|
11
|
+
v: number;
|
|
12
|
+
time: string;
|
|
13
|
+
receivedAt?: string;
|
|
14
|
+
runId?: string;
|
|
15
|
+
unitId?: string;
|
|
16
|
+
workflow?: {
|
|
17
|
+
id: string;
|
|
18
|
+
version: string;
|
|
19
|
+
};
|
|
20
|
+
actor: Actor;
|
|
21
|
+
data: D;
|
|
22
|
+
}
|
|
23
|
+
/** An event before the server gives it an id, seq and envelope. */
|
|
24
|
+
export interface EventDraft {
|
|
25
|
+
type: string;
|
|
26
|
+
unitId?: string;
|
|
27
|
+
data: Record<string, unknown>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Event types a worker may send in heartbeats and on complete: `log`, the six `agent.*`
|
|
31
|
+
* (agent-steps door 1), the four built `gate.*` (gate-events door 2), and `hook.*` and
|
|
32
|
+
* `workspace.*` (run-workspace door 7), `progress` and `artifact.created` (artifact-store door 4),
|
|
33
|
+
* and `effect.*` (boss-sdd-gaps door 1). `plugin.action.*` is appended by the server around the
|
|
34
|
+
* actions it runs (AD-048), never sent by a worker. Domain events (`<workflow-id>.*`) are not listed:
|
|
35
|
+
* the server checks them against the run's manifest.
|
|
36
|
+
*/
|
|
37
|
+
export declare const WORKER_EVENT_TYPES: readonly ["log", "agent.started", "agent.message", "agent.tool_call", "agent.tool_result", "agent.usage", "agent.finished", "agent.question", "gate.passed", "gate.failed", "gate.not_executed", "gate.not_configured", "hook.started", "hook.completed", "hook.failed", "workspace.created", "workspace.deleted", "workspace.kept", "progress", "artifact.created", "effect.deferred", "effect.applied", "effect.failed"];
|
|
38
|
+
export type WorkerEventType = (typeof WORKER_EVENT_TYPES)[number];
|
|
39
|
+
/** `aborted`: ended by a person with `cf run stop` (AD-004). */
|
|
40
|
+
export type RunStatus = 'running' | 'succeeded' | 'failed' | 'aborted';
|
|
41
|
+
/** Whether a running run is held: `pausing` while a unit is in flight, then `paused`. */
|
|
42
|
+
export type PauseState = 'pausing' | 'paused' | null;
|
|
43
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;AAEpF,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,OAAO,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClD,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,EAAE,MAAM,CAAC;IACV,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,CAAC,CAAC;CACT;AAED,mEAAmE;AACnE,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,4ZA0BrB,CAAC;AACX,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE,gEAAgE;AAChE,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEvE,yFAAyF;AACzF,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,QAAQ,GAAG,IAAI,CAAC"}
|
package/dist/events.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event types a worker may send in heartbeats and on complete: `log`, the six `agent.*`
|
|
3
|
+
* (agent-steps door 1), the four built `gate.*` (gate-events door 2), and `hook.*` and
|
|
4
|
+
* `workspace.*` (run-workspace door 7), `progress` and `artifact.created` (artifact-store door 4),
|
|
5
|
+
* and `effect.*` (boss-sdd-gaps door 1). `plugin.action.*` is appended by the server around the
|
|
6
|
+
* actions it runs (AD-048), never sent by a worker. Domain events (`<workflow-id>.*`) are not listed:
|
|
7
|
+
* the server checks them against the run's manifest.
|
|
8
|
+
*/
|
|
9
|
+
export const WORKER_EVENT_TYPES = [
|
|
10
|
+
'log',
|
|
11
|
+
'agent.started',
|
|
12
|
+
'agent.message',
|
|
13
|
+
'agent.tool_call',
|
|
14
|
+
'agent.tool_result',
|
|
15
|
+
'agent.usage',
|
|
16
|
+
'agent.finished',
|
|
17
|
+
'agent.question',
|
|
18
|
+
'gate.passed',
|
|
19
|
+
'gate.failed',
|
|
20
|
+
'gate.not_executed',
|
|
21
|
+
'gate.not_configured',
|
|
22
|
+
'hook.started',
|
|
23
|
+
'hook.completed',
|
|
24
|
+
'hook.failed',
|
|
25
|
+
'workspace.created',
|
|
26
|
+
'workspace.deleted',
|
|
27
|
+
'workspace.kept',
|
|
28
|
+
// artifact-store
|
|
29
|
+
'progress',
|
|
30
|
+
'artifact.created',
|
|
31
|
+
// boss-sdd-gaps door 1: deferred effects
|
|
32
|
+
'effect.deferred',
|
|
33
|
+
'effect.applied',
|
|
34
|
+
'effect.failed',
|
|
35
|
+
];
|
|
36
|
+
//# sourceMappingURL=events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.js","sourceRoot":"","sources":["../src/events.ts"],"names":[],"mappings":"AA6BA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,KAAK;IACL,eAAe;IACf,eAAe;IACf,iBAAiB;IACjB,mBAAmB;IACnB,aAAa;IACb,gBAAgB;IAChB,gBAAgB;IAChB,aAAa;IACb,aAAa;IACb,mBAAmB;IACnB,qBAAqB;IACrB,cAAc;IACd,gBAAgB;IAChB,aAAa;IACb,mBAAmB;IACnB,mBAAmB;IACnB,gBAAgB;IAChB,iBAAiB;IACjB,UAAU;IACV,kBAAkB;IAClB,yCAAyC;IACzC,iBAAiB;IACjB,gBAAgB;IAChB,eAAe;CACP,CAAC"}
|
package/dist/form.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules for a human step's form (human-steps door 7), shared by the CLI's prompts and the
|
|
3
|
+
* dashboard's answer form. Browser-safe: no Node imports, so it is also exported as
|
|
4
|
+
* `@artieeez/cf-core/form`.
|
|
5
|
+
*/
|
|
6
|
+
export interface FormProperty {
|
|
7
|
+
type?: unknown;
|
|
8
|
+
enum?: unknown[];
|
|
9
|
+
title?: unknown;
|
|
10
|
+
description?: unknown;
|
|
11
|
+
/** suggested answers (a `questionsForm` question's options): any other string is valid too */
|
|
12
|
+
'x-cf-options'?: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Which input a property gets; `json` means no input can take it. `select` is a strict string
|
|
16
|
+
* `enum`; `choice` is a string with suggested `x-cf-options` that also takes any other text.
|
|
17
|
+
*/
|
|
18
|
+
export type FieldKind = 'select' | 'choice' | 'boolean' | 'number' | 'integer' | 'text' | 'json';
|
|
19
|
+
export interface FormField {
|
|
20
|
+
name: string;
|
|
21
|
+
prop: FormProperty;
|
|
22
|
+
required: boolean;
|
|
23
|
+
kind: FieldKind;
|
|
24
|
+
/** the choices of a `select`, or the suggestions of a `choice` */
|
|
25
|
+
options: string[];
|
|
26
|
+
/** human-readable label (e.g. a dynamic question), if declared on the property */
|
|
27
|
+
title?: string;
|
|
28
|
+
/** optional helper text shown under the label */
|
|
29
|
+
description?: string;
|
|
30
|
+
}
|
|
31
|
+
/** Why `value` is not a valid runtime form JSON Schema object, or undefined when it is. */
|
|
32
|
+
export declare function formSchemaProblem(value: unknown): string | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* The form's properties in its order, and which are required. The order is `x-cf-order`, then any
|
|
35
|
+
* property it does not list: the stored `properties` object has lost its key order.
|
|
36
|
+
*/
|
|
37
|
+
export declare function formFields(form: Record<string, unknown>): FormField[];
|
|
38
|
+
/** The first property no input can take (an array, an object, or no type at all), if any. */
|
|
39
|
+
export declare function unaskableField(form: Record<string, unknown>): string | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* Why a typed entry is refused, or undefined when it is accepted. `''` and an entry of only
|
|
42
|
+
* spaces are empty.
|
|
43
|
+
*/
|
|
44
|
+
export declare function entryError(field: Pick<FormField, 'name' | 'kind' | 'required'>, value: string): string | undefined;
|
|
45
|
+
/** A typed entry as the value sent in `data`: numbers coerced, anything else as typed. */
|
|
46
|
+
export declare function coerceEntry(field: Pick<FormField, 'kind'>, value: string): string | number;
|
|
47
|
+
/**
|
|
48
|
+
* `data` from a form's entries, keyed by field name: an empty optional entry (or one of only
|
|
49
|
+
* spaces) is left out; a boolean has no empty state, so an unticked one is sent as `false`. Returns the per-field errors instead when any entry is refused.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildData(fields: FormField[], entries: Record<string, string | boolean | undefined>): {
|
|
52
|
+
data: Record<string, unknown>;
|
|
53
|
+
} | {
|
|
54
|
+
errors: Record<string, string>;
|
|
55
|
+
};
|
|
56
|
+
/** Parses the JSON area's text as `data`: it must be a JSON object. */
|
|
57
|
+
export declare function parseDataJson(text: string): {
|
|
58
|
+
data: Record<string, unknown>;
|
|
59
|
+
} | {
|
|
60
|
+
error: string;
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,WAAW,YAAY;IAC3B,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,8FAA8F;IAC9F,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEjG,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,YAAY,CAAC;IACnB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,SAAS,CAAC;IAChB,kEAAkE;IAClE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,kFAAkF;IAClF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iDAAiD;IACjD,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,2FAA2F;AAC3F,wBAAg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