@stackbone/sdk 0.1.0-alpha.5 → 0.1.0-alpha.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackbone/sdk",
3
- "version": "0.1.0-alpha.5",
3
+ "version": "0.1.0-alpha.7",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Official TypeScript SDK for Stackbone — the marketplace and managed runtime for containerized AI agents.",
6
6
  "type": "module",
@@ -28,6 +28,26 @@
28
28
  "default": "./db/index.cjs"
29
29
  }
30
30
  },
31
+ "./workflow": {
32
+ "import": {
33
+ "types": "./workflow.d.ts",
34
+ "default": "./workflow.js"
35
+ },
36
+ "require": {
37
+ "types": "./workflow.d.cts",
38
+ "default": "./workflow.cjs"
39
+ }
40
+ },
41
+ "./connect": {
42
+ "import": {
43
+ "types": "./connect.d.ts",
44
+ "default": "./connect.js"
45
+ },
46
+ "require": {
47
+ "types": "./connect.d.cts",
48
+ "default": "./connect.cjs"
49
+ }
50
+ },
31
51
  "./db/testing": {
32
52
  "import": {
33
53
  "types": "./db/testing/index.d.ts",
@@ -106,5 +126,17 @@
106
126
  "postgres": "3.4.9",
107
127
  "unpdf": "^0.12.1",
108
128
  "zod": "^4.3.6"
129
+ },
130
+ "peerDependencies": {
131
+ "eve": "*",
132
+ "workflow": "*"
133
+ },
134
+ "peerDependenciesMeta": {
135
+ "eve": {
136
+ "optional": true
137
+ },
138
+ "workflow": {
139
+ "optional": true
140
+ }
109
141
  }
110
142
  }
Binary file
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Augmentable registry of the workspace's eve agent NAMES. By default it is
3
+ * empty, so `eveAgent(name)` accepts any `string` (today's behavior, validated
4
+ * only at runtime against the injected `AGENT_URLS` map). `stackbone dev`
5
+ * generates an ambient `.stackbone/agents.d.ts` from the project's
6
+ * `stackbone.config.ts` agent list and augments this interface so the names
7
+ * become a closed set:
8
+ *
9
+ * declare module '@stackbone/sdk/workflow' {
10
+ * interface AgentRegistry {
11
+ * support: true;
12
+ * 'lead-qualifier': true;
13
+ * }
14
+ * }
15
+ *
16
+ * Once augmented, `eveAgent('lead-qualifier')` is fine and `eveAgent('typo')` is
17
+ * a compile error — the editor also autocompletes the declared names. Mirrors the
18
+ * `ConfigRegistry` augmentable-interface pattern used for `client.config`.
19
+ */
20
+ interface AgentRegistry {
21
+ }
22
+ /**
23
+ * The set of agent names `eveAgent` accepts, derived from the augmentable
24
+ * `AgentRegistry`. The tuple wrap (`[X] extends [never]`) defeats the
25
+ * conditional-type distributivity a bare `keyof AgentRegistry extends never`
26
+ * would trigger:
27
+ *
28
+ * - empty registry -> `string` (today's loose behavior: any name, checked at
29
+ * runtime when the workflow resolves it against `AGENT_URLS`);
30
+ * - augmented registry -> the union of declared agent names (typo = compile error).
31
+ */
32
+ type AgentName = [keyof AgentRegistry] extends [never] ? string : keyof AgentRegistry;
33
+
34
+ /**
35
+ * Queue-level options for a workflow trigger.
36
+ *
37
+ * NOTE: `delaySeconds` and `idempotencyKey` are typed for forward-compatibility
38
+ * but NOT wired in v1. The native WDK `start()` primitive (the sanctioned
39
+ * trigger path) does not expose queue-level delay or dedup — those live one
40
+ * layer down on the World's raw producer, and reaching it means re-implementing
41
+ * run creation against `@workflow/core` internals. Deferred to a follow-up when
42
+ * the WDK exposes them. Within-run idempotency already comes from `"use step"`
43
+ * memoization, so a step replay never double-enqueues.
44
+ */
45
+ interface WorkflowTriggerOptions {
46
+ /** Defer the triggered start by N seconds. Reserved — not wired in v1. */
47
+ readonly delaySeconds?: number;
48
+ /** Dedup key so a retry does not start the target twice. Reserved — not wired in v1. */
49
+ readonly idempotencyKey?: string;
50
+ }
51
+ /** What a fire-and-forget trigger resolves to: the started child run's id. */
52
+ interface WorkflowStartHandle {
53
+ /** The independent run id of the workflow that was started. */
54
+ readonly runId: string;
55
+ }
56
+ /**
57
+ * The runtime-injected bridge the trigger helpers reach. Built by the runtime on
58
+ * first dispatch (closing over the name→ref registry, the validators, the WDK
59
+ * `start` primitive, and the run projection) and planted with
60
+ * {@link setWorkflowStarter}.
61
+ */
62
+ interface WorkflowStarter {
63
+ /**
64
+ * Fire-and-forget: resolve `name`, validate `input`, enqueue the start on the
65
+ * `flows` queue, and resolve with the new independent run's id. Does NOT wait
66
+ * for the started workflow to finish.
67
+ */
68
+ start(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<WorkflowStartHandle>;
69
+ /**
70
+ * Durable sub-workflow: resolve `name`, validate `input`, start the run, then
71
+ * suspend until it reaches a terminal state and resolve with its terminal
72
+ * output (validated against the target's declared output schema). Backed by the
73
+ * WDK's native `Run.returnValue` poll-until-terminal primitive.
74
+ */
75
+ startAndWait(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<unknown>;
76
+ }
77
+ /**
78
+ * Plant (or clear, with `undefined`) the ambient starter. The runtime calls this
79
+ * on first dispatch with the bridge it built; tests pass a fake. Idempotent —
80
+ * the last write wins.
81
+ */
82
+ declare function setWorkflowStarter(starter: WorkflowStarter | undefined): void;
83
+ /**
84
+ * Return the bound ambient starter, or throw a clear error when none is bound —
85
+ * which means a trigger helper was called OUTSIDE a running workflow (the
86
+ * runtime binds the starter only on first dispatch).
87
+ */
88
+ declare function getWorkflowStarter(): WorkflowStarter;
89
+
90
+ /** One active scheduled trigger, as `listSchedules()` reports it. */
91
+ interface ScheduledWorkflow {
92
+ /** The workflow this trigger starts on each tick. */
93
+ readonly name: string;
94
+ /** The cron expression driving the cadence. */
95
+ readonly cron: string;
96
+ /** The input each tick passes to the workflow. */
97
+ readonly input: unknown;
98
+ /** `'declarative'` (harvested from the workflow, reconciled on boot) or
99
+ * `'dynamic'` (registered at run time via `scheduleWorkflow`). */
100
+ readonly source: 'declarative' | 'dynamic';
101
+ }
102
+ /** The runtime-injected bridge the imperative cron helpers reach. */
103
+ interface WorkflowScheduler {
104
+ /** Register (or upsert) a DYNAMIC repeatable trigger that starts `name` with
105
+ * `input` on the `cron` cadence. Idempotent by `name`. */
106
+ schedule(name: string, input: unknown, cron: string): Promise<void>;
107
+ /** Cancel a dynamic trigger by `name`. Resolves whether or not one existed. */
108
+ unschedule(name: string): Promise<void>;
109
+ /** List the active triggers — declarative + dynamic. */
110
+ listSchedules(): Promise<ScheduledWorkflow[]>;
111
+ }
112
+ /** Plant (or clear, with `undefined`) the ambient scheduler. The runtime calls
113
+ * this on first dispatch; tests pass a fake. Last write wins. */
114
+ declare function setWorkflowScheduler(scheduler: WorkflowScheduler | undefined): void;
115
+ /** Return the bound ambient scheduler, or throw a clear error when none is bound
116
+ * (the imperative cron API was reached outside a running workflow runtime). */
117
+ declare function getWorkflowScheduler(): WorkflowScheduler;
118
+
119
+ export { type AgentName as A, type ScheduledWorkflow as S, type WorkflowTriggerOptions as W, type WorkflowStartHandle as a, type AgentRegistry as b, type WorkflowScheduler as c, type WorkflowStarter as d, getWorkflowStarter as e, setWorkflowStarter as f, getWorkflowScheduler as g, setWorkflowScheduler as s };
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Augmentable registry of the workspace's eve agent NAMES. By default it is
3
+ * empty, so `eveAgent(name)` accepts any `string` (today's behavior, validated
4
+ * only at runtime against the injected `AGENT_URLS` map). `stackbone dev`
5
+ * generates an ambient `.stackbone/agents.d.ts` from the project's
6
+ * `stackbone.config.ts` agent list and augments this interface so the names
7
+ * become a closed set:
8
+ *
9
+ * declare module '@stackbone/sdk/workflow' {
10
+ * interface AgentRegistry {
11
+ * support: true;
12
+ * 'lead-qualifier': true;
13
+ * }
14
+ * }
15
+ *
16
+ * Once augmented, `eveAgent('lead-qualifier')` is fine and `eveAgent('typo')` is
17
+ * a compile error — the editor also autocompletes the declared names. Mirrors the
18
+ * `ConfigRegistry` augmentable-interface pattern used for `client.config`.
19
+ */
20
+ interface AgentRegistry {
21
+ }
22
+ /**
23
+ * The set of agent names `eveAgent` accepts, derived from the augmentable
24
+ * `AgentRegistry`. The tuple wrap (`[X] extends [never]`) defeats the
25
+ * conditional-type distributivity a bare `keyof AgentRegistry extends never`
26
+ * would trigger:
27
+ *
28
+ * - empty registry -> `string` (today's loose behavior: any name, checked at
29
+ * runtime when the workflow resolves it against `AGENT_URLS`);
30
+ * - augmented registry -> the union of declared agent names (typo = compile error).
31
+ */
32
+ type AgentName = [keyof AgentRegistry] extends [never] ? string : keyof AgentRegistry;
33
+
34
+ /**
35
+ * Queue-level options for a workflow trigger.
36
+ *
37
+ * NOTE: `delaySeconds` and `idempotencyKey` are typed for forward-compatibility
38
+ * but NOT wired in v1. The native WDK `start()` primitive (the sanctioned
39
+ * trigger path) does not expose queue-level delay or dedup — those live one
40
+ * layer down on the World's raw producer, and reaching it means re-implementing
41
+ * run creation against `@workflow/core` internals. Deferred to a follow-up when
42
+ * the WDK exposes them. Within-run idempotency already comes from `"use step"`
43
+ * memoization, so a step replay never double-enqueues.
44
+ */
45
+ interface WorkflowTriggerOptions {
46
+ /** Defer the triggered start by N seconds. Reserved — not wired in v1. */
47
+ readonly delaySeconds?: number;
48
+ /** Dedup key so a retry does not start the target twice. Reserved — not wired in v1. */
49
+ readonly idempotencyKey?: string;
50
+ }
51
+ /** What a fire-and-forget trigger resolves to: the started child run's id. */
52
+ interface WorkflowStartHandle {
53
+ /** The independent run id of the workflow that was started. */
54
+ readonly runId: string;
55
+ }
56
+ /**
57
+ * The runtime-injected bridge the trigger helpers reach. Built by the runtime on
58
+ * first dispatch (closing over the name→ref registry, the validators, the WDK
59
+ * `start` primitive, and the run projection) and planted with
60
+ * {@link setWorkflowStarter}.
61
+ */
62
+ interface WorkflowStarter {
63
+ /**
64
+ * Fire-and-forget: resolve `name`, validate `input`, enqueue the start on the
65
+ * `flows` queue, and resolve with the new independent run's id. Does NOT wait
66
+ * for the started workflow to finish.
67
+ */
68
+ start(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<WorkflowStartHandle>;
69
+ /**
70
+ * Durable sub-workflow: resolve `name`, validate `input`, start the run, then
71
+ * suspend until it reaches a terminal state and resolve with its terminal
72
+ * output (validated against the target's declared output schema). Backed by the
73
+ * WDK's native `Run.returnValue` poll-until-terminal primitive.
74
+ */
75
+ startAndWait(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<unknown>;
76
+ }
77
+ /**
78
+ * Plant (or clear, with `undefined`) the ambient starter. The runtime calls this
79
+ * on first dispatch with the bridge it built; tests pass a fake. Idempotent —
80
+ * the last write wins.
81
+ */
82
+ declare function setWorkflowStarter(starter: WorkflowStarter | undefined): void;
83
+ /**
84
+ * Return the bound ambient starter, or throw a clear error when none is bound —
85
+ * which means a trigger helper was called OUTSIDE a running workflow (the
86
+ * runtime binds the starter only on first dispatch).
87
+ */
88
+ declare function getWorkflowStarter(): WorkflowStarter;
89
+
90
+ /** One active scheduled trigger, as `listSchedules()` reports it. */
91
+ interface ScheduledWorkflow {
92
+ /** The workflow this trigger starts on each tick. */
93
+ readonly name: string;
94
+ /** The cron expression driving the cadence. */
95
+ readonly cron: string;
96
+ /** The input each tick passes to the workflow. */
97
+ readonly input: unknown;
98
+ /** `'declarative'` (harvested from the workflow, reconciled on boot) or
99
+ * `'dynamic'` (registered at run time via `scheduleWorkflow`). */
100
+ readonly source: 'declarative' | 'dynamic';
101
+ }
102
+ /** The runtime-injected bridge the imperative cron helpers reach. */
103
+ interface WorkflowScheduler {
104
+ /** Register (or upsert) a DYNAMIC repeatable trigger that starts `name` with
105
+ * `input` on the `cron` cadence. Idempotent by `name`. */
106
+ schedule(name: string, input: unknown, cron: string): Promise<void>;
107
+ /** Cancel a dynamic trigger by `name`. Resolves whether or not one existed. */
108
+ unschedule(name: string): Promise<void>;
109
+ /** List the active triggers — declarative + dynamic. */
110
+ listSchedules(): Promise<ScheduledWorkflow[]>;
111
+ }
112
+ /** Plant (or clear, with `undefined`) the ambient scheduler. The runtime calls
113
+ * this on first dispatch; tests pass a fake. Last write wins. */
114
+ declare function setWorkflowScheduler(scheduler: WorkflowScheduler | undefined): void;
115
+ /** Return the bound ambient scheduler, or throw a clear error when none is bound
116
+ * (the imperative cron API was reached outside a running workflow runtime). */
117
+ declare function getWorkflowScheduler(): WorkflowScheduler;
118
+
119
+ export { type AgentName as A, type ScheduledWorkflow as S, type WorkflowTriggerOptions as W, type WorkflowStartHandle as a, type AgentRegistry as b, type WorkflowScheduler as c, type WorkflowStarter as d, getWorkflowStarter as e, setWorkflowStarter as f, getWorkflowScheduler as g, setWorkflowScheduler as s };