@pinixai/hub-client 0.1.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.
- package/package.json +37 -0
- package/src/client.ts +33 -0
- package/src/gen/hub_pb.ts +1652 -0
- package/src/helpers.ts +47 -0
- package/src/index.ts +36 -0
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Client } from "@connectrpc/connect";
|
|
2
|
+
import type { HubService } from "./gen/hub_pb";
|
|
3
|
+
|
|
4
|
+
const encoder = new TextEncoder();
|
|
5
|
+
const decoder = new TextDecoder();
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Invoke a clip command via Hub and aggregate streaming output into a single result.
|
|
9
|
+
*
|
|
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.
|
|
12
|
+
*/
|
|
13
|
+
export async function hubInvoke(
|
|
14
|
+
client: Client<typeof HubService>,
|
|
15
|
+
clipName: string,
|
|
16
|
+
command: string,
|
|
17
|
+
input: unknown,
|
|
18
|
+
clipToken?: string,
|
|
19
|
+
): Promise<unknown> {
|
|
20
|
+
const inputBytes = encoder.encode(JSON.stringify(input));
|
|
21
|
+
let outputBytes = new Uint8Array(0);
|
|
22
|
+
|
|
23
|
+
for await (const response of client.invoke({
|
|
24
|
+
clipName,
|
|
25
|
+
command,
|
|
26
|
+
input: inputBytes,
|
|
27
|
+
clipToken: clipToken ?? "",
|
|
28
|
+
})) {
|
|
29
|
+
if (response.error) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
response.error.message || response.error.code || "Hub invoke error",
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
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;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (outputBytes.length === 0) return undefined;
|
|
44
|
+
|
|
45
|
+
const text = decoder.decode(outputBytes);
|
|
46
|
+
return JSON.parse(text) as unknown;
|
|
47
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export { createHubClient, type HubClientOptions } from "./client";
|
|
2
|
+
export { hubInvoke } from "./helpers";
|
|
3
|
+
|
|
4
|
+
export {
|
|
5
|
+
HubService,
|
|
6
|
+
type ClipInfo,
|
|
7
|
+
type CommandInfo,
|
|
8
|
+
type ClipManifest,
|
|
9
|
+
type ProviderInfo,
|
|
10
|
+
type DependencySlot,
|
|
11
|
+
type ClipBinding,
|
|
12
|
+
type InvokeRequest,
|
|
13
|
+
type InvokeResponse,
|
|
14
|
+
type ListClipsRequest,
|
|
15
|
+
type ListClipsResponse,
|
|
16
|
+
type ListProvidersRequest,
|
|
17
|
+
type ListProvidersResponse,
|
|
18
|
+
type GetManifestRequest,
|
|
19
|
+
type GetManifestResponse,
|
|
20
|
+
type GetClipWebRequest,
|
|
21
|
+
type GetClipWebResponse,
|
|
22
|
+
type AddClipRequest,
|
|
23
|
+
type AddClipResponse,
|
|
24
|
+
type RemoveClipRequest,
|
|
25
|
+
type RemoveClipResponse,
|
|
26
|
+
type GetBindingsRequest,
|
|
27
|
+
type GetBindingsResponse,
|
|
28
|
+
type SetBindingRequest,
|
|
29
|
+
type SetBindingResponse,
|
|
30
|
+
type RemoveBindingRequest,
|
|
31
|
+
type RemoveBindingResponse,
|
|
32
|
+
type HubError,
|
|
33
|
+
type ClipStatus,
|
|
34
|
+
} from "./gen/hub_pb";
|
|
35
|
+
|
|
36
|
+
export type { Interceptor } from "@connectrpc/connect";
|