@nanobpm/urban 0.16.1 → 0.17.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.
@@ -1,138 +1,8 @@
1
1
  import type { HostContext } from "./host.ts";
2
- export interface DataSource {
3
- driver: string;
4
- url: string;
5
- migrations?: string;
6
- }
7
- export interface TypeField {
8
- type: string;
9
- optional?: boolean;
10
- }
11
- export interface DomainType {
12
- name?: string;
13
- table?: string;
14
- fields?: Record<string, TypeField>;
15
- }
16
- export interface WorkerDecl {
17
- /** Job/task type the worker subscribes to. Schema allows `taskType` or `type`. */
18
- taskType?: string;
19
- type?: string;
20
- /** Path to the handler module, relative to the app root. Mutually exclusive with `llm`. */
21
- handler?: string;
22
- /** Name of an `llm[]` binding used as the worker (LLM-as-worker). Mutually exclusive with `handler`. */
23
- llm?: string;
24
- }
25
- /**
26
- * One named LLM binding (`llm.<id>` in the manifest). A binding is usable as a worker
27
- * (LLM-as-worker, ADR 0022 §E role 1) or as a chat surface agent. `provider` selects how
28
- * the endpoint is resolved (`"env"` reads it from the environment); `model` is typically
29
- * an env template. When `output.decision` is set, the model's JSON reply is fed through
30
- * that DMN decision (the "rails") and the decision's output is returned instead.
31
- */
32
- export interface LlmBinding {
33
- /** Provider selector. `"env"` resolves an OpenAI-compatible endpoint from the environment. */
34
- provider: string;
35
- /** Model id, typically an env template (e.g. `${NANO_APP_LLM_MODEL}`). */
36
- model: string;
37
- /** Constrains the model's structured output — currently a DMN decision id (the rails). */
38
- output?: {
39
- decision?: string;
40
- };
41
- /** Action-API tools the agent may call (chat-agent role; unused by the worker role). */
42
- tools?: string[];
43
- }
44
- export interface TriggerDecl {
45
- id: string;
46
- type: string;
47
- path?: string;
48
- auth?: string;
49
- /** cron: the 5-field crontab spec (UTC), e.g. "0 6 * * *". */
50
- spec?: string;
51
- /** cron catch-up policy for fires missed while the app was down. Default "skip". */
52
- onMissed?: "skip" | "once" | "all";
53
- /** Source-kind-specific settings (e.g. file `{ pollMs }`). */
54
- config?: Record<string, unknown>;
55
- /** Name of a connections[] entry supplying this source's credentials. */
56
- connection?: string;
57
- /** Maps the event to one engine call: start a process OR publish a message (ADR 0025 §1). */
58
- action?: {
59
- /** Process id/name to start. */
60
- start?: string;
61
- /** messageName to publish as a CorrelateMessage. */
62
- message?: string;
63
- /** correlationKey (literal, or `= body.path`) for a message action. */
64
- correlationKey?: string;
65
- /**
66
- * Variables for the started instance / published message. Per the manifest schema
67
- * (`#/$defs/triggerAction.variables`) this is a FEEL string over the event body
68
- * (e.g. `= body.payload`); an inline object literal is also accepted for convenience.
69
- */
70
- variables?: string | Record<string, unknown>;
71
- };
72
- }
73
- export interface SurfaceDecl {
74
- enabled?: boolean;
75
- path?: string;
76
- agent?: string;
77
- /** pages surface: directory of `*.page.json` (relative to app root). Default `pages`. */
78
- pagesDir?: string;
79
- /** pages surface: the page served at `/`. Default `home`. */
80
- homePage?: string;
81
- /** pages surface: max rows a `dataGrid` fetch returns. Default 200. */
82
- rowLimit?: number;
83
- /** pages surface: the injected default datasource name. Default `app`. */
84
- sourceName?: string;
85
- }
86
- /**
87
- * An app-authored action handler override (ADR 0055 phase 3). Each declaration binds a
88
- * route to a handler module (default-exports an `ActionHandler`), letting an app wrap the
89
- * generic pages start/cancel/message actions with business logic. Mounted before the
90
- * generic pages action routes, so an exact override shadows the generic one.
91
- */
92
- export interface ActionDecl {
93
- /** Route path to serve, e.g. "/app/actions/cancel" or "/app/actions/start/convergence-loop". */
94
- path: string;
95
- /** Handler module path relative to the app root; default-exports an `ActionHandler`. */
96
- module: string;
97
- /** HTTP method to match. Default "POST". */
98
- method?: string;
99
- /** Match `path` as a prefix rather than exactly. Default false. */
100
- prefix?: boolean;
101
- }
102
- export interface AppManifest {
103
- $schema?: string;
104
- schemaVersion: 1;
105
- id: string;
106
- name: string;
107
- codename?: string;
108
- runtime?: {
109
- engine?: string;
110
- node?: string;
111
- };
112
- models?: {
113
- processes?: string[];
114
- decisions?: string[];
115
- forms?: string[];
116
- };
117
- data?: {
118
- default?: string;
119
- sources?: Record<string, DataSource>;
120
- };
121
- types?: Record<string, DomainType>;
122
- triggers?: TriggerDecl[];
123
- connections?: Record<string, {
124
- type: string;
125
- [k: string]: unknown;
126
- }>;
127
- surfaces?: Record<string, SurfaceDecl>;
128
- actions?: ActionDecl[];
129
- workers?: WorkerDecl[];
130
- llm?: Record<string, LlmBinding>;
131
- security?: Record<string, unknown>;
132
- [k: string]: unknown;
133
- }
134
- /** The normalised job type for a worker declaration (`taskType` preferred, `type` fallback). */
135
- export declare function workerJobType(w: WorkerDecl): string | undefined;
2
+ import type { AppManifest, Worker } from "@nanobpm/nano-app-schema";
3
+ export type { ActionDecl, AppManifest, ChatSurface, Connection, Data, DataSource, DomainField, DomainType, LlmBinding, Models, PagesSurface, Runtime, Security, Surfaces, TaskInboxSurface, Trigger, TriggerAction, Worker, } from "@nanobpm/nano-app-schema";
4
+ /** The job type a worker subscribes to (schema key: `taskType`). */
5
+ export declare function workerJobType(w: Worker): string | undefined;
136
6
  /**
137
7
  * Expand `${VAR}` and `${VAR:-default}` placeholders in a string using `lookup`.
138
8
  * Unset vars with no default expand to "" (matching common shell semantics).
@@ -1,10 +1,15 @@
1
- // Manifest types (a hand-mirrored subset of nano-app.schema.json — the block shapes the
2
- // runtime actually consumes) plus env-placeholder expansion and a host-driven loader.
3
- // The schema itself (src/schema/nano-app.schema.json) remains the source of truth for
4
- // validation; see validate.ts.
5
- /** The normalised job type for a worker declaration (`taskType` preferred, `type` fallback). */
1
+ // Manifest types + env-placeholder expansion + a host-driven loader.
2
+ //
3
+ // The App manifest contract (nano.app.json) is owned by the canonical
4
+ // @nanobpm/nano-app-schema package (ADR 0027): the JSON Schema and its generated
5
+ // TypeScript types are the single source of truth. This module re-exports those
6
+ // types (type-only, so nothing from the package is pulled into the runtime
7
+ // bundle) and adds the runtime-side helpers the App loader needs. No shape is
8
+ // hand-mirrored here — that eliminated the schema/type drift the vendored copies
9
+ // used to cause.
10
+ /** The job type a worker subscribes to (schema key: `taskType`). */
6
11
  export function workerJobType(w) {
7
- return w.taskType ?? w.type;
12
+ return w.taskType;
8
13
  }
9
14
  const ENV_RE = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
10
15
  /**
@@ -1,6 +1,5 @@
1
1
  import type { AppApi, Mounted, RuntimeContext } from "../context.ts";
2
2
  import { type Route } from "../router.ts";
3
- import type { TriggerDecl } from "../manifest.ts";
4
3
  export interface TriggersHandle extends Mounted {
5
4
  routes: Route[];
6
5
  }
@@ -38,7 +37,20 @@ export declare function resolveActionVariables(expr: unknown, scope: Scope): Rec
38
37
  * of `correlationKey`/`variables`; cron passes a minimal `{ firedAt }` body. Returns what
39
38
  * was done.
40
39
  */
41
- export declare function runTriggerAction(app: AppApi, action: TriggerDecl["action"], scope: Scope): Promise<{
40
+ /**
41
+ * The trigger action as the *runtime* helper reads it: the fields `runTriggerAction`
42
+ * consumes, with `variables` permitting an inline object literal as well as a FEEL string.
43
+ * The manifest surface keeps `variables` string-only (a FEEL expression);
44
+ * `resolveActionVariables` tolerates both, so this shape matches runtime behaviour without
45
+ * loosening the schema. A locked `Trigger["action"]` is assignable to it.
46
+ */
47
+ export interface RuntimeTriggerAction {
48
+ start?: string;
49
+ message?: string;
50
+ correlationKey?: string;
51
+ variables?: string | Record<string, unknown>;
52
+ }
53
+ export declare function runTriggerAction(app: AppApi, action: RuntimeTriggerAction | undefined, scope: Scope): Promise<{
42
54
  kind: "start" | "message" | "none";
43
55
  target?: string;
44
56
  correlationKey?: string;
@@ -75,12 +75,6 @@ function headerRecord(req) {
75
75
  req.headers.forEach((v, k) => (out[k.toLowerCase()] = v));
76
76
  return out;
77
77
  }
78
- /**
79
- * Fire a trigger's action against the engine: start a process or publish a message
80
- * (ADR 0025 §1). `scope` supplies the event body/headers/query for FEEL-ish resolution
81
- * of `correlationKey`/`variables`; cron passes a minimal `{ firedAt }` body. Returns what
82
- * was done.
83
- */
84
78
  export async function runTriggerAction(app, action, scope) {
85
79
  if (!action)
86
80
  return { kind: "none" };
@@ -1,12 +1,13 @@
1
- // Manifest validation. We deliberately avoid a heavyweight JSON-Schema engine here to
2
- // keep core dependency-free and runtime-agnostic. Instead we drive validation *from* the
3
- // vendored nano-app.schema.json (the ADR 0027 source of truth) for the top-level envelope
4
- // — required keys, allowed keys (additionalProperties:false), the schemaVersion const, and
5
- // the id slug pattern — and then layer the runtime's binding rules (a worker needs a
6
- // handler, a data source needs driver+url, a typed table needs fields, a trigger needs
7
- // id+type). Reading the schema means the envelope check tracks the schema and can't drift
8
- // from it silently.
9
- import schema from "../schema/nano-app.schema.json" with { type: "json" };
1
+ // Manifest validation. We deliberately avoid a heavyweight JSON-Schema engine here to keep
2
+ // core lean and runtime-agnostic. Instead we drive validation *from* the canonical
3
+ // nano-app.schema.json (the ADR 0027 source of truth, imported from the
4
+ // @nanobpm/nano-app-schema package) for the top-level envelope — required keys, allowed keys
5
+ // (additionalProperties:false), the schemaVersion const, and the id slug pattern — and then
6
+ // layer the runtime's binding rules (a worker needs a handler, a data source needs
7
+ // driver+url, a typed table needs fields, a trigger needs id+type). Importing the shared
8
+ // schema JSON means the envelope check tracks the published schema and can't drift from it
9
+ // silently — the whole point of consuming the package rather than vendoring a copy.
10
+ import schema from "@nanobpm/nano-app-schema/schema" with { type: "json" };
10
11
  import { workerJobType } from "./manifest.js";
11
12
  export class ManifestValidationError extends Error {
12
13
  issues;
@@ -53,7 +54,7 @@ export function collectManifestIssues(m) {
53
54
  if (Array.isArray(man.workers)) {
54
55
  man.workers.forEach((w, i) => {
55
56
  if (!workerJobType(w)) {
56
- issues.push({ path: `workers[${i}]`, message: "missing taskType/type" });
57
+ issues.push({ path: `workers[${i}]`, message: "missing taskType" });
57
58
  }
58
59
  // The schema allows a worker backed by either a `handler` file or an `llm`
59
60
  // binding (oneOf). Require exactly one — don't force `handler`.
@@ -1,7 +1,7 @@
1
1
  export { createUrbanApp } from "./core/runtime.ts";
2
2
  export type { CreateUrbanAppOptions, MountFlags, UrbanApp, } from "./core/runtime.ts";
3
3
  export { expandEnv, expandEnvString, loadManifest, parseManifest, workerJobType, } from "./core/manifest.ts";
4
- export type { ActionDecl, AppManifest, DataSource, DomainType, LlmBinding, SurfaceDecl, TriggerDecl, TypeField, WorkerDecl, } from "./core/manifest.ts";
4
+ export type { ActionDecl, AppManifest, ChatSurface, DataSource, DomainField, DomainType, LlmBinding, PagesSurface, Surfaces, TaskInboxSurface, Trigger, Worker, } from "./core/manifest.ts";
5
5
  export { collectManifestIssues, ManifestValidationError, validateManifest, } from "./core/validate.ts";
6
6
  export type { ValidationIssue } from "./core/validate.ts";
7
7
  export type { EngineClient, EngineJob, HostContext, HttpHandler, HttpRequest, HttpResponse, HttpServer, JobHandler, SqliteDb, WatchHandle, WorkerSubscription, } from "./core/host.ts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nanobpm/urban",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "description": "Urban: build and run code-first apps on Nano — runtime, derivation toolkit, and CLI in one. Author durable processes with @nanobpm/workflow (defineFlow), a typed datasource, forms, triggers and surfaces from a nano.app.json manifest, on Node or Deno.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -55,13 +55,14 @@
55
55
  "README.md"
56
56
  ],
57
57
  "scripts": {
58
- "build": "tsc -p tsconfig.build.json && node -e \"const fs=require('fs');fs.mkdirSync('dist/runtime/schema',{recursive:true});fs.copyFileSync('src/runtime/schema/nano-app.schema.json','dist/runtime/schema/nano-app.schema.json')\"",
58
+ "build": "tsc -p tsconfig.build.json",
59
59
  "prepack": "npm run build",
60
60
  "typecheck": "tsc --noEmit -p tsconfig.json",
61
61
  "test": "node --test --experimental-strip-types \"src/**/*.test.ts\"",
62
62
  "test:deno": "deno test -A --no-check src/"
63
63
  },
64
64
  "dependencies": {
65
+ "@nanobpm/nano-app-schema": "^0.1.0",
65
66
  "@nanobpm/nano-sdk": "^1.2.3",
66
67
  "@nanobpm/workflow": "^0.7.0",
67
68
  "bpmn-auto-layout": "^2.0.0-alpha.2",
@@ -24,8 +24,7 @@ test("parseManifest expands env in place", () => {
24
24
  assert.equal(m.name, "App");
25
25
  });
26
26
 
27
- test("workerJobType prefers taskType then type", () => {
27
+ test("workerJobType returns the taskType", () => {
28
28
  assert.equal(workerJobType({ taskType: "a", handler: "h" }), "a");
29
- assert.equal(workerJobType({ type: "b", handler: "h" }), "b");
30
- assert.equal(workerJobType({ handler: "h" }), undefined);
29
+ assert.equal(workerJobType({ taskType: "llm-job", llm: "gpt" }), "llm-job");
31
30
  });
@@ -1,139 +1,40 @@
1
- // Manifest types (a hand-mirrored subset of nano-app.schema.json — the block shapes the
2
- // runtime actually consumes) plus env-placeholder expansion and a host-driven loader.
3
- // The schema itself (src/schema/nano-app.schema.json) remains the source of truth for
4
- // validation; see validate.ts.
1
+ // Manifest types + env-placeholder expansion + a host-driven loader.
2
+ //
3
+ // The App manifest contract (nano.app.json) is owned by the canonical
4
+ // @nanobpm/nano-app-schema package (ADR 0027): the JSON Schema and its generated
5
+ // TypeScript types are the single source of truth. This module re-exports those
6
+ // types (type-only, so nothing from the package is pulled into the runtime
7
+ // bundle) and adds the runtime-side helpers the App loader needs. No shape is
8
+ // hand-mirrored here — that eliminated the schema/type drift the vendored copies
9
+ // used to cause.
5
10
 
6
11
  import type { HostContext } from "./host.ts";
7
-
8
- export interface DataSource {
9
- driver: string;
10
- url: string;
11
- migrations?: string;
12
- }
13
-
14
- export interface TypeField {
15
- type: string;
16
- optional?: boolean;
17
- }
18
-
19
- export interface DomainType {
20
- name?: string;
21
- table?: string;
22
- fields?: Record<string, TypeField>;
23
- }
24
-
25
- export interface WorkerDecl {
26
- /** Job/task type the worker subscribes to. Schema allows `taskType` or `type`. */
27
- taskType?: string;
28
- type?: string;
29
- /** Path to the handler module, relative to the app root. Mutually exclusive with `llm`. */
30
- handler?: string;
31
- /** Name of an `llm[]` binding used as the worker (LLM-as-worker). Mutually exclusive with `handler`. */
32
- llm?: string;
33
- }
34
-
35
- /**
36
- * One named LLM binding (`llm.<id>` in the manifest). A binding is usable as a worker
37
- * (LLM-as-worker, ADR 0022 §E role 1) or as a chat surface agent. `provider` selects how
38
- * the endpoint is resolved (`"env"` reads it from the environment); `model` is typically
39
- * an env template. When `output.decision` is set, the model's JSON reply is fed through
40
- * that DMN decision (the "rails") and the decision's output is returned instead.
41
- */
42
- export interface LlmBinding {
43
- /** Provider selector. `"env"` resolves an OpenAI-compatible endpoint from the environment. */
44
- provider: string;
45
- /** Model id, typically an env template (e.g. `${NANO_APP_LLM_MODEL}`). */
46
- model: string;
47
- /** Constrains the model's structured output — currently a DMN decision id (the rails). */
48
- output?: { decision?: string };
49
- /** Action-API tools the agent may call (chat-agent role; unused by the worker role). */
50
- tools?: string[];
51
- }
52
-
53
- export interface TriggerDecl {
54
- id: string;
55
- type: string;
56
- path?: string;
57
- auth?: string;
58
- /** cron: the 5-field crontab spec (UTC), e.g. "0 6 * * *". */
59
- spec?: string;
60
- /** cron catch-up policy for fires missed while the app was down. Default "skip". */
61
- onMissed?: "skip" | "once" | "all";
62
- /** Source-kind-specific settings (e.g. file `{ pollMs }`). */
63
- config?: Record<string, unknown>;
64
- /** Name of a connections[] entry supplying this source's credentials. */
65
- connection?: string;
66
- /** Maps the event to one engine call: start a process OR publish a message (ADR 0025 §1). */
67
- action?: {
68
- /** Process id/name to start. */
69
- start?: string;
70
- /** messageName to publish as a CorrelateMessage. */
71
- message?: string;
72
- /** correlationKey (literal, or `= body.path`) for a message action. */
73
- correlationKey?: string;
74
- /**
75
- * Variables for the started instance / published message. Per the manifest schema
76
- * (`#/$defs/triggerAction.variables`) this is a FEEL string over the event body
77
- * (e.g. `= body.payload`); an inline object literal is also accepted for convenience.
78
- */
79
- variables?: string | Record<string, unknown>;
80
- };
81
- }
82
-
83
- export interface SurfaceDecl {
84
- enabled?: boolean;
85
- path?: string;
86
- agent?: string;
87
- /** pages surface: directory of `*.page.json` (relative to app root). Default `pages`. */
88
- pagesDir?: string;
89
- /** pages surface: the page served at `/`. Default `home`. */
90
- homePage?: string;
91
- /** pages surface: max rows a `dataGrid` fetch returns. Default 200. */
92
- rowLimit?: number;
93
- /** pages surface: the injected default datasource name. Default `app`. */
94
- sourceName?: string;
95
- }
96
-
97
- /**
98
- * An app-authored action handler override (ADR 0055 phase 3). Each declaration binds a
99
- * route to a handler module (default-exports an `ActionHandler`), letting an app wrap the
100
- * generic pages start/cancel/message actions with business logic. Mounted before the
101
- * generic pages action routes, so an exact override shadows the generic one.
102
- */
103
- export interface ActionDecl {
104
- /** Route path to serve, e.g. "/app/actions/cancel" or "/app/actions/start/convergence-loop". */
105
- path: string;
106
- /** Handler module path relative to the app root; default-exports an `ActionHandler`. */
107
- module: string;
108
- /** HTTP method to match. Default "POST". */
109
- method?: string;
110
- /** Match `path` as a prefix rather than exactly. Default false. */
111
- prefix?: boolean;
112
- }
113
-
114
- export interface AppManifest {
115
- $schema?: string;
116
- schemaVersion: 1;
117
- id: string;
118
- name: string;
119
- codename?: string;
120
- runtime?: { engine?: string; node?: string };
121
- models?: { processes?: string[]; decisions?: string[]; forms?: string[] };
122
- data?: { default?: string; sources?: Record<string, DataSource> };
123
- types?: Record<string, DomainType>;
124
- triggers?: TriggerDecl[];
125
- connections?: Record<string, { type: string; [k: string]: unknown }>;
126
- surfaces?: Record<string, SurfaceDecl>;
127
- actions?: ActionDecl[];
128
- workers?: WorkerDecl[];
129
- llm?: Record<string, LlmBinding>;
130
- security?: Record<string, unknown>;
131
- [k: string]: unknown;
132
- }
133
-
134
- /** The normalised job type for a worker declaration (`taskType` preferred, `type` fallback). */
135
- export function workerJobType(w: WorkerDecl): string | undefined {
136
- return w.taskType ?? w.type;
12
+ import type { AppManifest, Worker } from "@nanobpm/nano-app-schema";
13
+
14
+ export type {
15
+ ActionDecl,
16
+ AppManifest,
17
+ ChatSurface,
18
+ Connection,
19
+ Data,
20
+ DataSource,
21
+ DomainField,
22
+ DomainType,
23
+ LlmBinding,
24
+ Models,
25
+ PagesSurface,
26
+ Runtime,
27
+ Security,
28
+ Surfaces,
29
+ TaskInboxSurface,
30
+ Trigger,
31
+ TriggerAction,
32
+ Worker,
33
+ } from "@nanobpm/nano-app-schema";
34
+
35
+ /** The job type a worker subscribes to (schema key: `taskType`). */
36
+ export function workerJobType(w: Worker): string | undefined {
37
+ return w.taskType;
137
38
  }
138
39
 
139
40
  const ENV_RE = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
@@ -2,7 +2,7 @@ import { test } from "node:test";
2
2
  import assert from "node:assert/strict";
3
3
  import type { AppApi, RuntimeContext } from "../context.ts";
4
4
  import type { HttpRequest } from "../host.ts";
5
- import type { TriggerDecl } from "../manifest.ts";
5
+ import type { Trigger } from "../manifest.ts";
6
6
  import { makeRouter } from "../router.ts";
7
7
  import { evalCorrelation, mountTriggers, runTriggerAction, type SchedulerDeps } from "./triggers.ts";
8
8
 
@@ -33,7 +33,7 @@ function fakeApp(): { app: AppApi; calls: EngineCall[]; logs: Array<{ level: str
33
33
  return { app, calls, logs };
34
34
  }
35
35
 
36
- function fakeCtx(triggers: TriggerDecl[]): { ctx: RuntimeContext; hostLogs: Array<{ level: string; msg: string }> } {
36
+ function fakeCtx(triggers: Trigger[]): { ctx: RuntimeContext; hostLogs: Array<{ level: string; msg: string }> } {
37
37
  const hostLogs: Array<{ level: string; msg: string }> = [];
38
38
  const ctx = {
39
39
  root: "/app",
@@ -113,6 +113,8 @@ test("evalCorrelation returns undefined for a non-scalar result", () => {
113
113
 
114
114
  test("runTriggerAction starts a process with action.variables", async () => {
115
115
  const { app, calls } = fakeApp();
116
+ // The manifest surface types `variables` as a FEEL string; the runtime helper
117
+ // (runTriggerAction/resolveActionVariables) also accepts an inline object literal.
116
118
  const res = await runTriggerAction(app, { start: "proc-1", variables: { a: 1 } }, {
117
119
  body: { ignored: true },
118
120
  headers: {},
@@ -207,7 +209,7 @@ test("cron trigger with an invalid spec logs an error and does not schedule", ()
207
209
 
208
210
  test("cron trigger with no actionable action is not scheduled", () => {
209
211
  const { app, logs } = fakeApp();
210
- const { ctx } = fakeCtx([{ id: "noop", type: "cron", spec: "0 6 * * *" }]);
212
+ const { ctx } = fakeCtx([{ id: "noop", type: "cron", spec: "0 6 * * *", action: {} }]);
211
213
  const sched = fakeScheduler(0);
212
214
  const handle = mountTriggers(ctx, app, sched);
213
215
  assert.equal(sched.pending(), 0);
@@ -6,7 +6,7 @@
6
6
  import type { AppApi, Mounted, RuntimeContext } from "../context.ts";
7
7
  import type { HttpRequest } from "../host.ts";
8
8
  import { json, normalizeRoutePath, type Route } from "../router.ts";
9
- import type { TriggerDecl } from "../manifest.ts";
9
+ import type { Trigger } from "../manifest.ts";
10
10
  import { nextCronFire, parseCron } from "./cron.ts";
11
11
 
12
12
  export interface TriggersHandle extends Mounted {
@@ -112,9 +112,23 @@ function headerRecord(req: HttpRequest): Record<string, string> {
112
112
  * of `correlationKey`/`variables`; cron passes a minimal `{ firedAt }` body. Returns what
113
113
  * was done.
114
114
  */
115
+ /**
116
+ * The trigger action as the *runtime* helper reads it: the fields `runTriggerAction`
117
+ * consumes, with `variables` permitting an inline object literal as well as a FEEL string.
118
+ * The manifest surface keeps `variables` string-only (a FEEL expression);
119
+ * `resolveActionVariables` tolerates both, so this shape matches runtime behaviour without
120
+ * loosening the schema. A locked `Trigger["action"]` is assignable to it.
121
+ */
122
+ export interface RuntimeTriggerAction {
123
+ start?: string;
124
+ message?: string;
125
+ correlationKey?: string;
126
+ variables?: string | Record<string, unknown>;
127
+ }
128
+
115
129
  export async function runTriggerAction(
116
130
  app: AppApi,
117
- action: TriggerDecl["action"],
131
+ action: RuntimeTriggerAction | undefined,
118
132
  scope: Scope,
119
133
  ): Promise<{ kind: "start" | "message" | "none"; target?: string; correlationKey?: string }> {
120
134
  if (!action) return { kind: "none" };
@@ -161,7 +175,7 @@ export function mountTriggers(
161
175
  let stopped = false;
162
176
 
163
177
  // Arm a cron trigger: compute the next UTC fire, sleep until it, fire the action, repeat.
164
- const armCron = (trig: TriggerDecl): void => {
178
+ const armCron = (trig: Trigger): void => {
165
179
  const spec = trig.spec;
166
180
  if (!spec) {
167
181
  ctx.host.log("warn", `trigger "${trig.id}": cron trigger has no spec, skipped`);
@@ -241,7 +255,7 @@ export function mountTriggers(
241
255
  arm();
242
256
  };
243
257
 
244
- for (const trig of (ctx.manifest.triggers ?? []) as TriggerDecl[]) {
258
+ for (const trig of (ctx.manifest.triggers ?? []) as Trigger[]) {
245
259
  if (trig.type === "cron") {
246
260
  armCron(trig);
247
261
  continue;
@@ -4,7 +4,7 @@
4
4
 
5
5
  import type { AppApi, Mounted, RuntimeContext } from "../context.ts";
6
6
  import type { EngineJob, JobHandler, WorkerSubscription } from "../host.ts";
7
- import { workerJobType, type WorkerDecl } from "../manifest.ts";
7
+ import { workerJobType, type Worker } from "../manifest.ts";
8
8
  import { type DecisionEvaluator, type LlmRuntime, runLlmJob } from "./llm.ts";
9
9
 
10
10
  /** The subset of the engine SDK the LLM decision-rails need: evaluate a DMN decision,
@@ -106,7 +106,7 @@ export async function mountWorkers(ctx: RuntimeContext, app: AppApi): Promise<Wo
106
106
  return mod;
107
107
  };
108
108
 
109
- for (const decl of decls as WorkerDecl[]) {
109
+ for (const decl of decls as Worker[]) {
110
110
  const jobType = workerJobType(decl);
111
111
  if (!jobType) continue;
112
112
  if (!decl.handler) {
@@ -1,13 +1,14 @@
1
- // Manifest validation. We deliberately avoid a heavyweight JSON-Schema engine here to
2
- // keep core dependency-free and runtime-agnostic. Instead we drive validation *from* the
3
- // vendored nano-app.schema.json (the ADR 0027 source of truth) for the top-level envelope
4
- // — required keys, allowed keys (additionalProperties:false), the schemaVersion const, and
5
- // the id slug pattern — and then layer the runtime's binding rules (a worker needs a
6
- // handler, a data source needs driver+url, a typed table needs fields, a trigger needs
7
- // id+type). Reading the schema means the envelope check tracks the schema and can't drift
8
- // from it silently.
1
+ // Manifest validation. We deliberately avoid a heavyweight JSON-Schema engine here to keep
2
+ // core lean and runtime-agnostic. Instead we drive validation *from* the canonical
3
+ // nano-app.schema.json (the ADR 0027 source of truth, imported from the
4
+ // @nanobpm/nano-app-schema package) for the top-level envelope — required keys, allowed keys
5
+ // (additionalProperties:false), the schemaVersion const, and the id slug pattern — and then
6
+ // layer the runtime's binding rules (a worker needs a handler, a data source needs
7
+ // driver+url, a typed table needs fields, a trigger needs id+type). Importing the shared
8
+ // schema JSON means the envelope check tracks the published schema and can't drift from it
9
+ // silently — the whole point of consuming the package rather than vendoring a copy.
9
10
 
10
- import schema from "../schema/nano-app.schema.json" with { type: "json" };
11
+ import schema from "@nanobpm/nano-app-schema/schema" with { type: "json" };
11
12
  import { workerJobType, type AppManifest } from "./manifest.ts";
12
13
 
13
14
  export interface ValidationIssue {
@@ -73,7 +74,7 @@ export function collectManifestIssues(m: unknown): ValidationIssue[] {
73
74
  if (Array.isArray(man.workers)) {
74
75
  man.workers.forEach((w, i) => {
75
76
  if (!workerJobType(w)) {
76
- issues.push({ path: `workers[${i}]`, message: "missing taskType/type" });
77
+ issues.push({ path: `workers[${i}]`, message: "missing taskType" });
77
78
  }
78
79
  // The schema allows a worker backed by either a `handler` file or an `llm`
79
80
  // binding (oneOf). Require exactly one — don't force `handler`.
@@ -19,13 +19,16 @@ export {
19
19
  export type {
20
20
  ActionDecl,
21
21
  AppManifest,
22
+ ChatSurface,
22
23
  DataSource,
24
+ DomainField,
23
25
  DomainType,
24
26
  LlmBinding,
25
- SurfaceDecl,
26
- TriggerDecl,
27
- TypeField,
28
- WorkerDecl,
27
+ PagesSurface,
28
+ Surfaces,
29
+ TaskInboxSurface,
30
+ Trigger,
31
+ Worker,
29
32
  } from "./core/manifest.ts";
30
33
 
31
34
  // Validation