@simple-ai-lab/sdk 0.4.0 → 0.6.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.
Files changed (74) hide show
  1. package/README.md +54 -1
  2. package/dist/actions.cjs +438 -0
  3. package/dist/actions.d.cts +336 -0
  4. package/dist/actions.d.ts +336 -0
  5. package/dist/actions.js +429 -0
  6. package/dist/agents.cjs +1054 -0
  7. package/dist/agents.d.cts +1016 -0
  8. package/dist/agents.d.ts +1016 -0
  9. package/dist/agents.js +1044 -0
  10. package/dist/built-in-actions.cjs +356 -0
  11. package/dist/built-in-actions.d.cts +41 -0
  12. package/dist/built-in-actions.d.ts +41 -0
  13. package/dist/built-in-actions.js +353 -0
  14. package/dist/client.cjs +29 -0
  15. package/dist/client.d.cts +15 -0
  16. package/dist/client.d.ts +15 -0
  17. package/dist/client.js +25 -0
  18. package/dist/code-action/defaults.cjs +11 -0
  19. package/dist/code-action/defaults.d.cts +7 -0
  20. package/dist/code-action/defaults.d.ts +7 -0
  21. package/dist/code-action/defaults.js +8 -0
  22. package/dist/code-action/define-action.cjs +74 -0
  23. package/dist/code-action/define-action.d.cts +94 -0
  24. package/dist/code-action/define-action.d.ts +94 -0
  25. package/dist/code-action/define-action.js +69 -0
  26. package/dist/code-action/index.cjs +11 -0
  27. package/dist/code-action/index.d.cts +4 -0
  28. package/dist/code-action/index.d.ts +4 -0
  29. package/dist/code-action/index.js +3 -0
  30. package/dist/code-action/types.cjs +13 -0
  31. package/dist/code-action/types.d.cts +13 -0
  32. package/dist/code-action/types.d.ts +13 -0
  33. package/dist/code-action/types.js +10 -0
  34. package/dist/code-action/workflow.cjs +29 -0
  35. package/dist/code-action/workflow.d.cts +53 -0
  36. package/dist/code-action/workflow.d.ts +53 -0
  37. package/dist/code-action/workflow.js +26 -0
  38. package/dist/data.cjs +98 -0
  39. package/dist/data.d.cts +44 -0
  40. package/dist/data.d.ts +44 -0
  41. package/dist/data.js +94 -0
  42. package/dist/http.cjs +65 -0
  43. package/dist/http.d.cts +14 -0
  44. package/dist/http.d.ts +14 -0
  45. package/dist/http.js +62 -0
  46. package/dist/index.cjs +68 -1597
  47. package/dist/index.d.cts +12 -780
  48. package/dist/index.d.ts +12 -780
  49. package/dist/index.js +10 -1311
  50. package/dist/projects.cjs +234 -0
  51. package/dist/projects.d.cts +24 -0
  52. package/dist/projects.d.ts +24 -0
  53. package/dist/projects.js +228 -0
  54. package/dist/schemas.cjs +50 -0
  55. package/dist/schemas.d.cts +81 -0
  56. package/dist/schemas.d.ts +81 -0
  57. package/dist/schemas.js +47 -0
  58. package/dist/shared/errors.cjs +31 -0
  59. package/dist/shared/errors.d.cts +22 -0
  60. package/dist/shared/errors.d.ts +22 -0
  61. package/dist/shared/errors.js +26 -0
  62. package/package.json +27 -31
  63. package/dist/chunk-V4E5PSKB.js +0 -267
  64. package/dist/chunk-V4E5PSKB.js.map +0 -1
  65. package/dist/code-action-CDt77m7I.d.cts +0 -191
  66. package/dist/code-action-CDt77m7I.d.ts +0 -191
  67. package/dist/code-action.cjs +0 -282
  68. package/dist/code-action.cjs.map +0 -1
  69. package/dist/code-action.d.cts +0 -2
  70. package/dist/code-action.d.ts +0 -2
  71. package/dist/code-action.js +0 -9
  72. package/dist/code-action.js.map +0 -1
  73. package/dist/index.cjs.map +0 -1
  74. package/dist/index.js.map +0 -1
@@ -0,0 +1,94 @@
1
+ import { SimpleAI } from "../client.js";
2
+ import type { ActionInvocationMetadata } from "./types.js";
3
+ import { type ActionDirectiveCarrier, type ActionWorkflow } from "./workflow.js";
4
+ /**
5
+ * Brand the code-action runner uses to recognize `defineAction` handlers. The
6
+ * runner calls the default export with `{ inputs, config }` either way; the
7
+ * wrapper adds the authenticated `client` to the handler's context.
8
+ */
9
+ export declare const SIMPLE_ACTION_BRAND: unique symbol;
10
+ declare const SIMPLE_ACTION_RUNTIME: unique symbol;
11
+ type ActionRuntime = {
12
+ apiKey: string;
13
+ baseUrl: string;
14
+ };
15
+ export type CustomDataResult<TItem = Record<string, unknown>> = {
16
+ items: TItem[];
17
+ total: number;
18
+ truncated: boolean;
19
+ };
20
+ export type CustomDataTransformOperation = {
21
+ kind: 'agent_search';
22
+ table: string;
23
+ filters: {
24
+ column: string;
25
+ values: (string | number | boolean)[];
26
+ }[];
27
+ text: string | null;
28
+ } | {
29
+ kind: 'search';
30
+ table: string;
31
+ } | {
32
+ kind: 'query';
33
+ };
34
+ export type CustomDataTransformContext<TItem = Record<string, unknown>, TInputs = Record<string, unknown>> = {
35
+ dataResult: CustomDataResult<TItem>;
36
+ inputs: TInputs;
37
+ operation: CustomDataTransformOperation;
38
+ config: Record<string, string>;
39
+ /** What this invocation is allowed to do, decided by the use site that invoked it. */
40
+ metadata: ActionInvocationMetadata;
41
+ client: SimpleAI;
42
+ };
43
+ export type ActionContext<TInputs = Record<string, unknown>> = {
44
+ /** The Action's declared inputs, already validated against its input schema. */
45
+ inputs: TInputs;
46
+ /** Your organization's configuration variables. */
47
+ config: Record<string, string>;
48
+ /** What this invocation is allowed to do, decided by the use site that invoked it. */
49
+ metadata: ActionInvocationMetadata;
50
+ /** The Simple AI SDK, authenticated for your organization. */
51
+ client: SimpleAI;
52
+ /** Ask the workflow that invoked this Action to do something, e.g. run a different node next. */
53
+ workflow: ActionWorkflow;
54
+ };
55
+ export type ActionHandler<TInputs = Record<string, unknown>, TResult = unknown> = ((args: {
56
+ inputs: TInputs;
57
+ config: Record<string, string>;
58
+ /** Omitted by runtimes that predate invocation metadata; the handler still receives one. */
59
+ metadata?: ActionInvocationMetadata;
60
+ [SIMPLE_ACTION_RUNTIME]?: ActionRuntime;
61
+ } & ActionDirectiveCarrier) => Promise<TResult>) & {
62
+ [SIMPLE_ACTION_BRAND]: true;
63
+ };
64
+ export type CustomDataTransformHandler<TItem = Record<string, unknown>, TInputs = Record<string, unknown>, TResult = unknown> = ((args: {
65
+ dataResult: CustomDataResult<TItem>;
66
+ inputs: TInputs;
67
+ operation: CustomDataTransformOperation;
68
+ config: Record<string, string>;
69
+ /** Omitted by runtimes that predate invocation metadata; the handler still receives one. */
70
+ metadata?: ActionInvocationMetadata;
71
+ [SIMPLE_ACTION_RUNTIME]?: ActionRuntime;
72
+ }) => Promise<TResult>) & {
73
+ [SIMPLE_ACTION_BRAND]: true;
74
+ };
75
+ /**
76
+ * Define a code action with a typed context and an org-authenticated SDK
77
+ * client. The returned value must be your module's default export.
78
+ *
79
+ * ```ts
80
+ * import { defineAction } from '@simple-ai-lab/sdk';
81
+ *
82
+ * export default defineAction(async ({ inputs, config, client }) => {
83
+ * const { records } = await client.data.query({ tableName: 'customers', text: inputs.email });
84
+ * return { found: records.length > 0 };
85
+ * });
86
+ * ```
87
+ */
88
+ export declare function defineAction<TInputs = Record<string, unknown>, TResult = unknown>(handler: (context: ActionContext<TInputs>) => Promise<TResult> | TResult): ActionHandler<TInputs, TResult>;
89
+ /**
90
+ * Define the optional result-formatting stage of a Custom Data Action.
91
+ * The first generic describes one item returned by the data operation.
92
+ */
93
+ export declare function defineCustomDataTransform<TItem = Record<string, unknown>, TInputs = Record<string, unknown>, TResult = unknown>(handler: (context: CustomDataTransformContext<TItem, TInputs>) => Promise<TResult> | TResult): CustomDataTransformHandler<TItem, TInputs, TResult>;
94
+ export {};
@@ -0,0 +1,69 @@
1
+ import { SimpleAI } from "../client.js";
2
+ import { ensureMetadata } from "./defaults.js";
3
+ import { createActionWorkflow } from "./workflow.js";
4
+ /**
5
+ * Brand the code-action runner uses to recognize `defineAction` handlers. The
6
+ * runner calls the default export with `{ inputs, config }` either way; the
7
+ * wrapper adds the authenticated `client` to the handler's context.
8
+ */
9
+ export const SIMPLE_ACTION_BRAND = Symbol.for('simple-ai.action');
10
+ const SIMPLE_ACTION_RUNTIME = Symbol.for('simple-ai.action-runtime');
11
+ function authenticatedClient(runtime) {
12
+ return runtime === undefined ? new SimpleAI() : new SimpleAI(runtime);
13
+ }
14
+ /**
15
+ * Define a code action with a typed context and an org-authenticated SDK
16
+ * client. The returned value must be your module's default export.
17
+ *
18
+ * ```ts
19
+ * import { defineAction } from '@simple-ai-lab/sdk';
20
+ *
21
+ * export default defineAction(async ({ inputs, config, client }) => {
22
+ * const { records } = await client.data.query({ tableName: 'customers', text: inputs.email });
23
+ * return { found: records.length > 0 };
24
+ * });
25
+ * ```
26
+ */
27
+ export function defineAction(handler) {
28
+ const wrapped = async (invocation) => {
29
+ const { inputs, config } = invocation;
30
+ const runtime = invocation[SIMPLE_ACTION_RUNTIME];
31
+ // The Dynamic Worker runner supplies a non-secret API identity. The
32
+ // outbound Worker injects the real short-lived credential after the
33
+ // request has crossed the untrusted isolate boundary.
34
+ const client = authenticatedClient(runtime);
35
+ const metadata = ensureMetadata(invocation.metadata);
36
+ // The invocation object doubles as the channel back to the runtime: a
37
+ // directive the handler requests is recorded on it and read once the
38
+ // handler resolves, beside the value it returned.
39
+ return handler({
40
+ inputs,
41
+ config,
42
+ metadata,
43
+ client,
44
+ workflow: createActionWorkflow({ metadata, carrier: invocation }),
45
+ });
46
+ };
47
+ const brand = { [SIMPLE_ACTION_BRAND]: true };
48
+ return Object.assign(wrapped, brand);
49
+ }
50
+ /**
51
+ * Define the optional result-formatting stage of a Custom Data Action.
52
+ * The first generic describes one item returned by the data operation.
53
+ */
54
+ export function defineCustomDataTransform(handler) {
55
+ const wrapped = async (invocation) => {
56
+ const { dataResult, inputs, operation, config } = invocation;
57
+ const client = authenticatedClient(invocation[SIMPLE_ACTION_RUNTIME]);
58
+ return handler({
59
+ dataResult,
60
+ inputs,
61
+ operation,
62
+ config,
63
+ metadata: ensureMetadata(invocation.metadata),
64
+ client,
65
+ });
66
+ };
67
+ const brand = { [SIMPLE_ACTION_BRAND]: true };
68
+ return Object.assign(wrapped, brand);
69
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ActionCapability = exports.SIMPLE_ACTION_BRAND = exports.defineCustomDataTransform = exports.defineAction = exports.MissingCapabilityError = void 0;
4
+ var errors_1 = require("../shared/errors.cjs");
5
+ Object.defineProperty(exports, "MissingCapabilityError", { enumerable: true, get: function () { return errors_1.MissingCapabilityError; } });
6
+ var define_action_1 = require("./define-action.cjs");
7
+ Object.defineProperty(exports, "defineAction", { enumerable: true, get: function () { return define_action_1.defineAction; } });
8
+ Object.defineProperty(exports, "defineCustomDataTransform", { enumerable: true, get: function () { return define_action_1.defineCustomDataTransform; } });
9
+ Object.defineProperty(exports, "SIMPLE_ACTION_BRAND", { enumerable: true, get: function () { return define_action_1.SIMPLE_ACTION_BRAND; } });
10
+ var types_1 = require("./types.cjs");
11
+ Object.defineProperty(exports, "ActionCapability", { enumerable: true, get: function () { return types_1.ActionCapability; } });
@@ -0,0 +1,4 @@
1
+ export { MissingCapabilityError } from "../shared/errors.cjs";
2
+ export { type ActionContext, type ActionHandler, type CustomDataResult, type CustomDataTransformContext, type CustomDataTransformHandler, type CustomDataTransformOperation, defineAction, defineCustomDataTransform, SIMPLE_ACTION_BRAND, } from "./define-action.cjs";
3
+ export { ActionCapability, type ActionInvocationMetadata } from "./types.cjs";
4
+ export type { ActionWorkflow, TransitionToOptions } from "./workflow.cjs";
@@ -0,0 +1,4 @@
1
+ export { MissingCapabilityError } from "../shared/errors.js";
2
+ export { type ActionContext, type ActionHandler, type CustomDataResult, type CustomDataTransformContext, type CustomDataTransformHandler, type CustomDataTransformOperation, defineAction, defineCustomDataTransform, SIMPLE_ACTION_BRAND, } from "./define-action.js";
3
+ export { ActionCapability, type ActionInvocationMetadata } from "./types.js";
4
+ export type { ActionWorkflow, TransitionToOptions } from "./workflow.js";
@@ -0,0 +1,3 @@
1
+ export { MissingCapabilityError } from "../shared/errors.js";
2
+ export { defineAction, defineCustomDataTransform, SIMPLE_ACTION_BRAND, } from "./define-action.js";
3
+ export { ActionCapability } from "./types.js";
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ /**
3
+ * Mirror of the invocation metadata the runtime puts on the wire. The SDK ships
4
+ * standalone, so it cannot import the platform's schema — `actionInvocationMetadataSchema`
5
+ * in `@simple-ai-lab/shared` is the source of truth and these declarations must track it.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.ActionCapability = void 0;
9
+ /** Something an Action is allowed to do at the use site that invoked it. */
10
+ var ActionCapability;
11
+ (function (ActionCapability) {
12
+ ActionCapability["WORKFLOW_TRANSITION"] = "WORKFLOW_TRANSITION";
13
+ })(ActionCapability || (exports.ActionCapability = ActionCapability = {}));
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mirror of the invocation metadata the runtime puts on the wire. The SDK ships
3
+ * standalone, so it cannot import the platform's schema — `actionInvocationMetadataSchema`
4
+ * in `@simple-ai-lab/shared` is the source of truth and these declarations must track it.
5
+ */
6
+ /** Something an Action is allowed to do at the use site that invoked it. */
7
+ export declare enum ActionCapability {
8
+ WORKFLOW_TRANSITION = "WORKFLOW_TRANSITION"
9
+ }
10
+ export interface ActionInvocationMetadata {
11
+ /** Capabilities this invocation grants — empty when the use site grants none. */
12
+ capabilities: ActionCapability[];
13
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Mirror of the invocation metadata the runtime puts on the wire. The SDK ships
3
+ * standalone, so it cannot import the platform's schema — `actionInvocationMetadataSchema`
4
+ * in `@simple-ai-lab/shared` is the source of truth and these declarations must track it.
5
+ */
6
+ /** Something an Action is allowed to do at the use site that invoked it. */
7
+ export declare enum ActionCapability {
8
+ WORKFLOW_TRANSITION = "WORKFLOW_TRANSITION"
9
+ }
10
+ export interface ActionInvocationMetadata {
11
+ /** Capabilities this invocation grants — empty when the use site grants none. */
12
+ capabilities: ActionCapability[];
13
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Mirror of the invocation metadata the runtime puts on the wire. The SDK ships
3
+ * standalone, so it cannot import the platform's schema — `actionInvocationMetadataSchema`
4
+ * in `@simple-ai-lab/shared` is the source of truth and these declarations must track it.
5
+ */
6
+ /** Something an Action is allowed to do at the use site that invoked it. */
7
+ export var ActionCapability;
8
+ (function (ActionCapability) {
9
+ ActionCapability["WORKFLOW_TRANSITION"] = "WORKFLOW_TRANSITION";
10
+ })(ActionCapability || (ActionCapability = {}));
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createActionWorkflow = createActionWorkflow;
4
+ const errors_1 = require("../shared/errors.cjs");
5
+ const types_1 = require("./types.cjs");
6
+ /**
7
+ * Registry-symbol key the SDK records a requested directive under, on the
8
+ * invocation object the runtime handed the handler. The platform declares the
9
+ * same key (`code-backend/worker-harness.ts`) and reads it back once the
10
+ * handler resolves; both run in one isolate, so `Symbol.for` resolves them to
11
+ * the same symbol.
12
+ */
13
+ const ACTION_DIRECTIVE = Symbol.for('simple-ai.action-directive');
14
+ function createActionWorkflow({ metadata, carrier, }) {
15
+ const assertCapability = (capability) => {
16
+ if (!metadata.capabilities.includes(capability)) {
17
+ throw new errors_1.MissingCapabilityError(capability);
18
+ }
19
+ };
20
+ return {
21
+ transitionTo({ nodeName, message, reason }) {
22
+ assertCapability(types_1.ActionCapability.WORKFLOW_TRANSITION);
23
+ carrier[ACTION_DIRECTIVE] = {
24
+ type: 'workflow-navigate',
25
+ payload: { nodeName, message: message ?? null, reason: reason ?? null },
26
+ };
27
+ },
28
+ };
29
+ }
@@ -0,0 +1,53 @@
1
+ import { type ActionInvocationMetadata } from "./types.cjs";
2
+ /**
3
+ * Registry-symbol key the SDK records a requested directive under, on the
4
+ * invocation object the runtime handed the handler. The platform declares the
5
+ * same key (`code-backend/worker-harness.ts`) and reads it back once the
6
+ * handler resolves; both run in one isolate, so `Symbol.for` resolves them to
7
+ * the same symbol.
8
+ */
9
+ declare const ACTION_DIRECTIVE: unique symbol;
10
+ /**
11
+ * Mirror of `actionDirectiveSchema` on the platform. The SDK ships standalone,
12
+ * so it cannot import that schema — these declarations must track it.
13
+ */
14
+ type ActionDirective = {
15
+ type: 'workflow-navigate';
16
+ payload: {
17
+ nodeName: string;
18
+ message: string | null;
19
+ reason: string | null;
20
+ };
21
+ };
22
+ /** The invocation object a directive is recorded on, for the runtime to read back. */
23
+ export type ActionDirectiveCarrier = {
24
+ [ACTION_DIRECTIVE]?: ActionDirective;
25
+ };
26
+ export type TransitionToOptions = {
27
+ /** Name of the node to run next, as it appears in the Agent. */
28
+ nodeName: string;
29
+ /** A short sentence to say to the caller as the transition happens. */
30
+ message?: string;
31
+ /** Why the Action transitioned, recorded on the call. */
32
+ reason?: string;
33
+ };
34
+ /** What an Action can ask of the workflow that invoked it. */
35
+ export interface ActionWorkflow {
36
+ /**
37
+ * Run `nodeName` next instead of following the Agent's own edges. Returns
38
+ * normally: the rest of the handler still runs, and the value it returns is
39
+ * still mapped to the Action's outputs. The transition travels beside that
40
+ * result. Calling it more than once keeps the last request.
41
+ *
42
+ * Requires the WORKFLOW_TRANSITION capability, which only conversation use
43
+ * sites grant — an Action node or an Agent tool call. Other use sites (per-turn
44
+ * Actions, automatic before/after-call Actions, data sync) have no live
45
+ * conversation to steer and throw {@link MissingCapabilityError} instead.
46
+ */
47
+ transitionTo(options: TransitionToOptions): void;
48
+ }
49
+ export declare function createActionWorkflow({ metadata, carrier, }: {
50
+ metadata: ActionInvocationMetadata;
51
+ carrier: ActionDirectiveCarrier;
52
+ }): ActionWorkflow;
53
+ export {};
@@ -0,0 +1,53 @@
1
+ import { type ActionInvocationMetadata } from "./types.js";
2
+ /**
3
+ * Registry-symbol key the SDK records a requested directive under, on the
4
+ * invocation object the runtime handed the handler. The platform declares the
5
+ * same key (`code-backend/worker-harness.ts`) and reads it back once the
6
+ * handler resolves; both run in one isolate, so `Symbol.for` resolves them to
7
+ * the same symbol.
8
+ */
9
+ declare const ACTION_DIRECTIVE: unique symbol;
10
+ /**
11
+ * Mirror of `actionDirectiveSchema` on the platform. The SDK ships standalone,
12
+ * so it cannot import that schema — these declarations must track it.
13
+ */
14
+ type ActionDirective = {
15
+ type: 'workflow-navigate';
16
+ payload: {
17
+ nodeName: string;
18
+ message: string | null;
19
+ reason: string | null;
20
+ };
21
+ };
22
+ /** The invocation object a directive is recorded on, for the runtime to read back. */
23
+ export type ActionDirectiveCarrier = {
24
+ [ACTION_DIRECTIVE]?: ActionDirective;
25
+ };
26
+ export type TransitionToOptions = {
27
+ /** Name of the node to run next, as it appears in the Agent. */
28
+ nodeName: string;
29
+ /** A short sentence to say to the caller as the transition happens. */
30
+ message?: string;
31
+ /** Why the Action transitioned, recorded on the call. */
32
+ reason?: string;
33
+ };
34
+ /** What an Action can ask of the workflow that invoked it. */
35
+ export interface ActionWorkflow {
36
+ /**
37
+ * Run `nodeName` next instead of following the Agent's own edges. Returns
38
+ * normally: the rest of the handler still runs, and the value it returns is
39
+ * still mapped to the Action's outputs. The transition travels beside that
40
+ * result. Calling it more than once keeps the last request.
41
+ *
42
+ * Requires the WORKFLOW_TRANSITION capability, which only conversation use
43
+ * sites grant — an Action node or an Agent tool call. Other use sites (per-turn
44
+ * Actions, automatic before/after-call Actions, data sync) have no live
45
+ * conversation to steer and throw {@link MissingCapabilityError} instead.
46
+ */
47
+ transitionTo(options: TransitionToOptions): void;
48
+ }
49
+ export declare function createActionWorkflow({ metadata, carrier, }: {
50
+ metadata: ActionInvocationMetadata;
51
+ carrier: ActionDirectiveCarrier;
52
+ }): ActionWorkflow;
53
+ export {};
@@ -0,0 +1,26 @@
1
+ import { MissingCapabilityError } from "../shared/errors.js";
2
+ import { ActionCapability } from "./types.js";
3
+ /**
4
+ * Registry-symbol key the SDK records a requested directive under, on the
5
+ * invocation object the runtime handed the handler. The platform declares the
6
+ * same key (`code-backend/worker-harness.ts`) and reads it back once the
7
+ * handler resolves; both run in one isolate, so `Symbol.for` resolves them to
8
+ * the same symbol.
9
+ */
10
+ const ACTION_DIRECTIVE = Symbol.for('simple-ai.action-directive');
11
+ export function createActionWorkflow({ metadata, carrier, }) {
12
+ const assertCapability = (capability) => {
13
+ if (!metadata.capabilities.includes(capability)) {
14
+ throw new MissingCapabilityError(capability);
15
+ }
16
+ };
17
+ return {
18
+ transitionTo({ nodeName, message, reason }) {
19
+ assertCapability(ActionCapability.WORKFLOW_TRANSITION);
20
+ carrier[ACTION_DIRECTIVE] = {
21
+ type: 'workflow-navigate',
22
+ payload: { nodeName, message: message ?? null, reason: reason ?? null },
23
+ };
24
+ },
25
+ };
26
+ }
package/dist/data.cjs ADDED
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DataClient = void 0;
4
+ const schemas_1 = require("./schemas.cjs");
5
+ function encodeTable(tableName) {
6
+ return encodeURIComponent(schemas_1.tableNameSchema.parse(tableName));
7
+ }
8
+ /**
9
+ * Custom data tables — query, read, and write your organization's records.
10
+ * Wraps the `/api/v1/data` REST endpoints.
11
+ */
12
+ class DataClient {
13
+ #http;
14
+ constructor(http) {
15
+ this.#http = http;
16
+ }
17
+ /** Facet-filtered search over an indexed table (Elasticsearch-backed, max 50 hits). */
18
+ async query(input) {
19
+ const parsed = schemas_1.queryInputSchema.parse(input);
20
+ const result = await this.#http.request({ method: 'POST', path: '/data/query', body: parsed });
21
+ return result;
22
+ }
23
+ /** Facet values for an indexed table. */
24
+ async facets(tableName) {
25
+ const result = await this.#http.request({ method: 'GET', path: `/data/facets/${encodeTable(tableName)}` });
26
+ return result;
27
+ }
28
+ /** Paginated listing straight from the relational store. */
29
+ async list(tableName, options = {}) {
30
+ const parsed = schemas_1.listOptionsSchema.parse(options);
31
+ const query = { ...(parsed.filters ?? {}) };
32
+ if (parsed.page !== undefined) {
33
+ query.page = String(parsed.page);
34
+ }
35
+ if (parsed.perPage !== undefined) {
36
+ query.per_page = String(parsed.perPage);
37
+ }
38
+ if (parsed.orderBy !== undefined) {
39
+ query.order_by = parsed.orderBy;
40
+ }
41
+ if (parsed.orderDirection !== undefined) {
42
+ query.order_direction = parsed.orderDirection;
43
+ }
44
+ const result = await this.#http.request({ method: 'GET', path: `/data/${encodeTable(tableName)}`, query });
45
+ return result;
46
+ }
47
+ async get(tableName, id) {
48
+ const result = await this.#http.request({ method: 'GET', path: `/data/${encodeTable(tableName)}/${id}` });
49
+ return result;
50
+ }
51
+ async create(tableName, payload) {
52
+ const result = await this.#http.request({
53
+ method: 'PUT',
54
+ path: `/data/${encodeTable(tableName)}`,
55
+ body: schemas_1.recordPayloadSchema.parse(payload),
56
+ });
57
+ return result;
58
+ }
59
+ async update(tableName, id, payload) {
60
+ const result = await this.#http.request({
61
+ method: 'PATCH',
62
+ path: `/data/${encodeTable(tableName)}/${id}`,
63
+ body: schemas_1.recordPayloadSchema.parse(payload),
64
+ });
65
+ return result;
66
+ }
67
+ async delete(tableName, id) {
68
+ const result = await this.#http.request({ method: 'DELETE', path: `/data/${encodeTable(tableName)}/${id}` });
69
+ return result;
70
+ }
71
+ /** Deletes every record in the table. Irreversible. */
72
+ async deleteAll(tableName) {
73
+ const result = await this.#http.request({ method: 'DELETE', path: `/data/${encodeTable(tableName)}` });
74
+ return result;
75
+ }
76
+ /**
77
+ * Asynchronous bulk upsert (max 1000 rows per call). Rows are FULL-ROW
78
+ * REPLACE on key conflict — omitted columns are cleared, not preserved.
79
+ * Returns a batch handle; poll `getBatch` for completion.
80
+ */
81
+ async batchUpsert(tableName, rows) {
82
+ const result = await this.#http.request({
83
+ method: 'PUT',
84
+ path: `/data/${encodeTable(tableName)}/batch`,
85
+ body: { rows: schemas_1.batchUpsertRowsSchema.parse(rows) },
86
+ });
87
+ return result;
88
+ }
89
+ /** Status of an async upsert batch created by `batchUpsert`. */
90
+ async getBatch(ingestBatchId) {
91
+ const result = await this.#http.request({
92
+ method: 'GET',
93
+ path: `/data/_batches/${encodeURIComponent(ingestBatchId)}`,
94
+ });
95
+ return result;
96
+ }
97
+ }
98
+ exports.DataClient = DataClient;
@@ -0,0 +1,44 @@
1
+ import type { HttpClient } from "./http.cjs";
2
+ import { type BatchUpsertResult, type DataRecord, type DeleteResult, type FacetsResult, type IngestBatchStatus, type ListOptions, type QueryInput, type RecordPayload } from "./schemas.cjs";
3
+ /**
4
+ * Custom data tables — query, read, and write your organization's records.
5
+ * Wraps the `/api/v1/data` REST endpoints.
6
+ */
7
+ export declare class DataClient {
8
+ #private;
9
+ constructor(http: HttpClient);
10
+ /** Facet-filtered search over an indexed table (Elasticsearch-backed, max 50 hits). */
11
+ query<TRecord extends DataRecord = DataRecord>(input: QueryInput): Promise<{
12
+ records: TRecord[];
13
+ total: number;
14
+ }>;
15
+ /** Facet values for an indexed table. */
16
+ facets(tableName: string): Promise<FacetsResult>;
17
+ /** Paginated listing straight from the relational store. */
18
+ list<TRecord extends DataRecord = DataRecord>(tableName: string, options?: ListOptions): Promise<{
19
+ records: TRecord[];
20
+ total_count: number;
21
+ page: number;
22
+ per_page: number;
23
+ }>;
24
+ get<TRecord extends DataRecord = DataRecord>(tableName: string, id: number): Promise<{
25
+ record: TRecord;
26
+ }>;
27
+ create<TRecord extends DataRecord = DataRecord>(tableName: string, payload: RecordPayload): Promise<{
28
+ record: TRecord;
29
+ }>;
30
+ update<TRecord extends DataRecord = DataRecord>(tableName: string, id: number, payload: RecordPayload): Promise<{
31
+ record: TRecord;
32
+ }>;
33
+ delete(tableName: string, id: number): Promise<DeleteResult>;
34
+ /** Deletes every record in the table. Irreversible. */
35
+ deleteAll(tableName: string): Promise<DeleteResult>;
36
+ /**
37
+ * Asynchronous bulk upsert (max 1000 rows per call). Rows are FULL-ROW
38
+ * REPLACE on key conflict — omitted columns are cleared, not preserved.
39
+ * Returns a batch handle; poll `getBatch` for completion.
40
+ */
41
+ batchUpsert(tableName: string, rows: RecordPayload[]): Promise<BatchUpsertResult>;
42
+ /** Status of an async upsert batch created by `batchUpsert`. */
43
+ getBatch(ingestBatchId: string): Promise<IngestBatchStatus>;
44
+ }
package/dist/data.d.ts ADDED
@@ -0,0 +1,44 @@
1
+ import type { HttpClient } from "./http.js";
2
+ import { type BatchUpsertResult, type DataRecord, type DeleteResult, type FacetsResult, type IngestBatchStatus, type ListOptions, type QueryInput, type RecordPayload } from "./schemas.js";
3
+ /**
4
+ * Custom data tables — query, read, and write your organization's records.
5
+ * Wraps the `/api/v1/data` REST endpoints.
6
+ */
7
+ export declare class DataClient {
8
+ #private;
9
+ constructor(http: HttpClient);
10
+ /** Facet-filtered search over an indexed table (Elasticsearch-backed, max 50 hits). */
11
+ query<TRecord extends DataRecord = DataRecord>(input: QueryInput): Promise<{
12
+ records: TRecord[];
13
+ total: number;
14
+ }>;
15
+ /** Facet values for an indexed table. */
16
+ facets(tableName: string): Promise<FacetsResult>;
17
+ /** Paginated listing straight from the relational store. */
18
+ list<TRecord extends DataRecord = DataRecord>(tableName: string, options?: ListOptions): Promise<{
19
+ records: TRecord[];
20
+ total_count: number;
21
+ page: number;
22
+ per_page: number;
23
+ }>;
24
+ get<TRecord extends DataRecord = DataRecord>(tableName: string, id: number): Promise<{
25
+ record: TRecord;
26
+ }>;
27
+ create<TRecord extends DataRecord = DataRecord>(tableName: string, payload: RecordPayload): Promise<{
28
+ record: TRecord;
29
+ }>;
30
+ update<TRecord extends DataRecord = DataRecord>(tableName: string, id: number, payload: RecordPayload): Promise<{
31
+ record: TRecord;
32
+ }>;
33
+ delete(tableName: string, id: number): Promise<DeleteResult>;
34
+ /** Deletes every record in the table. Irreversible. */
35
+ deleteAll(tableName: string): Promise<DeleteResult>;
36
+ /**
37
+ * Asynchronous bulk upsert (max 1000 rows per call). Rows are FULL-ROW
38
+ * REPLACE on key conflict — omitted columns are cleared, not preserved.
39
+ * Returns a batch handle; poll `getBatch` for completion.
40
+ */
41
+ batchUpsert(tableName: string, rows: RecordPayload[]): Promise<BatchUpsertResult>;
42
+ /** Status of an async upsert batch created by `batchUpsert`. */
43
+ getBatch(ingestBatchId: string): Promise<IngestBatchStatus>;
44
+ }