@trigger.dev/react-hooks 4.4.1 → 4.4.2
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/dist/commonjs/hooks/useInputStreamSend.d.ts +26 -0
- package/dist/commonjs/hooks/useInputStreamSend.js +45 -0
- package/dist/commonjs/hooks/useInputStreamSend.js.map +1 -0
- package/dist/commonjs/index.d.ts +1 -0
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/esm/hooks/useInputStreamSend.d.ts +26 -0
- package/dist/esm/hooks/useInputStreamSend.js +39 -0
- package/dist/esm/hooks/useInputStreamSend.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UseApiClientOptions } from "./useApiClient.js";
|
|
2
|
+
export interface InputStreamSendInstance<TData> {
|
|
3
|
+
/** Send data to the input stream */
|
|
4
|
+
send: (data: TData) => void;
|
|
5
|
+
/** Whether a send is currently in progress */
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
/** Any error that occurred during the last send */
|
|
8
|
+
error?: Error;
|
|
9
|
+
/** Whether the hook is ready to send (has runId and access token) */
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook to send data to an input stream on a running task.
|
|
14
|
+
*
|
|
15
|
+
* @template TData - The type of data to send
|
|
16
|
+
* @param streamId - The input stream identifier
|
|
17
|
+
* @param runId - The run to send input stream data to
|
|
18
|
+
* @param options - API client options (e.g. accessToken)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const { send, isLoading } = useInputStreamSend("my-stream", runId, { accessToken });
|
|
23
|
+
* send({ message: "hello" });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function useInputStreamSend<TData>(streamId: string, runId?: string, options?: UseApiClientOptions): InputStreamSendInstance<TData>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useInputStreamSend = useInputStreamSend;
|
|
8
|
+
const mutation_1 = __importDefault(require("swr/mutation"));
|
|
9
|
+
const useApiClient_js_1 = require("./useApiClient.js");
|
|
10
|
+
/**
|
|
11
|
+
* Hook to send data to an input stream on a running task.
|
|
12
|
+
*
|
|
13
|
+
* @template TData - The type of data to send
|
|
14
|
+
* @param streamId - The input stream identifier
|
|
15
|
+
* @param runId - The run to send input stream data to
|
|
16
|
+
* @param options - API client options (e.g. accessToken)
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* const { send, isLoading } = useInputStreamSend("my-stream", runId, { accessToken });
|
|
21
|
+
* send({ message: "hello" });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
function useInputStreamSend(streamId, runId, options) {
|
|
25
|
+
const apiClient = (0, useApiClient_js_1.useApiClient)(options);
|
|
26
|
+
async function sendToStream(key, { arg }) {
|
|
27
|
+
if (!apiClient) {
|
|
28
|
+
throw new Error("Could not send to input stream: Missing access token");
|
|
29
|
+
}
|
|
30
|
+
if (!runId) {
|
|
31
|
+
throw new Error("Could not send to input stream: Missing run ID");
|
|
32
|
+
}
|
|
33
|
+
return await apiClient.sendInputStream(runId, streamId, arg.data);
|
|
34
|
+
}
|
|
35
|
+
const mutation = (0, mutation_1.default)(runId ? `input-stream:${runId}:${streamId}` : null, sendToStream);
|
|
36
|
+
return {
|
|
37
|
+
send: (data) => {
|
|
38
|
+
mutation.trigger({ data });
|
|
39
|
+
},
|
|
40
|
+
isLoading: mutation.isMutating,
|
|
41
|
+
isReady: !!runId && !!apiClient,
|
|
42
|
+
error: mutation.error,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=useInputStreamSend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInputStreamSend.js","sourceRoot":"","sources":["../../../src/hooks/useInputStreamSend.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;AA8Bb,gDA6BC;AAzDD,4DAA0C;AAC1C,uDAAsE;AAatE;;;;;;;;;;;;;GAaG;AACH,SAAgB,kBAAkB,CAChC,QAAgB,EAChB,KAAc,EACd,OAA6B;IAE7B,MAAM,SAAS,GAAG,IAAA,8BAAY,EAAC,OAAO,CAAC,CAAC;IAExC,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,EAAE,GAAG,EAA4B;QACxE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,MAAM,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,QAAQ,GAAG,IAAA,kBAAc,EAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,KAAK,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAElG,OAAO;QACL,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;YACb,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,SAAS,EAAE,QAAQ,CAAC,UAAU;QAC9B,OAAO,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,SAAS;QAC/B,KAAK,EAAE,QAAQ,CAAC,KAAK;KACtB,CAAC;AACJ,CAAC"}
|
package/dist/commonjs/index.d.ts
CHANGED
package/dist/commonjs/index.js
CHANGED
|
@@ -20,4 +20,5 @@ __exportStar(require("./hooks/useRun.js"), exports);
|
|
|
20
20
|
__exportStar(require("./hooks/useRealtime.js"), exports);
|
|
21
21
|
__exportStar(require("./hooks/useTaskTrigger.js"), exports);
|
|
22
22
|
__exportStar(require("./hooks/useWaitToken.js"), exports);
|
|
23
|
+
__exportStar(require("./hooks/useInputStreamSend.js"), exports);
|
|
23
24
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0DAAwC;AACxC,oDAAkC;AAClC,yDAAuC;AACvC,4DAA0C;AAC1C,0DAAwC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA8B;AAC9B,0DAAwC;AACxC,oDAAkC;AAClC,yDAAuC;AACvC,4DAA0C;AAC1C,0DAAwC;AACxC,gEAA8C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { UseApiClientOptions } from "./useApiClient.js";
|
|
2
|
+
export interface InputStreamSendInstance<TData> {
|
|
3
|
+
/** Send data to the input stream */
|
|
4
|
+
send: (data: TData) => void;
|
|
5
|
+
/** Whether a send is currently in progress */
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
/** Any error that occurred during the last send */
|
|
8
|
+
error?: Error;
|
|
9
|
+
/** Whether the hook is ready to send (has runId and access token) */
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook to send data to an input stream on a running task.
|
|
14
|
+
*
|
|
15
|
+
* @template TData - The type of data to send
|
|
16
|
+
* @param streamId - The input stream identifier
|
|
17
|
+
* @param runId - The run to send input stream data to
|
|
18
|
+
* @param options - API client options (e.g. accessToken)
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* const { send, isLoading } = useInputStreamSend("my-stream", runId, { accessToken });
|
|
23
|
+
* send({ message: "hello" });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function useInputStreamSend<TData>(streamId: string, runId?: string, options?: UseApiClientOptions): InputStreamSendInstance<TData>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWRMutation from "swr/mutation";
|
|
3
|
+
import { useApiClient } from "./useApiClient.js";
|
|
4
|
+
/**
|
|
5
|
+
* Hook to send data to an input stream on a running task.
|
|
6
|
+
*
|
|
7
|
+
* @template TData - The type of data to send
|
|
8
|
+
* @param streamId - The input stream identifier
|
|
9
|
+
* @param runId - The run to send input stream data to
|
|
10
|
+
* @param options - API client options (e.g. accessToken)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* const { send, isLoading } = useInputStreamSend("my-stream", runId, { accessToken });
|
|
15
|
+
* send({ message: "hello" });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function useInputStreamSend(streamId, runId, options) {
|
|
19
|
+
const apiClient = useApiClient(options);
|
|
20
|
+
async function sendToStream(key, { arg }) {
|
|
21
|
+
if (!apiClient) {
|
|
22
|
+
throw new Error("Could not send to input stream: Missing access token");
|
|
23
|
+
}
|
|
24
|
+
if (!runId) {
|
|
25
|
+
throw new Error("Could not send to input stream: Missing run ID");
|
|
26
|
+
}
|
|
27
|
+
return await apiClient.sendInputStream(runId, streamId, arg.data);
|
|
28
|
+
}
|
|
29
|
+
const mutation = useSWRMutation(runId ? `input-stream:${runId}:${streamId}` : null, sendToStream);
|
|
30
|
+
return {
|
|
31
|
+
send: (data) => {
|
|
32
|
+
mutation.trigger({ data });
|
|
33
|
+
},
|
|
34
|
+
isLoading: mutation.isMutating,
|
|
35
|
+
isReady: !!runId && !!apiClient,
|
|
36
|
+
error: mutation.error,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=useInputStreamSend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useInputStreamSend.js","sourceRoot":"","sources":["../../../src/hooks/useInputStreamSend.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,cAAc,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAuB,MAAM,mBAAmB,CAAC;AAatE;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAChC,QAAgB,EAChB,KAAc,EACd,OAA6B;IAE7B,MAAM,SAAS,GAAG,YAAY,CAAC,OAAO,CAAC,CAAC;IAExC,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,EAAE,GAAG,EAA4B;QACxE,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;QAC1E,CAAC;QAED,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,MAAM,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC;IACpE,CAAC;IAED,MAAM,QAAQ,GAAG,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,KAAK,IAAI,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAElG,OAAO;QACL,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;YACb,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,SAAS,EAAE,QAAQ,CAAC,UAAU;QAC9B,OAAO,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,SAAS;QAC/B,KAAK,EAAE,QAAQ,CAAC,KAAK;KACtB,CAAC;AACJ,CAAC"}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trigger.dev/react-hooks",
|
|
3
|
-
"version": "4.4.
|
|
3
|
+
"version": "4.4.2",
|
|
4
4
|
"description": "trigger.dev react hooks",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
]
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@trigger.dev/core": "^4.4.
|
|
32
|
+
"@trigger.dev/core": "^4.4.2",
|
|
33
33
|
"swr": "^2.2.5"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|