@perstack/react 0.0.58 → 0.0.59

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 (45) hide show
  1. package/dist/src/index.d.ts +156 -3
  2. package/dist/src/index.js +660 -4
  3. package/dist/src/index.js.map +1 -1
  4. package/package.json +3 -3
  5. package/dist/src/hooks/index.d.ts +0 -4
  6. package/dist/src/hooks/index.d.ts.map +0 -1
  7. package/dist/src/hooks/index.js +0 -4
  8. package/dist/src/hooks/index.js.map +0 -1
  9. package/dist/src/hooks/use-job-stream.d.ts +0 -17
  10. package/dist/src/hooks/use-job-stream.d.ts.map +0 -1
  11. package/dist/src/hooks/use-job-stream.js +0 -45
  12. package/dist/src/hooks/use-job-stream.js.map +0 -1
  13. package/dist/src/hooks/use-job-streams.d.ts +0 -14
  14. package/dist/src/hooks/use-job-streams.d.ts.map +0 -1
  15. package/dist/src/hooks/use-job-streams.js +0 -89
  16. package/dist/src/hooks/use-job-streams.js.map +0 -1
  17. package/dist/src/hooks/use-run.d.ts +0 -38
  18. package/dist/src/hooks/use-run.d.ts.map +0 -1
  19. package/dist/src/hooks/use-run.js +0 -200
  20. package/dist/src/hooks/use-run.js.map +0 -1
  21. package/dist/src/index.d.ts.map +0 -1
  22. package/dist/src/types/index.d.ts +0 -2
  23. package/dist/src/types/index.d.ts.map +0 -1
  24. package/dist/src/types/index.js +0 -2
  25. package/dist/src/types/index.js.map +0 -1
  26. package/dist/src/types/runtime-state.d.ts +0 -19
  27. package/dist/src/types/runtime-state.d.ts.map +0 -1
  28. package/dist/src/types/runtime-state.js +0 -2
  29. package/dist/src/types/runtime-state.js.map +0 -1
  30. package/dist/src/utils/event-to-activity.d.ts +0 -67
  31. package/dist/src/utils/event-to-activity.d.ts.map +0 -1
  32. package/dist/src/utils/event-to-activity.js +0 -337
  33. package/dist/src/utils/event-to-activity.js.map +0 -1
  34. package/dist/src/utils/group-by-run.d.ts +0 -24
  35. package/dist/src/utils/group-by-run.d.ts.map +0 -1
  36. package/dist/src/utils/group-by-run.js +0 -43
  37. package/dist/src/utils/group-by-run.js.map +0 -1
  38. package/dist/src/utils/index.d.ts +0 -4
  39. package/dist/src/utils/index.d.ts.map +0 -1
  40. package/dist/src/utils/index.js +0 -4
  41. package/dist/src/utils/index.js.map +0 -1
  42. package/dist/src/utils/stream.d.ts +0 -13
  43. package/dist/src/utils/stream.d.ts.map +0 -1
  44. package/dist/src/utils/stream.js +0 -18
  45. package/dist/src/utils/stream.js.map +0 -1
@@ -1,4 +1,157 @@
1
- export { type ActivityProcessState, type JobStreamState, type JobStreamSummary, type RunResult, type StreamConnector, useJobStream, useJobStreams, useRun, } from "./hooks/index.js";
2
- export type { PerRunStreamingState, StreamingState } from "./types/index.js";
3
- export { type ActivityProcessState as UtilActivityProcessState, createInitialActivityProcessState, groupActivitiesByRun, processRunEventToActivity, type RunGroup, toolToActivity, } from "./utils/index.js";
1
+ import { Activity, ActivityOrGroup, PerstackEvent, ToolCall, ToolResult } from "@perstack/core";
2
+
3
+ //#region src/types/runtime-state.d.ts
4
+ /** Per-run streaming state for real-time display */
5
+ type PerRunStreamingState = {
6
+ /** Expert key for this run */expertKey: string; /** Accumulated reasoning text during extended thinking */
7
+ reasoning?: string; /** Accumulated run result text during generation */
8
+ runResult?: string; /** Whether reasoning is currently streaming */
9
+ isReasoningActive?: boolean; /** Whether run result is currently streaming */
10
+ isRunResultActive?: boolean;
11
+ };
12
+ /** Streaming state organized by run ID to support parallel execution */
13
+ type StreamingState = {
14
+ /** Per-run streaming state, keyed by runId */runs: Record<string, PerRunStreamingState>;
15
+ };
16
+ //#endregion
17
+ //#region src/utils/stream.d.ts
18
+ type StreamConnector = (jobId: string, signal: AbortSignal) => Promise<AsyncIterable<PerstackEvent>>;
19
+ //#endregion
20
+ //#region src/hooks/use-job-stream.d.ts
21
+ type JobStreamState = {
22
+ activities: ActivityOrGroup[];
23
+ streaming: StreamingState;
24
+ latestActivity: ActivityOrGroup | null;
25
+ isConnected: boolean;
26
+ error: Error | null;
27
+ };
28
+ declare function useJobStream(options: {
29
+ jobId: string | null;
30
+ connect: StreamConnector;
31
+ enabled?: boolean;
32
+ }): JobStreamState;
33
+ //#endregion
34
+ //#region src/hooks/use-job-streams.d.ts
35
+ type JobStreamSummary = {
36
+ latestActivity: ActivityOrGroup | null;
37
+ isConnected: boolean;
38
+ };
39
+ declare function useJobStreams(options: {
40
+ jobs: Array<{
41
+ id: string;
42
+ enabled: boolean;
43
+ }>;
44
+ connect: StreamConnector;
45
+ }): Map<string, JobStreamSummary>;
46
+ //#endregion
47
+ //#region src/utils/event-to-activity.d.ts
48
+ /**
49
+ * Converts a tool call and result to an Activity.
50
+ * Delegates to core's createBaseToolActivity/createGeneralToolActivity to avoid duplication.
51
+ */
52
+ declare function toolToActivity(toolCall: ToolCall, toolResult: ToolResult, reasoning: string | undefined, meta: {
53
+ id: string;
54
+ expertKey: string;
55
+ runId: string;
56
+ previousActivityId?: string;
57
+ delegatedBy?: {
58
+ expertKey: string;
59
+ runId: string;
60
+ };
61
+ }): Activity;
62
+ type ToolState = {
63
+ id: string;
64
+ toolCall: ToolCall;
65
+ logged: boolean;
66
+ };
67
+ /**
68
+ * Per-run state to support parallel execution.
69
+ * Each run maintains its own independent state.
70
+ */
71
+ type RunState = {
72
+ expertKey: string;
73
+ queryLogged: boolean;
74
+ completionLogged: boolean;
75
+ isComplete: boolean;
76
+ completedReasoning?: string;
77
+ lastActivityId?: string;
78
+ delegatedBy?: {
79
+ expertKey: string;
80
+ runId: string;
81
+ }; /** Track if this run has pending delegate tool calls (for delegation complete detection) */
82
+ pendingDelegateCount: number;
83
+ };
84
+ /**
85
+ * State for processing RunEvent stream into Activity[].
86
+ * This state tracks tool calls and their results to create complete Activity items.
87
+ *
88
+ * Supports the daisy chain architecture:
89
+ * - Within-Run ordering via lastActivityId (per-run state)
90
+ * - Cross-Run ordering via delegatedBy (per-run state)
91
+ *
92
+ * Note: `tools` is NOT cleared on new run to support delegation results
93
+ * that arrive after parent expert resumes with a new runId.
94
+ */
95
+ type ActivityProcessState = {
96
+ /** Tool calls indexed by toolCallId - persisted across runs for delegation handling */tools: Map<string, ToolState>; /** Per-run state to support parallel execution */
97
+ runStates: Map<string, RunState>;
98
+ };
99
+ declare function createInitialActivityProcessState(): ActivityProcessState;
100
+ /**
101
+ * Processes a RunEvent and produces Activity or ParallelActivitiesGroup items.
102
+ * Only processes RunEvent (state machine transitions), not RuntimeEvent.
103
+ *
104
+ * @param state - Mutable processing state
105
+ * @param event - The event to process
106
+ * @param addActivity - Callback to add a new Activity or ParallelActivitiesGroup
107
+ */
108
+ declare function processRunEventToActivity(state: ActivityProcessState, event: PerstackEvent, addActivity: (activity: ActivityOrGroup) => void): void;
109
+ //#endregion
110
+ //#region src/hooks/use-run.d.ts
111
+ type RunResult = {
112
+ /** Accumulated activities from RunEvent (may include ParallelActivitiesGroup) */activities: ActivityOrGroup[]; /** Current streaming state */
113
+ streaming: StreamingState; /** Whether the run is complete */
114
+ isComplete: boolean; /** Number of events processed */
115
+ eventCount: number; /** Add a new event to be processed */
116
+ addEvent: (event: PerstackEvent) => void; /** Append historical events (processes and appends to activities) */
117
+ appendHistoricalEvents: (events: PerstackEvent[]) => void; /** Clear streaming state */
118
+ clearStreaming: () => void;
119
+ };
120
+ /**
121
+ * Hook for managing Run state from RunEvent stream.
122
+ *
123
+ * Architecture:
124
+ * - ExpertStateEvent → ActivityOrGroup[] (accumulated, append-only)
125
+ * - StreamingEvent → StreamingState (latest only, for display)
126
+ *
127
+ * IMPORTANT: activities are append-only and never cleared.
128
+ * This is required for compatibility with Ink's <Static> component.
129
+ */
130
+ declare function useRun(): RunResult;
131
+ //#endregion
132
+ //#region src/utils/group-by-run.d.ts
133
+ /**
134
+ * Represents a group of activities belonging to the same run
135
+ */
136
+ type RunGroup = {
137
+ runId: string;
138
+ expertKey: string;
139
+ activities: ActivityOrGroup[];
140
+ delegatedBy?: {
141
+ expertKey: string;
142
+ runId: string;
143
+ };
144
+ };
145
+ /**
146
+ * Groups activities by their runId while preserving order.
147
+ *
148
+ * This function groups activities so that each run can be displayed in its own
149
+ * visual section (e.g., separate <Static> components in Ink).
150
+ *
151
+ * @param activities - Array of activities or groups to group
152
+ * @returns Array of RunGroup objects, ordered by first appearance
153
+ */
154
+ declare function groupActivitiesByRun(activities: ActivityOrGroup[]): RunGroup[];
155
+ //#endregion
156
+ export { type ActivityProcessState, type ActivityProcessState as UtilActivityProcessState, type JobStreamState, type JobStreamSummary, type PerRunStreamingState, type RunGroup, type RunResult, type StreamConnector, type StreamingState, createInitialActivityProcessState, groupActivitiesByRun, processRunEventToActivity, toolToActivity, useJobStream, useJobStreams, useRun };
4
157
  //# sourceMappingURL=index.d.ts.map