@softr/sdk 0.0.36 → 0.0.37

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,31 +1,40 @@
1
1
  import { fetch } from "../fetch.js";
2
+ import { panic } from "../assertions.js";
2
3
  import { sessionConfig } from "../auth/config.js";
3
4
  import { readSessionToken } from "../auth/session.js";
4
5
  import { platformApiUrl } from "../auth/platform.js";
5
6
 
6
7
  //#region src/core/workflow.ts
8
+ function workflowsApiUrl() {
9
+ const url = process.env.SOFTR_WORKFLOWS_API_URL;
10
+ if (!url) panic("SOFTR_WORKFLOWS_API_URL is not set.");
11
+ return url.replace(/\/+$/, "");
12
+ }
7
13
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
8
14
  async function triggerWorkflow(action, payload) {
9
- const baseUrl = `${await platformApiUrl()}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`;
10
- const triggerRes = await fetch(baseUrl, {
15
+ const triggerRes = await fetch(`${await platformApiUrl()}/v1/vibe/applications/${sessionConfig().applicationId}/actions/${action.id}/workflow`, {
11
16
  method: "POST",
12
17
  headers: {
13
18
  Authorization: `Bearer ${readSessionToken()}`,
14
19
  "Content-Type": "application/json"
15
20
  },
16
- body: JSON.stringify(payload ?? {})
21
+ body: JSON.stringify({ input: payload ?? {} })
17
22
  });
18
23
  if (!triggerRes.ok) throw new Error(`Workflow trigger failed: ${triggerRes.status}`);
19
- const execution = await triggerRes.json();
20
- if (execution.status === "FINISHED") return;
21
- if (execution.status === "PENDING_INTERACTION") throw new Error("Workflow requires interaction");
22
- while (true) {
23
- await sleep(2e3);
24
- const detailsRes = await fetch(`${baseUrl}/${execution.id}`, { headers: { Authorization: `Bearer ${readSessionToken()}` } });
24
+ let details = await triggerRes.json();
25
+ while (details.status !== "FINISHED") {
26
+ if (details.status === "PENDING_INTERACTION") for (const interaction of details.nextInteractions) {
27
+ const interactionRes = await fetch(`${workflowsApiUrl()}/v1/interactive-actions/executions/${details.id}/actions/${interaction.id}`, {
28
+ method: "POST",
29
+ headers: { "Content-Type": "application/json" },
30
+ body: "{}"
31
+ });
32
+ if (!interactionRes.ok) throw new Error(`Workflow interaction failed: ${interactionRes.status}`);
33
+ }
34
+ await sleep(1e3);
35
+ const detailsRes = await fetch(`${workflowsApiUrl()}/v1/workflows/${action.resource.workflowId}/executions/${details.id}/details`);
25
36
  if (!detailsRes.ok) throw new Error(`Workflow status check failed: ${detailsRes.status}`);
26
- const details = await detailsRes.json();
27
- if (details.status === "FINISHED") return;
28
- if (details.status === "PENDING_INTERACTION") throw new Error("Workflow requires interaction");
37
+ details = await detailsRes.json();
29
38
  }
30
39
  }
31
40
  const workflow = { trigger: triggerWorkflow };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "0.0.36";
2
+ var version = "0.0.37";
3
3
 
4
4
  //#endregion
5
5
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@softr/sdk",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" },
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: core
13
13
  library: softr-sdk
14
- library_version: 0.0.36
14
+ library_version: 0.0.37
15
15
  ---
16
16
 
17
17
  # Softr SDK core
@@ -16,7 +16,7 @@ description: >-
16
16
  metadata:
17
17
  type: sub-skill
18
18
  library: softr-sdk
19
- library_version: 0.0.36
19
+ library_version: 0.0.37
20
20
  ---
21
21
 
22
22
  **Boundary.** `auth` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineVisibility`, the hooks and every type come from `@softr/sdk`. The app is already wired (`src/start.ts`, `src/router.tsx`, `src/routes/__root.tsx`); never add a second registration. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 0.0.36
15
+ library_version: 0.0.37
16
16
  ---
17
17
 
18
18
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere. The app is already wired (`src/start.ts`, `src/router.tsx`, `src/routes/__root.tsx`); never add a second registration. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -10,7 +10,7 @@ description: >-
10
10
  metadata:
11
11
  type: sub-skill
12
12
  library: softr-sdk
13
- library_version: 0.0.36
13
+ library_version: 0.0.37
14
14
  ---
15
15
 
16
16
  **Boundary.** `useCurrentUser`, `usePermissions` and every type come from `@softr/sdk` and work anywhere; `ds` and `auth` live on `@softr/sdk/server` and run only inside a `createServerFn` handler. The app is already wired — `src/start.ts` registers `softrAuthMiddleware`, `src/routes/__root.tsx` publishes the visitor as route context — never add a second registration. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.36
12
+ library_version: 0.0.37
13
13
  ---
14
14
 
15
15
  **Boundary.** `upload` lives on `@softr/sdk/server` and runs inside server functions. `useFileUpload` and `FileItem` live on `@softr/sdk/client` and run only in components. `FileAttachment` comes from `@softr/sdk` and can be imported anywhere.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.36
12
+ library_version: 0.0.37
13
13
  ---
14
14
 
15
15
  **Boundary.** `integration` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineIntegration` and every type come from `@softr/sdk` and can be imported anywhere. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -28,14 +28,17 @@ import { integration } from '@softr/sdk/server'
28
28
 
29
29
  ## Reading connected integrations from the prompt
30
30
 
31
- When the user attaches integrations to the chat, they appear in the `## Attached data sources` section of the prompt in this form:
31
+ When the user attaches integrations to the chat, they appear in the `## Attached integrations` section of the prompt in this form:
32
32
 
33
33
  ```
34
- - "Gmail" — database `<databaseId>`, integration `<integrationId>`, type `GMAIL`
34
+ - integration `<integrationId>`, type `GMAIL`, database `<databaseId>` "Gmail"
35
+ - integration `<integrationId>`, type `GMAIL`
35
36
  ```
36
37
 
37
38
  Pass the `integration` value as `integrationId` in `defineIntegration`. The `database` value is the table coordinate; integrations do not use it, so do not pass it anywhere. Use `integrationType` (e.g. `GMAIL`) to look up the base URL from the reference table below — then construct the full URL path, including any query parameters, directly in the `url` string.
38
39
 
40
+ Either shape configures `defineIntegration`. An entry with no `database` coordinate carries the `integrationId`, which is all the call needs.
41
+
39
42
  ## Declare the integration action
40
43
 
41
44
  ```ts
@@ -93,7 +96,7 @@ Do not add an `Authorization` key to `headers` — Softr injects the integration
93
96
 
94
97
  ## Base URLs by integration type
95
98
 
96
- Match the `integrationType` from the attached data sources section to find the base URL:
99
+ Match the `integrationType` from the attached integrations section to find the base URL:
97
100
 
98
101
  | integrationType | Base URL |
99
102
  |---|---|
@@ -11,7 +11,7 @@ description: >-
11
11
  metadata:
12
12
  type: sub-skill
13
13
  library: softr-sdk
14
- library_version: 0.0.36
14
+ library_version: 0.0.37
15
15
  ---
16
16
 
17
17
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineMutation` and every type come from `@softr/sdk` and can be imported anywhere. The app is already wired (`src/start.ts`, `src/router.tsx`, `src/routes/__root.tsx`); never add a second registration. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 0.0.36
15
+ library_version: 0.0.37
16
16
  ---
17
17
 
18
18
  **Boundary.** `ds` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler or a server-side route hook — importing it into a component fails the build. `defineQuery` and every type come from `@softr/sdk` and can be imported anywhere. The app is already wired (`src/start.ts`, `src/router.tsx`, `src/routes/__root.tsx`); never add a second registration. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -12,7 +12,7 @@ description: >-
12
12
  metadata:
13
13
  type: sub-skill
14
14
  library: softr-sdk
15
- library_version: 0.0.36
15
+ library_version: 0.0.37
16
16
  ---
17
17
 
18
18
  **Boundary.** `defineVisibility`, the error predicates and every type come from `@softr/sdk` and work anywhere; `ds` and `auth` live on `@softr/sdk/server` and run only inside a `createServerFn` handler. The app is already wired — `src/start.ts` registers `softrAuthMiddleware`, `src/routes/__root.tsx` publishes the visitor as route context — never add a second registration. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.
@@ -9,7 +9,7 @@ description: >-
9
9
  metadata:
10
10
  type: sub-skill
11
11
  library: softr-sdk
12
- library_version: 0.0.36
12
+ library_version: 0.0.37
13
13
  ---
14
14
 
15
15
  **Boundary.** `workflow` lives on `@softr/sdk/server` and runs only inside a `createServerFn` handler — importing it into a component fails the build. `defineWorkflow` and every type come from `@softr/sdk` and can be imported anywhere. Load the core `softr-sdk` skill only if you are unsure this is the right sub-skill.