@stackbone/sdk 0.1.0-alpha.6 → 0.1.0-alpha.8

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,198 @@
1
+ /** One active scheduled trigger, as `listSchedules()` reports it. */
2
+ interface ScheduledWorkflow {
3
+ /** The workflow this trigger starts on each tick. */
4
+ readonly name: string;
5
+ /** The cron expression driving the cadence. */
6
+ readonly cron: string;
7
+ /** The input each tick passes to the workflow. */
8
+ readonly input: unknown;
9
+ /** `'declarative'` (harvested from the workflow, reconciled on boot) or
10
+ * `'dynamic'` (registered at run time via `scheduleWorkflow`). */
11
+ readonly source: 'declarative' | 'dynamic';
12
+ }
13
+ /** The runtime-injected bridge the imperative cron helpers reach. */
14
+ interface WorkflowScheduler {
15
+ /** Register (or upsert) a DYNAMIC repeatable trigger that starts `name` with
16
+ * `input` on the `cron` cadence. Idempotent by `name`. */
17
+ schedule(name: string, input: unknown, cron: string): Promise<void>;
18
+ /** Cancel a dynamic trigger by `name`. Resolves whether or not one existed. */
19
+ unschedule(name: string): Promise<void>;
20
+ /** List the active triggers — declarative + dynamic. */
21
+ listSchedules(): Promise<ScheduledWorkflow[]>;
22
+ }
23
+ /** Plant (or clear, with `undefined`) the ambient scheduler. The runtime calls
24
+ * this on first dispatch; tests pass a fake. Last write wins. */
25
+ declare function setWorkflowScheduler(scheduler: WorkflowScheduler | undefined): void;
26
+ /** Return the bound ambient scheduler, or throw a clear error when none is bound
27
+ * (the imperative cron API was reached outside a running workflow runtime). */
28
+ declare function getWorkflowScheduler(): WorkflowScheduler;
29
+
30
+ /**
31
+ * Queue-level options for a workflow trigger.
32
+ *
33
+ * NOTE: `delaySeconds` and `idempotencyKey` are typed for forward-compatibility
34
+ * but NOT wired in v1. The native WDK `start()` primitive (the sanctioned
35
+ * trigger path) does not expose queue-level delay or dedup — those live one
36
+ * layer down on the World's raw producer, and reaching it means re-implementing
37
+ * run creation against `@workflow/core` internals. Deferred to a follow-up when
38
+ * the WDK exposes them. Within-run idempotency already comes from `"use step"`
39
+ * memoization, so a step replay never double-enqueues.
40
+ */
41
+ interface WorkflowTriggerOptions {
42
+ /** Defer the triggered start by N seconds. Reserved — not wired in v1. */
43
+ readonly delaySeconds?: number;
44
+ /** Dedup key so a retry does not start the target twice. Reserved — not wired in v1. */
45
+ readonly idempotencyKey?: string;
46
+ }
47
+ /** What a fire-and-forget trigger resolves to: the started child run's id. */
48
+ interface WorkflowStartHandle {
49
+ /** The independent run id of the workflow that was started. */
50
+ readonly runId: string;
51
+ }
52
+ /**
53
+ * The runtime-injected bridge the trigger helpers reach. Built by the runtime on
54
+ * first dispatch (closing over the name→ref registry, the validators, the WDK
55
+ * `start` primitive, and the run projection) and planted with
56
+ * {@link setWorkflowStarter}.
57
+ */
58
+ interface WorkflowStarter {
59
+ /**
60
+ * Fire-and-forget: resolve `name`, validate `input`, enqueue the start on the
61
+ * `flows` queue, and resolve with the new independent run's id. Does NOT wait
62
+ * for the started workflow to finish.
63
+ */
64
+ start(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<WorkflowStartHandle>;
65
+ /**
66
+ * Durable sub-workflow: resolve `name`, validate `input`, start the run, then
67
+ * suspend until it reaches a terminal state and resolve with its terminal
68
+ * output (validated against the target's declared output schema). Backed by the
69
+ * WDK's native `Run.returnValue` poll-until-terminal primitive.
70
+ */
71
+ startAndWait(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<unknown>;
72
+ }
73
+ /**
74
+ * Plant (or clear, with `undefined`) the ambient starter. The runtime calls this
75
+ * on first dispatch with the bridge it built; tests pass a fake. Idempotent —
76
+ * the last write wins.
77
+ */
78
+ declare function setWorkflowStarter(starter: WorkflowStarter | undefined): void;
79
+ /**
80
+ * Return the bound ambient starter, or throw a clear error when none is bound —
81
+ * which means a trigger helper was called OUTSIDE a running workflow (the
82
+ * runtime binds the starter only on first dispatch).
83
+ */
84
+ declare function getWorkflowStarter(): WorkflowStarter;
85
+
86
+ /**
87
+ * Augmentable registry of the workspace's WORKFLOW names. By default it is empty,
88
+ * so `startWorkflow(name, ...)` / `startWorkflowAndWait(name, ...)` accept any
89
+ * `string` (today's behavior, validated only at runtime against the injected
90
+ * name→ref registry). `stackbone dev` generates an ambient
91
+ * `.stackbone/workflows.d.ts` from the project's `stackbone.config.ts` workflow
92
+ * list and augments this interface so the names become a closed set:
93
+ *
94
+ * declare module '@stackbone/sdk/workflow' {
95
+ * interface WorkflowRegistry {
96
+ * onboarding: true;
97
+ * qualifyLead: true;
98
+ * }
99
+ * }
100
+ *
101
+ * Once augmented, `startWorkflow('qualifyLead', ...)` is fine and
102
+ * `startWorkflow('typo', ...)` is a compile error — the editor also autocompletes
103
+ * the declared names. Mirrors the `AgentRegistry` augmentable-interface pattern
104
+ * used for `eveAgent`.
105
+ */
106
+ interface WorkflowRegistry {
107
+ }
108
+ /**
109
+ * The set of workflow names the trigger helpers accept, derived from the
110
+ * augmentable `WorkflowRegistry`. The tuple wrap (`[X] extends [never]`) defeats
111
+ * the conditional-type distributivity a bare `keyof WorkflowRegistry extends
112
+ * never` would trigger:
113
+ *
114
+ * - empty registry -> `string` (today's loose behavior: any name, checked at
115
+ * runtime when the workflow resolves it against the manifest);
116
+ * - augmented registry -> the union of declared workflow names (typo = compile error).
117
+ */
118
+ type WorkflowName = [keyof WorkflowRegistry] extends [never] ? string : keyof WorkflowRegistry;
119
+
120
+ /** Options for {@link startWorkflow}. See {@link WorkflowTriggerOptions}. */
121
+ type StartWorkflowOptions = WorkflowTriggerOptions;
122
+
123
+ /**
124
+ * Start the workflow named `name` with its own independent run and return its
125
+ * `{ runId }` immediately — fire-and-forget. The input is validated against the
126
+ * target's declared input schema BEFORE the run is enqueued; a name that does
127
+ * not resolve, or input that violates the schema, rejects without starting
128
+ * anything.
129
+ *
130
+ * `name` is typed `WorkflowName` — a loose `string` by default, narrowed to the
131
+ * workspace's declared workflow names once `stackbone dev` has generated
132
+ * `.stackbone/workflows.d.ts` (see `workflow-registry.ts`), so a typo becomes a
133
+ * compile error.
134
+ *
135
+ * MUST be called from inside a running workflow (the runtime binds the starter on
136
+ * first dispatch); calling it elsewhere throws.
137
+ *
138
+ * DURABILITY: the enqueue runs in a `"use step"`, so once it completes a parent
139
+ * restart resumes with the memoized `{ runId }` and does NOT re-enqueue. A crash
140
+ * WHILE the step is mid-flight re-runs it (at-least-once) — the same shape the
141
+ * eve-agent-from-step path has; for fire-and-forget fan-out this is acceptable.
142
+ * Use {@link startWorkflowAndWait} when you need the child's result.
143
+ */
144
+ declare function startWorkflow(name: WorkflowName, input: unknown, opts?: StartWorkflowOptions): Promise<WorkflowStartHandle>;
145
+
146
+ /** Options for {@link startWorkflowAndWait}. See {@link WorkflowTriggerOptions}. */
147
+ type StartWorkflowAndWaitOptions = WorkflowTriggerOptions;
148
+ /**
149
+ * Start the workflow named `name` with its own independent run and durably wait
150
+ * for it to finish, returning its terminal output (validated against the
151
+ * target's declared output schema). Use this when one workflow needs another's
152
+ * result to continue.
153
+ *
154
+ * The input is validated against the target's declared input schema BEFORE the
155
+ * run is enqueued; a name that does not resolve, or input that violates the
156
+ * schema, rejects without starting anything. `TOutput` lets the caller name the
157
+ * expected output shape (defaults to `unknown`).
158
+ *
159
+ * `name` is typed `WorkflowName` — narrowed to the workspace's declared workflow
160
+ * names once `stackbone dev` has generated `.stackbone/workflows.d.ts`. MUST be
161
+ * called from inside a running workflow.
162
+ */
163
+ declare function startWorkflowAndWait<TOutput = unknown>(name: WorkflowName, input: unknown, opts?: StartWorkflowAndWaitOptions): Promise<TOutput>;
164
+
165
+ /**
166
+ * Augmentable registry of the workspace's eve agent NAMES. By default it is
167
+ * empty, so `eveAgent(name)` accepts any `string` (today's behavior, validated
168
+ * only at runtime against the injected `AGENT_URLS` map). `stackbone dev`
169
+ * generates an ambient `.stackbone/agents.d.ts` from the project's
170
+ * `stackbone.config.ts` agent list and augments this interface so the names
171
+ * become a closed set:
172
+ *
173
+ * declare module '@stackbone/sdk/workflow' {
174
+ * interface AgentRegistry {
175
+ * support: true;
176
+ * 'lead-qualifier': true;
177
+ * }
178
+ * }
179
+ *
180
+ * Once augmented, `eveAgent('lead-qualifier')` is fine and `eveAgent('typo')` is
181
+ * a compile error — the editor also autocompletes the declared names. Mirrors the
182
+ * `ConfigRegistry` augmentable-interface pattern used for `client.config`.
183
+ */
184
+ interface AgentRegistry {
185
+ }
186
+ /**
187
+ * The set of agent names `eveAgent` accepts, derived from the augmentable
188
+ * `AgentRegistry`. The tuple wrap (`[X] extends [never]`) defeats the
189
+ * conditional-type distributivity a bare `keyof AgentRegistry extends never`
190
+ * would trigger:
191
+ *
192
+ * - empty registry -> `string` (today's loose behavior: any name, checked at
193
+ * runtime when the workflow resolves it against `AGENT_URLS`);
194
+ * - augmented registry -> the union of declared agent names (typo = compile error).
195
+ */
196
+ type AgentName = [keyof AgentRegistry] extends [never] ? string : keyof AgentRegistry;
197
+
198
+ export { type AgentName as A, type ScheduledWorkflow as S, type WorkflowName as W, type AgentRegistry as a, type StartWorkflowAndWaitOptions as b, type StartWorkflowOptions as c, type WorkflowRegistry as d, type WorkflowStartHandle as e, startWorkflowAndWait as f, type WorkflowScheduler as g, type WorkflowStarter as h, type WorkflowTriggerOptions as i, getWorkflowScheduler as j, getWorkflowStarter as k, setWorkflowScheduler as l, setWorkflowStarter as m, startWorkflow as s };
@@ -0,0 +1,198 @@
1
+ /** One active scheduled trigger, as `listSchedules()` reports it. */
2
+ interface ScheduledWorkflow {
3
+ /** The workflow this trigger starts on each tick. */
4
+ readonly name: string;
5
+ /** The cron expression driving the cadence. */
6
+ readonly cron: string;
7
+ /** The input each tick passes to the workflow. */
8
+ readonly input: unknown;
9
+ /** `'declarative'` (harvested from the workflow, reconciled on boot) or
10
+ * `'dynamic'` (registered at run time via `scheduleWorkflow`). */
11
+ readonly source: 'declarative' | 'dynamic';
12
+ }
13
+ /** The runtime-injected bridge the imperative cron helpers reach. */
14
+ interface WorkflowScheduler {
15
+ /** Register (or upsert) a DYNAMIC repeatable trigger that starts `name` with
16
+ * `input` on the `cron` cadence. Idempotent by `name`. */
17
+ schedule(name: string, input: unknown, cron: string): Promise<void>;
18
+ /** Cancel a dynamic trigger by `name`. Resolves whether or not one existed. */
19
+ unschedule(name: string): Promise<void>;
20
+ /** List the active triggers — declarative + dynamic. */
21
+ listSchedules(): Promise<ScheduledWorkflow[]>;
22
+ }
23
+ /** Plant (or clear, with `undefined`) the ambient scheduler. The runtime calls
24
+ * this on first dispatch; tests pass a fake. Last write wins. */
25
+ declare function setWorkflowScheduler(scheduler: WorkflowScheduler | undefined): void;
26
+ /** Return the bound ambient scheduler, or throw a clear error when none is bound
27
+ * (the imperative cron API was reached outside a running workflow runtime). */
28
+ declare function getWorkflowScheduler(): WorkflowScheduler;
29
+
30
+ /**
31
+ * Queue-level options for a workflow trigger.
32
+ *
33
+ * NOTE: `delaySeconds` and `idempotencyKey` are typed for forward-compatibility
34
+ * but NOT wired in v1. The native WDK `start()` primitive (the sanctioned
35
+ * trigger path) does not expose queue-level delay or dedup — those live one
36
+ * layer down on the World's raw producer, and reaching it means re-implementing
37
+ * run creation against `@workflow/core` internals. Deferred to a follow-up when
38
+ * the WDK exposes them. Within-run idempotency already comes from `"use step"`
39
+ * memoization, so a step replay never double-enqueues.
40
+ */
41
+ interface WorkflowTriggerOptions {
42
+ /** Defer the triggered start by N seconds. Reserved — not wired in v1. */
43
+ readonly delaySeconds?: number;
44
+ /** Dedup key so a retry does not start the target twice. Reserved — not wired in v1. */
45
+ readonly idempotencyKey?: string;
46
+ }
47
+ /** What a fire-and-forget trigger resolves to: the started child run's id. */
48
+ interface WorkflowStartHandle {
49
+ /** The independent run id of the workflow that was started. */
50
+ readonly runId: string;
51
+ }
52
+ /**
53
+ * The runtime-injected bridge the trigger helpers reach. Built by the runtime on
54
+ * first dispatch (closing over the name→ref registry, the validators, the WDK
55
+ * `start` primitive, and the run projection) and planted with
56
+ * {@link setWorkflowStarter}.
57
+ */
58
+ interface WorkflowStarter {
59
+ /**
60
+ * Fire-and-forget: resolve `name`, validate `input`, enqueue the start on the
61
+ * `flows` queue, and resolve with the new independent run's id. Does NOT wait
62
+ * for the started workflow to finish.
63
+ */
64
+ start(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<WorkflowStartHandle>;
65
+ /**
66
+ * Durable sub-workflow: resolve `name`, validate `input`, start the run, then
67
+ * suspend until it reaches a terminal state and resolve with its terminal
68
+ * output (validated against the target's declared output schema). Backed by the
69
+ * WDK's native `Run.returnValue` poll-until-terminal primitive.
70
+ */
71
+ startAndWait(name: string, input: unknown, opts?: WorkflowTriggerOptions): Promise<unknown>;
72
+ }
73
+ /**
74
+ * Plant (or clear, with `undefined`) the ambient starter. The runtime calls this
75
+ * on first dispatch with the bridge it built; tests pass a fake. Idempotent —
76
+ * the last write wins.
77
+ */
78
+ declare function setWorkflowStarter(starter: WorkflowStarter | undefined): void;
79
+ /**
80
+ * Return the bound ambient starter, or throw a clear error when none is bound —
81
+ * which means a trigger helper was called OUTSIDE a running workflow (the
82
+ * runtime binds the starter only on first dispatch).
83
+ */
84
+ declare function getWorkflowStarter(): WorkflowStarter;
85
+
86
+ /**
87
+ * Augmentable registry of the workspace's WORKFLOW names. By default it is empty,
88
+ * so `startWorkflow(name, ...)` / `startWorkflowAndWait(name, ...)` accept any
89
+ * `string` (today's behavior, validated only at runtime against the injected
90
+ * name→ref registry). `stackbone dev` generates an ambient
91
+ * `.stackbone/workflows.d.ts` from the project's `stackbone.config.ts` workflow
92
+ * list and augments this interface so the names become a closed set:
93
+ *
94
+ * declare module '@stackbone/sdk/workflow' {
95
+ * interface WorkflowRegistry {
96
+ * onboarding: true;
97
+ * qualifyLead: true;
98
+ * }
99
+ * }
100
+ *
101
+ * Once augmented, `startWorkflow('qualifyLead', ...)` is fine and
102
+ * `startWorkflow('typo', ...)` is a compile error — the editor also autocompletes
103
+ * the declared names. Mirrors the `AgentRegistry` augmentable-interface pattern
104
+ * used for `eveAgent`.
105
+ */
106
+ interface WorkflowRegistry {
107
+ }
108
+ /**
109
+ * The set of workflow names the trigger helpers accept, derived from the
110
+ * augmentable `WorkflowRegistry`. The tuple wrap (`[X] extends [never]`) defeats
111
+ * the conditional-type distributivity a bare `keyof WorkflowRegistry extends
112
+ * never` would trigger:
113
+ *
114
+ * - empty registry -> `string` (today's loose behavior: any name, checked at
115
+ * runtime when the workflow resolves it against the manifest);
116
+ * - augmented registry -> the union of declared workflow names (typo = compile error).
117
+ */
118
+ type WorkflowName = [keyof WorkflowRegistry] extends [never] ? string : keyof WorkflowRegistry;
119
+
120
+ /** Options for {@link startWorkflow}. See {@link WorkflowTriggerOptions}. */
121
+ type StartWorkflowOptions = WorkflowTriggerOptions;
122
+
123
+ /**
124
+ * Start the workflow named `name` with its own independent run and return its
125
+ * `{ runId }` immediately — fire-and-forget. The input is validated against the
126
+ * target's declared input schema BEFORE the run is enqueued; a name that does
127
+ * not resolve, or input that violates the schema, rejects without starting
128
+ * anything.
129
+ *
130
+ * `name` is typed `WorkflowName` — a loose `string` by default, narrowed to the
131
+ * workspace's declared workflow names once `stackbone dev` has generated
132
+ * `.stackbone/workflows.d.ts` (see `workflow-registry.ts`), so a typo becomes a
133
+ * compile error.
134
+ *
135
+ * MUST be called from inside a running workflow (the runtime binds the starter on
136
+ * first dispatch); calling it elsewhere throws.
137
+ *
138
+ * DURABILITY: the enqueue runs in a `"use step"`, so once it completes a parent
139
+ * restart resumes with the memoized `{ runId }` and does NOT re-enqueue. A crash
140
+ * WHILE the step is mid-flight re-runs it (at-least-once) — the same shape the
141
+ * eve-agent-from-step path has; for fire-and-forget fan-out this is acceptable.
142
+ * Use {@link startWorkflowAndWait} when you need the child's result.
143
+ */
144
+ declare function startWorkflow(name: WorkflowName, input: unknown, opts?: StartWorkflowOptions): Promise<WorkflowStartHandle>;
145
+
146
+ /** Options for {@link startWorkflowAndWait}. See {@link WorkflowTriggerOptions}. */
147
+ type StartWorkflowAndWaitOptions = WorkflowTriggerOptions;
148
+ /**
149
+ * Start the workflow named `name` with its own independent run and durably wait
150
+ * for it to finish, returning its terminal output (validated against the
151
+ * target's declared output schema). Use this when one workflow needs another's
152
+ * result to continue.
153
+ *
154
+ * The input is validated against the target's declared input schema BEFORE the
155
+ * run is enqueued; a name that does not resolve, or input that violates the
156
+ * schema, rejects without starting anything. `TOutput` lets the caller name the
157
+ * expected output shape (defaults to `unknown`).
158
+ *
159
+ * `name` is typed `WorkflowName` — narrowed to the workspace's declared workflow
160
+ * names once `stackbone dev` has generated `.stackbone/workflows.d.ts`. MUST be
161
+ * called from inside a running workflow.
162
+ */
163
+ declare function startWorkflowAndWait<TOutput = unknown>(name: WorkflowName, input: unknown, opts?: StartWorkflowAndWaitOptions): Promise<TOutput>;
164
+
165
+ /**
166
+ * Augmentable registry of the workspace's eve agent NAMES. By default it is
167
+ * empty, so `eveAgent(name)` accepts any `string` (today's behavior, validated
168
+ * only at runtime against the injected `AGENT_URLS` map). `stackbone dev`
169
+ * generates an ambient `.stackbone/agents.d.ts` from the project's
170
+ * `stackbone.config.ts` agent list and augments this interface so the names
171
+ * become a closed set:
172
+ *
173
+ * declare module '@stackbone/sdk/workflow' {
174
+ * interface AgentRegistry {
175
+ * support: true;
176
+ * 'lead-qualifier': true;
177
+ * }
178
+ * }
179
+ *
180
+ * Once augmented, `eveAgent('lead-qualifier')` is fine and `eveAgent('typo')` is
181
+ * a compile error — the editor also autocompletes the declared names. Mirrors the
182
+ * `ConfigRegistry` augmentable-interface pattern used for `client.config`.
183
+ */
184
+ interface AgentRegistry {
185
+ }
186
+ /**
187
+ * The set of agent names `eveAgent` accepts, derived from the augmentable
188
+ * `AgentRegistry`. The tuple wrap (`[X] extends [never]`) defeats the
189
+ * conditional-type distributivity a bare `keyof AgentRegistry extends never`
190
+ * would trigger:
191
+ *
192
+ * - empty registry -> `string` (today's loose behavior: any name, checked at
193
+ * runtime when the workflow resolves it against `AGENT_URLS`);
194
+ * - augmented registry -> the union of declared agent names (typo = compile error).
195
+ */
196
+ type AgentName = [keyof AgentRegistry] extends [never] ? string : keyof AgentRegistry;
197
+
198
+ export { type AgentName as A, type ScheduledWorkflow as S, type WorkflowName as W, type AgentRegistry as a, type StartWorkflowAndWaitOptions as b, type StartWorkflowOptions as c, type WorkflowRegistry as d, type WorkflowStartHandle as e, startWorkflowAndWait as f, type WorkflowScheduler as g, type WorkflowStarter as h, type WorkflowTriggerOptions as i, getWorkflowScheduler as j, getWorkflowStarter as k, setWorkflowScheduler as l, setWorkflowStarter as m, startWorkflow as s };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * WHO a connector call is made on behalf of — the scoping principal the broker
3
+ * keys its credential cache/grant against. A STRUCTURAL mirror of the broker
4
+ * contract's `@stackbone/connect-contract` `Principal` union (app / user /
5
+ * client-credentials / jwt-bearer); defined locally rather than imported so the
6
+ * SDK connect surface stays a self-contained leaf (the sibling eve adapter follows
7
+ * the same discipline — it never pulls the platform contract into the published
8
+ * SDK tarball). It is structurally compatible, so a value typed against the
9
+ * contract's `Principal` is assignable here and vice-versa.
10
+ */
11
+ type Principal = {
12
+ readonly type: 'app';
13
+ } | {
14
+ readonly type: 'user';
15
+ readonly id: string;
16
+ readonly issuer: string;
17
+ readonly attributes?: Readonly<Record<string, string | readonly string[]>>;
18
+ } | {
19
+ readonly type: 'client-credentials';
20
+ readonly serviceAccountId: string;
21
+ } | {
22
+ readonly type: 'jwt-bearer';
23
+ readonly subject: string;
24
+ readonly issuer: string;
25
+ };
26
+
27
+ /** Options accepted by `callConnector` / `connection(...).call`. */
28
+ interface CallConnectorOptions {
29
+ /**
30
+ * WHO the connector call is made on behalf of. Defaults to `{ type: 'app' }`
31
+ * (the agent's own service-account credential). A `user` principal scopes the
32
+ * broker token issuer to that end user; `client-credentials` / `jwt-bearer` are
33
+ * the broker's M2M auth modes.
34
+ */
35
+ readonly principal?: Principal;
36
+ }
37
+ /**
38
+ * An `Error` carrying the broker's machine-readable `code` so a workflow matches
39
+ * the failure BY CODE STRING (never `instanceof` — under bundling the SDK and the
40
+ * workflow can hold different class identities; the code is the stable signal).
41
+ */
42
+ interface ConnectorCallError extends Error {
43
+ /** The broker error code (`invalid_args`, `credential_error`, `timeout`, …). */
44
+ readonly code: string;
45
+ }
46
+ /**
47
+ * Call a Stackbone Connect connector operation directly from a workflow.
48
+ *
49
+ * POSTs `{ connector, operation, args, principal, installationId }` to the
50
+ * agent-facing broker (`POST /api/connect/execute`) with HMAC scheme-A headers.
51
+ * On `{ ok: true, output }` it returns the operation `output`; on
52
+ * `{ ok: false, error }` (or any non-2xx) it THROWS a `ConnectorCallError` whose
53
+ * `.code` is the broker error code and `.message` the broker message.
54
+ *
55
+ * ```ts
56
+ * const channels = await callConnector('slack', 'conversations.list');
57
+ * await callConnector('slack', 'chat.postMessage', { channel: 'C123', text: 'hi' });
58
+ * ```
59
+ *
60
+ * @param connector The connect connector id registered in Studio.
61
+ * @param operation The operation / tool id to run on that connector.
62
+ * @param args The operation arguments (path/query/body params). Defaults `{}`.
63
+ * @param opts Optional `{ principal }` — defaults to `{ type: 'app' }`.
64
+ */
65
+ declare function callConnector(connector: string, operation: string, args?: Readonly<Record<string, unknown>>, opts?: CallConnectorOptions): Promise<unknown>;
66
+ /** The dynamic escape hatch present on every `connection(id)` handle. */
67
+ interface ConnectorHandle {
68
+ /**
69
+ * Run ANY operation on this connector by id — the untyped escape hatch, always
70
+ * available (use it for an operation id that is not a JS identifier, e.g. a
71
+ * dotted `chat.postMessage`, or a connector with no generated types). Sugar for
72
+ * `callConnector(id, operation, args, opts)`.
73
+ */
74
+ call(operation: string, args?: Readonly<Record<string, unknown>>, opts?: CallConnectorOptions): Promise<unknown>;
75
+ }
76
+ /**
77
+ * Augmentable registry of TYPED connector operations, keyed by the VERBATIM
78
+ * connector id (`'stub-mail'`, `'slack'`). The Stackbone Connect type generator
79
+ * (`stackbone dev` writes `.stackbone/connect.d.ts`) MERGES one member per connector
80
+ * into this interface via a `declare module` augmentation, each a map of the
81
+ * connector's operations → typed `(args) => Promise<output>`, derived from the
82
+ * introspected JSON Schema. Empty by default — with no generated types,
83
+ * `connection(id)` offers only the dynamic `.call(...)`.
84
+ *
85
+ * Same id-keyed-registry mechanism as `eveAgent`'s `AgentRegistry`: the selection
86
+ * style is unified — address an entity by its verbatim id, get a typed handle.
87
+ */
88
+ interface StackboneConnections {
89
+ }
90
+ /**
91
+ * The typed handle for a connector id: its generated operations (when the id is a
92
+ * known key of `StackboneConnections`) intersected with the dynamic `.call` escape
93
+ * hatch (always present). An unknown id resolves to just `ConnectorHandle`.
94
+ */
95
+ type ConnectorOf<Id extends string> = (Id extends keyof StackboneConnections ? StackboneConnections[Id] : unknown) & ConnectorHandle;
96
+ /**
97
+ * The exported `connection`: select a connector by its verbatim id and get a typed
98
+ * handle. A known id (a key of the generated `StackboneConnections`) yields its
99
+ * typed operations + `.call`; any other string yields the dynamic `ConnectorHandle`.
100
+ */
101
+ interface ConnectionAccessor {
102
+ <Id extends keyof StackboneConnections>(id: Id): ConnectorOf<Id>;
103
+ (id: string): ConnectorHandle;
104
+ }
105
+ /**
106
+ * Call Stackbone Connect connectors. Select by verbatim id, then call an operation —
107
+ * typed when `.stackbone/connect.d.ts` is generated, dynamic via `.call` always:
108
+ *
109
+ * ```ts
110
+ * await connection('stub-mail').sendMail({ to, subject, body }); // typed
111
+ * await connection('slack').call('chat.postMessage', { ... }); // dynamic escape hatch
112
+ * ```
113
+ *
114
+ * Mirrors `eveAgent('agent-name')`: one id-keyed selection style across the SDK.
115
+ */
116
+ declare const connection: ConnectionAccessor;
117
+
118
+ export { type CallConnectorOptions as C, type Principal as P, type StackboneConnections as S, type ConnectionAccessor as a, type ConnectorCallError as b, type ConnectorHandle as c, callConnector as d, connection as e };
@@ -0,0 +1,118 @@
1
+ /**
2
+ * WHO a connector call is made on behalf of — the scoping principal the broker
3
+ * keys its credential cache/grant against. A STRUCTURAL mirror of the broker
4
+ * contract's `@stackbone/connect-contract` `Principal` union (app / user /
5
+ * client-credentials / jwt-bearer); defined locally rather than imported so the
6
+ * SDK connect surface stays a self-contained leaf (the sibling eve adapter follows
7
+ * the same discipline — it never pulls the platform contract into the published
8
+ * SDK tarball). It is structurally compatible, so a value typed against the
9
+ * contract's `Principal` is assignable here and vice-versa.
10
+ */
11
+ type Principal = {
12
+ readonly type: 'app';
13
+ } | {
14
+ readonly type: 'user';
15
+ readonly id: string;
16
+ readonly issuer: string;
17
+ readonly attributes?: Readonly<Record<string, string | readonly string[]>>;
18
+ } | {
19
+ readonly type: 'client-credentials';
20
+ readonly serviceAccountId: string;
21
+ } | {
22
+ readonly type: 'jwt-bearer';
23
+ readonly subject: string;
24
+ readonly issuer: string;
25
+ };
26
+
27
+ /** Options accepted by `callConnector` / `connection(...).call`. */
28
+ interface CallConnectorOptions {
29
+ /**
30
+ * WHO the connector call is made on behalf of. Defaults to `{ type: 'app' }`
31
+ * (the agent's own service-account credential). A `user` principal scopes the
32
+ * broker token issuer to that end user; `client-credentials` / `jwt-bearer` are
33
+ * the broker's M2M auth modes.
34
+ */
35
+ readonly principal?: Principal;
36
+ }
37
+ /**
38
+ * An `Error` carrying the broker's machine-readable `code` so a workflow matches
39
+ * the failure BY CODE STRING (never `instanceof` — under bundling the SDK and the
40
+ * workflow can hold different class identities; the code is the stable signal).
41
+ */
42
+ interface ConnectorCallError extends Error {
43
+ /** The broker error code (`invalid_args`, `credential_error`, `timeout`, …). */
44
+ readonly code: string;
45
+ }
46
+ /**
47
+ * Call a Stackbone Connect connector operation directly from a workflow.
48
+ *
49
+ * POSTs `{ connector, operation, args, principal, installationId }` to the
50
+ * agent-facing broker (`POST /api/connect/execute`) with HMAC scheme-A headers.
51
+ * On `{ ok: true, output }` it returns the operation `output`; on
52
+ * `{ ok: false, error }` (or any non-2xx) it THROWS a `ConnectorCallError` whose
53
+ * `.code` is the broker error code and `.message` the broker message.
54
+ *
55
+ * ```ts
56
+ * const channels = await callConnector('slack', 'conversations.list');
57
+ * await callConnector('slack', 'chat.postMessage', { channel: 'C123', text: 'hi' });
58
+ * ```
59
+ *
60
+ * @param connector The connect connector id registered in Studio.
61
+ * @param operation The operation / tool id to run on that connector.
62
+ * @param args The operation arguments (path/query/body params). Defaults `{}`.
63
+ * @param opts Optional `{ principal }` — defaults to `{ type: 'app' }`.
64
+ */
65
+ declare function callConnector(connector: string, operation: string, args?: Readonly<Record<string, unknown>>, opts?: CallConnectorOptions): Promise<unknown>;
66
+ /** The dynamic escape hatch present on every `connection(id)` handle. */
67
+ interface ConnectorHandle {
68
+ /**
69
+ * Run ANY operation on this connector by id — the untyped escape hatch, always
70
+ * available (use it for an operation id that is not a JS identifier, e.g. a
71
+ * dotted `chat.postMessage`, or a connector with no generated types). Sugar for
72
+ * `callConnector(id, operation, args, opts)`.
73
+ */
74
+ call(operation: string, args?: Readonly<Record<string, unknown>>, opts?: CallConnectorOptions): Promise<unknown>;
75
+ }
76
+ /**
77
+ * Augmentable registry of TYPED connector operations, keyed by the VERBATIM
78
+ * connector id (`'stub-mail'`, `'slack'`). The Stackbone Connect type generator
79
+ * (`stackbone dev` writes `.stackbone/connect.d.ts`) MERGES one member per connector
80
+ * into this interface via a `declare module` augmentation, each a map of the
81
+ * connector's operations → typed `(args) => Promise<output>`, derived from the
82
+ * introspected JSON Schema. Empty by default — with no generated types,
83
+ * `connection(id)` offers only the dynamic `.call(...)`.
84
+ *
85
+ * Same id-keyed-registry mechanism as `eveAgent`'s `AgentRegistry`: the selection
86
+ * style is unified — address an entity by its verbatim id, get a typed handle.
87
+ */
88
+ interface StackboneConnections {
89
+ }
90
+ /**
91
+ * The typed handle for a connector id: its generated operations (when the id is a
92
+ * known key of `StackboneConnections`) intersected with the dynamic `.call` escape
93
+ * hatch (always present). An unknown id resolves to just `ConnectorHandle`.
94
+ */
95
+ type ConnectorOf<Id extends string> = (Id extends keyof StackboneConnections ? StackboneConnections[Id] : unknown) & ConnectorHandle;
96
+ /**
97
+ * The exported `connection`: select a connector by its verbatim id and get a typed
98
+ * handle. A known id (a key of the generated `StackboneConnections`) yields its
99
+ * typed operations + `.call`; any other string yields the dynamic `ConnectorHandle`.
100
+ */
101
+ interface ConnectionAccessor {
102
+ <Id extends keyof StackboneConnections>(id: Id): ConnectorOf<Id>;
103
+ (id: string): ConnectorHandle;
104
+ }
105
+ /**
106
+ * Call Stackbone Connect connectors. Select by verbatim id, then call an operation —
107
+ * typed when `.stackbone/connect.d.ts` is generated, dynamic via `.call` always:
108
+ *
109
+ * ```ts
110
+ * await connection('stub-mail').sendMail({ to, subject, body }); // typed
111
+ * await connection('slack').call('chat.postMessage', { ... }); // dynamic escape hatch
112
+ * ```
113
+ *
114
+ * Mirrors `eveAgent('agent-name')`: one id-keyed selection style across the SDK.
115
+ */
116
+ declare const connection: ConnectionAccessor;
117
+
118
+ export { type CallConnectorOptions as C, type Principal as P, type StackboneConnections as S, type ConnectionAccessor as a, type ConnectorCallError as b, type ConnectorHandle as c, callConnector as d, connection as e };