@bendyline/gezel-sdk 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.
@@ -0,0 +1,282 @@
1
+ /**
2
+ * Descriptor types mirroring `packages/core/src/schemas/script.ts`. We
3
+ * intentionally duplicate the shapes here (rather than taking a runtime
4
+ * dep on `@bendyline/gezel`) so the SDK stays tiny and vendor-friendly —
5
+ * scripts can import this package without pulling in all of core.
6
+ */
7
+ /**
8
+ * A permission a script must declare in `meta.requires` before it may
9
+ * use the corresponding {@link import('./index.js').GezelSDK | `gezel`}
10
+ * namespace. The runtime denies any call whose capability is absent from
11
+ * the list (`CAPABILITY_DENIED`). The mapping is:
12
+ *
13
+ * - `llm` → `gezel.llm.oneShot`
14
+ * - `network` → `gezel.mcp.call`, `gezel.http.authed`
15
+ * - `workspace.read` / `workspace.write` → `gezel.fs.*`
16
+ * - `artifacts.read` / `artifacts.write` → `gezel.artifacts.*`
17
+ * - `documents.read` / `documents.write` → `gezel.documents.*`
18
+ * - `tasks.read` / `tasks.write` → `gezel.task.*`
19
+ * - `memory.read` / `memory.write` → `gezel.memory.*`
20
+ *
21
+ * `gezel.http.authed` additionally needs a `credential:<name>` entry
22
+ * (declared as a raw string in `requires`) naming each credential it uses.
23
+ */
24
+ type ScriptCapability = 'llm' | 'network' | 'workspace.read' | 'workspace.write' | 'artifacts.read' | 'artifacts.write' | 'documents.read' | 'documents.write' | 'tasks.read' | 'tasks.write' | 'memory.read' | 'memory.write';
25
+ /** A free-text string input field. */
26
+ interface ScriptStringInput {
27
+ type: 'string';
28
+ /** Human-readable label/help shown in the input form. */
29
+ description: string;
30
+ /** When `true`, the value must be supplied. Defaults to `false`. */
31
+ required?: boolean;
32
+ /** Default value used when none is supplied. */
33
+ default?: string;
34
+ /** Optional regular-expression source the value must match. */
35
+ pattern?: string;
36
+ /** Render a multi-line text area instead of a single-line field. */
37
+ multiline?: boolean;
38
+ }
39
+ /** A numeric input field. */
40
+ interface ScriptNumberInput {
41
+ type: 'number';
42
+ /** Human-readable label/help shown in the input form. */
43
+ description: string;
44
+ /** When `true`, the value must be supplied. Defaults to `false`. */
45
+ required?: boolean;
46
+ /** Default value used when none is supplied. */
47
+ default?: number;
48
+ /** Inclusive minimum accepted value. */
49
+ min?: number;
50
+ /** Inclusive maximum accepted value. */
51
+ max?: number;
52
+ /** Require a whole number (reject fractional values). */
53
+ integer?: boolean;
54
+ }
55
+ /** A boolean (checkbox) input field. */
56
+ interface ScriptBooleanInput {
57
+ type: 'boolean';
58
+ /** Human-readable label/help shown in the input form. */
59
+ description: string;
60
+ /** When `true`, the value must be supplied. Defaults to `false`. */
61
+ required?: boolean;
62
+ /** Default value used when none is supplied. */
63
+ default?: boolean;
64
+ }
65
+ /** One selectable option in a {@link ScriptChoiceInput}. */
66
+ interface ScriptChoiceOption {
67
+ /** The value stored/passed when this option is selected. */
68
+ value: string;
69
+ /** Optional display label; falls back to `value` when omitted. */
70
+ label?: string;
71
+ }
72
+ /**
73
+ * A single-select input constrained to a fixed list of options. Declare
74
+ * `options` `as const` to get literal-typed inference on the resolved
75
+ * input value.
76
+ */
77
+ interface ScriptChoiceInput<O extends readonly ScriptChoiceOption[] = readonly ScriptChoiceOption[]> {
78
+ type: 'choice';
79
+ /** Human-readable label/help shown in the input form. */
80
+ description: string;
81
+ /** When `true`, the value must be supplied. Defaults to `false`. */
82
+ required?: boolean;
83
+ /** Default selected `value`; must be one of `options`. */
84
+ default?: string;
85
+ /** The allowed options. */
86
+ options: O;
87
+ }
88
+ /**
89
+ * A reference picker — selects an existing entity by id. The resolved
90
+ * input value is the referenced entity's id (a string).
91
+ */
92
+ interface ScriptRefInput {
93
+ type: 'ref';
94
+ /** Human-readable label/help shown in the input form. */
95
+ description: string;
96
+ /** When `true`, the value must be supplied. Defaults to `false`. */
97
+ required?: boolean;
98
+ /** Which kind of entity may be referenced. */
99
+ kind: 'gezel' | 'task' | 'artifact' | 'document';
100
+ }
101
+ /** A free-form JSON input field, optionally validated against a schema. */
102
+ interface ScriptJsonInput {
103
+ type: 'json';
104
+ /** Human-readable label/help shown in the input form. */
105
+ description: string;
106
+ /** When `true`, the value must be supplied. Defaults to `false`. */
107
+ required?: boolean;
108
+ /** Default value used when none is supplied. */
109
+ default?: unknown;
110
+ /** Optional JSON Schema the supplied value is validated against. */
111
+ schema?: unknown;
112
+ }
113
+ /** Any input field descriptor; discriminated by its `type`. */
114
+ type ScriptInputField = ScriptStringInput | ScriptNumberInput | ScriptBooleanInput | ScriptChoiceInput | ScriptRefInput | ScriptJsonInput;
115
+ /** A script's input descriptors, keyed by input name (`meta.inputs`). */
116
+ type ScriptInputs = Record<string, ScriptInputField>;
117
+ /** A string field of the script's output. */
118
+ interface ScriptStringOutput {
119
+ type: 'string';
120
+ /** Human-readable description of this output field. */
121
+ description: string;
122
+ /** Allow `null` as a value for this field. */
123
+ nullable?: boolean;
124
+ }
125
+ /** A numeric field of the script's output. */
126
+ interface ScriptNumberOutput {
127
+ type: 'number';
128
+ /** Human-readable description of this output field. */
129
+ description: string;
130
+ /** Allow `null` as a value for this field. */
131
+ nullable?: boolean;
132
+ }
133
+ /** A boolean field of the script's output. */
134
+ interface ScriptBooleanOutput {
135
+ type: 'boolean';
136
+ /** Human-readable description of this output field. */
137
+ description: string;
138
+ /** Allow `null` as a value for this field. */
139
+ nullable?: boolean;
140
+ }
141
+ /** An array field of the script's output. */
142
+ interface ScriptArrayOutput {
143
+ type: 'array';
144
+ /** Human-readable description of this output field. */
145
+ description: string;
146
+ /** The type of each element in the array. */
147
+ itemType: 'string' | 'number' | 'boolean' | 'object';
148
+ }
149
+ /** An object field of the script's output. */
150
+ interface ScriptObjectOutput {
151
+ type: 'object';
152
+ /** Human-readable description of this output field. */
153
+ description: string;
154
+ /** Optional JSON Schema describing the object's shape. */
155
+ schema?: unknown;
156
+ }
157
+ /** A free-form JSON field of the script's output. */
158
+ interface ScriptJsonOutput {
159
+ type: 'json';
160
+ /** Human-readable description of this output field. */
161
+ description: string;
162
+ /** Optional JSON Schema the value conforms to. */
163
+ schema?: unknown;
164
+ }
165
+ /** Any output field descriptor; discriminated by its `type`. */
166
+ type ScriptOutputField = ScriptStringOutput | ScriptNumberOutput | ScriptBooleanOutput | ScriptArrayOutput | ScriptObjectOutput | ScriptJsonOutput;
167
+ /** A script's output descriptors, keyed by field name (`meta.outputs`). */
168
+ type ScriptOutputs = Record<string, ScriptOutputField>;
169
+ /**
170
+ * The metadata block every script exports (conventionally via
171
+ * {@link import('./index.js').defineScript | `defineScript`}). It names
172
+ * the script, declares its typed inputs/outputs, and lists the
173
+ * capabilities the runtime must grant. The input/output descriptors also
174
+ * drive type inference for `gezel.input` and the `gezel.output(...)`
175
+ * payload (see {@link InferInput} / {@link InferOutput}).
176
+ *
177
+ * @typeParam I - The `inputs` descriptor map (or `undefined`).
178
+ * @typeParam O - The `outputs` descriptor map (or `undefined`).
179
+ */
180
+ interface ScriptMeta<I extends ScriptInputs | undefined = ScriptInputs | undefined, O extends ScriptOutputs | undefined = ScriptOutputs | undefined> {
181
+ /** Unique script name, used to invoke it (including from `gezel.script.run`). */
182
+ name: string;
183
+ /** One-line description of what the script does. */
184
+ description: string;
185
+ /**
186
+ * What the script is for. `gate` = it is meant to be attached to a
187
+ * craftbook step's gate and stamps a {@link GateScriptResult} via
188
+ * `gezel.output(...)`. Absent = 'action'.
189
+ */
190
+ kind?: 'action' | 'gate';
191
+ /** Typed input descriptors; surfaced on `gezel.input`. */
192
+ inputs?: I;
193
+ /** Typed output descriptors; describe the `gezel.output(...)` payload. */
194
+ outputs?: O;
195
+ /**
196
+ * Capabilities this script needs. Each maps to a `gezel` namespace
197
+ * (see {@link ScriptCapability}); the runtime denies any call whose
198
+ * capability is missing here. For `gezel.http.authed`, also add a raw
199
+ * `credential:<name>` string for each credential used.
200
+ */
201
+ requires?: ScriptCapability[];
202
+ }
203
+ /**
204
+ * The structured verdict a GATE script stamps via `gezel.output(...)`.
205
+ * Mirrors `GateScriptResultSchema` in @bendyline/gezel (the SDK stays
206
+ * runtime-dependency-free, so the shape is mirrored, not imported).
207
+ *
208
+ * - `approve` → the step may complete; optional `goto` overrides routing.
209
+ * - `reject` → the step does NOT complete. `message` is REQUIRED and
210
+ * must be prescriptive — it is shown to the working LLM session
211
+ * verbatim as the instruction for what to fix. Optional `goto`
212
+ * re-activates a (usually earlier) step — this is how craftbooks loop.
213
+ * - `handoff` → on approve, a payload delivered to the next step.
214
+ */
215
+ interface GateScriptResult {
216
+ /** `approve` lets the step complete; `reject` blocks it. */
217
+ decision: 'approve' | 'reject';
218
+ /**
219
+ * On `reject`, **required** and prescriptive — shown verbatim to the
220
+ * working LLM session as the instruction for what to fix. On
221
+ * `approve`, an optional note.
222
+ */
223
+ message?: string;
224
+ /**
225
+ * Name of a step to route to. On `reject`, re-activates a (usually
226
+ * earlier) step — this is how craftbooks loop. On `approve`, overrides
227
+ * the default next step.
228
+ */
229
+ goto?: string;
230
+ /** On `approve`, a payload delivered to the next step. */
231
+ handoff?: {
232
+ message: string;
233
+ params?: Record<string, unknown>;
234
+ };
235
+ }
236
+ type ResolvedInputValue<F> = F extends ScriptStringInput ? string : F extends ScriptNumberInput ? number : F extends ScriptBooleanInput ? boolean : F extends ScriptChoiceInput<infer O> ? O[number]['value'] : F extends ScriptRefInput ? string : F extends ScriptJsonInput ? unknown : never;
237
+ type IsAlwaysPresent<F> = F extends {
238
+ required: true;
239
+ } ? true : F extends {
240
+ default: unknown;
241
+ } ? true : false;
242
+ type RequiredKeys<I> = {
243
+ [K in keyof I]: IsAlwaysPresent<I[K]> extends true ? K : never;
244
+ }[keyof I];
245
+ type OptionalKeys<I> = {
246
+ [K in keyof I]: IsAlwaysPresent<I[K]> extends true ? never : K;
247
+ }[keyof I];
248
+ /**
249
+ * Derive the concrete `gezel.input` type from a `meta.inputs` descriptor
250
+ * map: each field becomes its resolved value type, and fields that are
251
+ * `required` or have a `default` become non-optional. Prefer the
252
+ * {@link import('./index.js').InferredInput | `InferredInput<typeof meta>`}
253
+ * alias in scripts.
254
+ *
255
+ * @typeParam I - The `meta.inputs` descriptor map.
256
+ */
257
+ type InferInput<I extends ScriptInputs | undefined> = I extends ScriptInputs ? {
258
+ [K in RequiredKeys<I>]: ResolvedInputValue<I[K]>;
259
+ } & {
260
+ [K in OptionalKeys<I>]?: ResolvedInputValue<I[K]>;
261
+ } : Record<string, unknown>;
262
+ type ResolvedOutputValue<F> = F extends ScriptStringOutput ? string | (F extends {
263
+ nullable: true;
264
+ } ? null : never) : F extends ScriptNumberOutput ? number | (F extends {
265
+ nullable: true;
266
+ } ? null : never) : F extends ScriptBooleanOutput ? boolean | (F extends {
267
+ nullable: true;
268
+ } ? null : never) : F extends ScriptArrayOutput ? unknown[] : F extends ScriptObjectOutput ? Record<string, unknown> : F extends ScriptJsonOutput ? unknown : never;
269
+ /**
270
+ * Derive the concrete `gezel.output(...)` payload type from a
271
+ * `meta.outputs` descriptor map: each field becomes its resolved value
272
+ * type (with `null` added when `nullable` is set). Prefer the
273
+ * {@link import('./index.js').InferredOutput | `InferredOutput<typeof meta>`}
274
+ * alias in scripts.
275
+ *
276
+ * @typeParam O - The `meta.outputs` descriptor map.
277
+ */
278
+ type InferOutput<O extends ScriptOutputs | undefined> = O extends ScriptOutputs ? {
279
+ [K in keyof O]: ResolvedOutputValue<O[K]>;
280
+ } : unknown;
281
+
282
+ export type { GateScriptResult as G, InferInput as I, ScriptMeta as S, InferOutput as a, ScriptInputs as b, ScriptOutputs as c, ScriptArrayOutput as d, ScriptBooleanInput as e, ScriptBooleanOutput as f, ScriptCapability as g, ScriptChoiceInput as h, ScriptChoiceOption as i, ScriptInputField as j, ScriptJsonInput as k, ScriptJsonOutput as l, ScriptNumberInput as m, ScriptNumberOutput as n, ScriptObjectOutput as o, ScriptOutputField as p, ScriptRefInput as q, ScriptStringInput as r, ScriptStringOutput as s };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@bendyline/gezel-sdk",
3
+ "version": "0.1.0",
4
+ "description": "SDK imported by scripts running in the Gezel sandbox. Exposes the `gezel` object and `defineScript` helper.",
5
+ "license": "MIT",
6
+ "keywords": [
7
+ "gezel",
8
+ "ai",
9
+ "agents",
10
+ "local-first",
11
+ "sdk",
12
+ "extensions"
13
+ ],
14
+ "homepage": "https://github.com/bendyline/gezel",
15
+ "bugs": {
16
+ "url": "https://github.com/bendyline/gezel/issues"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/bendyline/gezel.git",
21
+ "directory": "packages/sdk"
22
+ },
23
+ "author": {
24
+ "name": "Bendyline",
25
+ "email": "support@bendyline.com"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public",
29
+ "provenance": true
30
+ },
31
+ "type": "module",
32
+ "engines": {
33
+ "node": ">=24.0.0"
34
+ },
35
+ "main": "./dist/index.js",
36
+ "module": "./dist/index.js",
37
+ "types": "./dist/index.d.ts",
38
+ "exports": {
39
+ ".": {
40
+ "types": "./dist/index.d.ts",
41
+ "import": "./dist/index.js"
42
+ },
43
+ "./checks": {
44
+ "types": "./dist/checks.d.ts",
45
+ "import": "./dist/checks.js"
46
+ },
47
+ "./stores": {
48
+ "types": "./dist/stores.d.ts",
49
+ "import": "./dist/stores.js"
50
+ },
51
+ "./package.json": "./package.json"
52
+ },
53
+ "files": [
54
+ "dist",
55
+ "!dist/**/*.map"
56
+ ],
57
+ "devDependencies": {
58
+ "tsup": "^8.5.1",
59
+ "typescript": "^6.0.3",
60
+ "vitest": "^4.1.10",
61
+ "@bendyline/gezel": "0.1.0"
62
+ },
63
+ "scripts": {
64
+ "build": "tsup",
65
+ "dev": "tsup --watch",
66
+ "typecheck": "tsc --noEmit",
67
+ "clean": "rm -rf dist .turbo",
68
+ "test": "vitest run"
69
+ }
70
+ }