@pinixai/core 0.3.0 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pinixai/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Clip framework for Pinix — define once, run as CLI / MCP / Pinix bridge",
5
5
  "main": "src/index.ts",
6
6
  "module": "src/index.ts",
package/src/handler.ts CHANGED
@@ -1,15 +1,19 @@
1
1
  import { z, type ZodType } from "zod";
2
2
 
3
+ export interface Stream {
4
+ chunk(data: unknown): void;
5
+ }
6
+
3
7
  export interface HandlerDef<I extends ZodType = ZodType, O extends ZodType = ZodType> {
4
8
  input: I;
5
9
  output: O;
6
- fn: (input: z.infer<I>) => Promise<z.infer<O>>;
10
+ fn: (input: z.infer<I>, stream?: Stream) => Promise<z.infer<O>>;
7
11
  }
8
12
 
9
13
  export function handler<I extends ZodType, O extends ZodType>(
10
14
  input: I,
11
15
  output: O,
12
- fn: (input: z.infer<I>) => Promise<z.infer<O>>,
16
+ fn: (input: z.infer<I>, stream?: Stream) => Promise<z.infer<O>>,
13
17
  ): HandlerDef<I, O> {
14
18
  return { input, output, fn };
15
19
  }
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { Clip } from "./clip";
2
2
  export { command } from "./command";
3
- export { handler, type HandlerDef } from "./handler";
3
+ export { handler, type HandlerDef, type Stream } from "./handler";
4
4
  export { serveHTTP } from "./http";
5
5
  export { serveIPC, invoke } from "./ipc";
6
6
  export { serveMCP } from "./mcp";
package/src/ipc.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import type { Clip } from "./clip";
2
+ import type { Stream } from "./handler";
2
3
  import { createIPCManifest } from "./manifest";
3
4
 
4
5
  // === IPC Protocol Types ===
@@ -138,7 +139,21 @@ async function handleInvoke(
138
139
 
139
140
  try {
140
141
  const parsed = cmd.input.parse(msg.input ?? {});
141
- const output = await cmd.fn(parsed);
142
+ let streamed = false;
143
+ const stream: Stream = {
144
+ chunk(data: unknown): void {
145
+ streamed = true;
146
+ send({ id: msg.id, type: "chunk", output: data });
147
+ },
148
+ };
149
+
150
+ const output = await cmd.fn(parsed, stream);
151
+
152
+ if (streamed) {
153
+ send({ id: msg.id, type: "done" });
154
+ return;
155
+ }
156
+
142
157
  send({ id: msg.id, type: "result", output });
143
158
  } catch (err) {
144
159
  send({ id: msg.id, type: "error", error: err instanceof Error ? err.message : String(err) });