@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/helpers.ts +13 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinixai/hub-client",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Typed Hub client for Pinix — Connect-RPC transport + proto types",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
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 aggregate streaming output into a single result.
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
- * This helper collects all chunks and returns the parsed JSON result.
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
- let outputBytes = new Uint8Array(0);
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 merged = new Uint8Array(outputBytes.length + response.output.length);
37
- merged.set(outputBytes);
38
- merged.set(response.output, outputBytes.length);
39
- outputBytes = merged;
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 (outputBytes.length === 0) return undefined;
44
-
45
- const text = decoder.decode(outputBytes);
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
  }