@pinixai/hub-client 0.1.0 → 0.1.1
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 +1 -1
- package/src/helpers.ts +13 -11
package/package.json
CHANGED
package/src/helpers.ts
CHANGED
|
@@ -5,10 +5,11 @@ const encoder = new TextEncoder();
|
|
|
5
5
|
const decoder = new TextDecoder();
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* Invoke a clip command via Hub and
|
|
8
|
+
* Invoke a clip command via Hub and return the parsed result.
|
|
9
9
|
*
|
|
10
10
|
* The Hub's Invoke RPC is server-streaming: each response carries a chunk of output.
|
|
11
|
-
*
|
|
11
|
+
* Each chunk is parsed independently. Returns a single value for one chunk,
|
|
12
|
+
* or an array for multiple chunks.
|
|
12
13
|
*/
|
|
13
14
|
export async function hubInvoke(
|
|
14
15
|
client: Client<typeof HubService>,
|
|
@@ -18,7 +19,7 @@ export async function hubInvoke(
|
|
|
18
19
|
clipToken?: string,
|
|
19
20
|
): Promise<unknown> {
|
|
20
21
|
const inputBytes = encoder.encode(JSON.stringify(input));
|
|
21
|
-
|
|
22
|
+
const results: unknown[] = [];
|
|
22
23
|
|
|
23
24
|
for await (const response of client.invoke({
|
|
24
25
|
clipName,
|
|
@@ -33,15 +34,16 @@ export async function hubInvoke(
|
|
|
33
34
|
}
|
|
34
35
|
|
|
35
36
|
if (response.output.length > 0) {
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
const text = decoder.decode(response.output);
|
|
38
|
+
try {
|
|
39
|
+
results.push(JSON.parse(text));
|
|
40
|
+
} catch {
|
|
41
|
+
results.push(text);
|
|
42
|
+
}
|
|
40
43
|
}
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return JSON.parse(text) as unknown;
|
|
46
|
+
if (results.length === 0) return undefined;
|
|
47
|
+
if (results.length === 1) return results[0];
|
|
48
|
+
return results;
|
|
47
49
|
}
|