veryfront 0.1.701 → 0.1.704
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/esm/cli/templates/manifest.d.ts +0 -2
- package/esm/cli/templates/manifest.js +1 -3
- package/esm/deno.js +1 -1
- package/esm/src/agent/streaming/fork-runtime-part-mapper.d.ts +59 -0
- package/esm/src/agent/streaming/fork-runtime-part-mapper.d.ts.map +1 -0
- package/esm/src/agent/streaming/fork-runtime-part-mapper.js +246 -0
- package/esm/src/agent/streaming/fork-runtime-step-state.d.ts +36 -0
- package/esm/src/agent/streaming/fork-runtime-step-state.d.ts.map +1 -0
- package/esm/src/agent/streaming/fork-runtime-step-state.js +240 -0
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts +4 -81
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts.map +1 -1
- package/esm/src/agent/streaming/fork-runtime-stream.js +5 -482
- package/esm/src/integrations/_data.d.ts.map +1 -1
- package/esm/src/integrations/_data.js +1 -42
- package/esm/src/internal-agents/run-stream.d.ts.map +1 -1
- package/esm/src/internal-agents/run-stream.js +3 -0
- package/esm/src/oauth/providers/common.d.ts.map +1 -1
- package/esm/src/oauth/providers/common.js +6 -1
- package/esm/src/tool/types.d.ts +2 -0
- package/esm/src/tool/types.d.ts.map +1 -1
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/esm/src/workflow/claude-code/react/event-state-reducer.d.ts +37 -0
- package/esm/src/workflow/claude-code/react/event-state-reducer.d.ts.map +1 -0
- package/esm/src/workflow/claude-code/react/event-state-reducer.js +104 -0
- package/esm/src/workflow/claude-code/react/use-claude-code-stream.d.ts +3 -35
- package/esm/src/workflow/claude-code/react/use-claude-code-stream.d.ts.map +1 -1
- package/esm/src/workflow/claude-code/react/use-claude-code-stream.js +9 -78
- package/esm/src/workflow/claude-code/react/use-claude-code-websocket.d.ts +2 -27
- package/esm/src/workflow/claude-code/react/use-claude-code-websocket.d.ts.map +1 -1
- package/esm/src/workflow/claude-code/react/use-claude-code-websocket.js +5 -57
- package/package.json +1 -1
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ClaudeCodeEvent, ClaudeCodeEventExtended, ClaudeCodeResult } from "../types.js";
|
|
2
|
+
export interface ClaudeCodeCurrentTool {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
input: Record<string, unknown>;
|
|
6
|
+
}
|
|
7
|
+
export interface ClaudeCodeToolCall extends ClaudeCodeCurrentTool {
|
|
8
|
+
output?: string;
|
|
9
|
+
isError?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface ClaudeCodeAllToolCall extends ClaudeCodeToolCall {
|
|
12
|
+
iteration: number;
|
|
13
|
+
}
|
|
14
|
+
export interface ClaudeCodeEventState {
|
|
15
|
+
isRunning: boolean;
|
|
16
|
+
currentIteration: number;
|
|
17
|
+
maxIterations: number;
|
|
18
|
+
text: string;
|
|
19
|
+
currentTool: ClaudeCodeCurrentTool | null;
|
|
20
|
+
toolCalls: ClaudeCodeToolCall[];
|
|
21
|
+
result: ClaudeCodeResult | null;
|
|
22
|
+
error: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface ClaudeCodeEventReducerOptions {
|
|
25
|
+
keepEventHistory?: boolean;
|
|
26
|
+
maxEventHistory?: number;
|
|
27
|
+
trackAllToolCalls?: boolean;
|
|
28
|
+
}
|
|
29
|
+
type ClaudeCodeEventStateWithOptionalTracking = ClaudeCodeEventState & {
|
|
30
|
+
events?: ClaudeCodeEvent[];
|
|
31
|
+
allToolCalls?: ClaudeCodeAllToolCall[];
|
|
32
|
+
};
|
|
33
|
+
export declare function createClaudeCodeEventState(): ClaudeCodeEventState;
|
|
34
|
+
export declare function isClaudeCodeCoreEvent(event: ClaudeCodeEventExtended): event is ClaudeCodeEvent;
|
|
35
|
+
export declare function reduceClaudeCodeEventState<TState extends ClaudeCodeEventStateWithOptionalTracking>(previous: TState, event: ClaudeCodeEvent, options?: ClaudeCodeEventReducerOptions): TState;
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=event-state-reducer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-state-reducer.d.ts","sourceRoot":"","sources":["../../../../../src/src/workflow/claude-code/react/event-state-reducer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uBAAuB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE9F,MAAM,WAAW,qBAAqB;IACpC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB;IAC/D,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,OAAO,CAAC;IACnB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAC1C,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAAC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,6BAA6B;IAC5C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,KAAK,wCAAwC,GAAG,oBAAoB,GAAG;IACrE,MAAM,CAAC,EAAE,eAAe,EAAE,CAAC;IAC3B,YAAY,CAAC,EAAE,qBAAqB,EAAE,CAAC;CACxC,CAAC;AAkBF,wBAAgB,0BAA0B,IAAI,oBAAoB,CAWjE;AAED,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,uBAAuB,GAC7B,KAAK,IAAI,eAAe,CAE1B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,SAAS,wCAAwC,EAEvD,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,eAAe,EACtB,OAAO,GAAE,6BAAkC,GAC1C,MAAM,CA2FR"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
const CLAUDE_CODE_CORE_EVENT_TYPES = new Set([
|
|
2
|
+
"iteration_start",
|
|
3
|
+
"text_delta",
|
|
4
|
+
"text_complete",
|
|
5
|
+
"tool_call_start",
|
|
6
|
+
"tool_call_input",
|
|
7
|
+
"tool_call_complete",
|
|
8
|
+
"tool_result",
|
|
9
|
+
"iteration_complete",
|
|
10
|
+
"thinking_start",
|
|
11
|
+
"thinking_delta",
|
|
12
|
+
"thinking_complete",
|
|
13
|
+
"complete",
|
|
14
|
+
"error",
|
|
15
|
+
]);
|
|
16
|
+
export function createClaudeCodeEventState() {
|
|
17
|
+
return {
|
|
18
|
+
isRunning: false,
|
|
19
|
+
currentIteration: 0,
|
|
20
|
+
maxIterations: 20,
|
|
21
|
+
text: "",
|
|
22
|
+
currentTool: null,
|
|
23
|
+
toolCalls: [],
|
|
24
|
+
result: null,
|
|
25
|
+
error: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function isClaudeCodeCoreEvent(event) {
|
|
29
|
+
return CLAUDE_CODE_CORE_EVENT_TYPES.has(event.type);
|
|
30
|
+
}
|
|
31
|
+
export function reduceClaudeCodeEventState(previous, event, options = {}) {
|
|
32
|
+
const next = { ...previous };
|
|
33
|
+
if (options.keepEventHistory && Array.isArray(next.events)) {
|
|
34
|
+
next.events = [...(previous.events ?? []), event].slice(-(options.maxEventHistory ?? 100));
|
|
35
|
+
}
|
|
36
|
+
switch (event.type) {
|
|
37
|
+
case "iteration_start":
|
|
38
|
+
next.isRunning = true;
|
|
39
|
+
next.currentIteration = event.iteration;
|
|
40
|
+
next.maxIterations = event.maxIterations;
|
|
41
|
+
next.toolCalls = [];
|
|
42
|
+
next.currentTool = null;
|
|
43
|
+
break;
|
|
44
|
+
case "text_delta":
|
|
45
|
+
next.text = previous.text + event.content;
|
|
46
|
+
break;
|
|
47
|
+
case "text_complete":
|
|
48
|
+
next.text = event.content;
|
|
49
|
+
break;
|
|
50
|
+
case "tool_call_start":
|
|
51
|
+
next.currentTool = {
|
|
52
|
+
id: event.toolCallId,
|
|
53
|
+
name: event.toolName,
|
|
54
|
+
input: {},
|
|
55
|
+
};
|
|
56
|
+
break;
|
|
57
|
+
case "tool_call_complete":
|
|
58
|
+
next.currentTool = null;
|
|
59
|
+
next.toolCalls = [
|
|
60
|
+
...previous.toolCalls,
|
|
61
|
+
{
|
|
62
|
+
id: event.toolCallId,
|
|
63
|
+
name: event.toolName,
|
|
64
|
+
input: event.input,
|
|
65
|
+
},
|
|
66
|
+
];
|
|
67
|
+
break;
|
|
68
|
+
case "tool_result": {
|
|
69
|
+
next.toolCalls = previous.toolCalls.map((toolCall) => toolCall.id === event.toolCallId
|
|
70
|
+
? { ...toolCall, output: event.output, isError: event.isError }
|
|
71
|
+
: toolCall);
|
|
72
|
+
if (options.trackAllToolCalls && Array.isArray(next.allToolCalls)) {
|
|
73
|
+
const matchingToolCall = previous.toolCalls.find((toolCall) => toolCall.id === event.toolCallId);
|
|
74
|
+
next.allToolCalls = [
|
|
75
|
+
...(previous.allToolCalls ?? []),
|
|
76
|
+
{
|
|
77
|
+
iteration: event.iteration ?? previous.currentIteration,
|
|
78
|
+
id: event.toolCallId,
|
|
79
|
+
name: event.toolName,
|
|
80
|
+
input: matchingToolCall?.input ?? {},
|
|
81
|
+
output: event.output,
|
|
82
|
+
isError: event.isError,
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
case "iteration_complete":
|
|
89
|
+
next.currentTool = null;
|
|
90
|
+
break;
|
|
91
|
+
case "complete":
|
|
92
|
+
next.isRunning = false;
|
|
93
|
+
next.result = event.result;
|
|
94
|
+
next.currentTool = null;
|
|
95
|
+
break;
|
|
96
|
+
case "error":
|
|
97
|
+
next.error = event.message;
|
|
98
|
+
if (!event.recoverable) {
|
|
99
|
+
next.isRunning = false;
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
return next;
|
|
104
|
+
}
|
|
@@ -1,45 +1,13 @@
|
|
|
1
1
|
import type { ClaudeCodeEvent, ClaudeCodeResult } from "../types.js";
|
|
2
|
+
import { type ClaudeCodeAllToolCall, type ClaudeCodeEventState } from "./event-state-reducer.js";
|
|
2
3
|
/**
|
|
3
4
|
* State for Claude Code streaming
|
|
4
5
|
*/
|
|
5
|
-
export interface UseClaudeCodeStreamState {
|
|
6
|
+
export interface UseClaudeCodeStreamState extends ClaudeCodeEventState {
|
|
6
7
|
/** Whether currently connected to stream */
|
|
7
8
|
isConnected: boolean;
|
|
8
|
-
/** Whether agent is currently executing */
|
|
9
|
-
isRunning: boolean;
|
|
10
|
-
/** Current iteration number */
|
|
11
|
-
currentIteration: number;
|
|
12
|
-
/** Maximum iterations allowed */
|
|
13
|
-
maxIterations: number;
|
|
14
|
-
/** Accumulated text output */
|
|
15
|
-
text: string;
|
|
16
|
-
/** Current tool being executed (if any) */
|
|
17
|
-
currentTool: {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
input: Record<string, unknown>;
|
|
21
|
-
} | null;
|
|
22
|
-
/** Tool calls in current iteration */
|
|
23
|
-
toolCalls: Array<{
|
|
24
|
-
id: string;
|
|
25
|
-
name: string;
|
|
26
|
-
input: Record<string, unknown>;
|
|
27
|
-
output?: string;
|
|
28
|
-
isError?: boolean;
|
|
29
|
-
}>;
|
|
30
9
|
/** All tool calls across all iterations */
|
|
31
|
-
allToolCalls:
|
|
32
|
-
iteration: number;
|
|
33
|
-
id: string;
|
|
34
|
-
name: string;
|
|
35
|
-
input: Record<string, unknown>;
|
|
36
|
-
output?: string;
|
|
37
|
-
isError?: boolean;
|
|
38
|
-
}>;
|
|
39
|
-
/** Final result (when complete) */
|
|
40
|
-
result: ClaudeCodeResult | null;
|
|
41
|
-
/** Error message (if any) */
|
|
42
|
-
error: string | null;
|
|
10
|
+
allToolCalls: ClaudeCodeAllToolCall[];
|
|
43
11
|
/** Raw events (for debugging) */
|
|
44
12
|
events: ClaudeCodeEvent[];
|
|
45
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-claude-code-stream.d.ts","sourceRoot":"","sources":["../../../../../src/src/workflow/claude-code/react/use-claude-code-stream.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"use-claude-code-stream.d.ts","sourceRoot":"","sources":["../../../../../src/src/workflow/claude-code/react/use-claude-code-stream.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EACL,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,EAG1B,MAAM,0BAA0B,CAAC;AASlC;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,oBAAoB;IACpE,4CAA4C;IAC5C,WAAW,EAAE,OAAO,CAAC;IAErB,2CAA2C;IAC3C,YAAY,EAAE,qBAAqB,EAAE,CAAC;IAEtC,iCAAiC;IACjC,MAAM,EAAE,eAAe,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;IAEZ,uBAAuB;IACvB,KAAK,EAAE,MAAM,CAAC;IAEd,4BAA4B;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,8BAA8B;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,6BAA6B;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,2BAA2B;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,yBAAyB;IACzB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B,oCAAoC;IACpC,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB,gBAAgB;IAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC3C,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;CACjD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,0BAA0B,GAClC,wBAAwB,GAAG;IAC5B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAoIA;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,IAAI,CAAC,0BAA0B,EAAE,kBAAkB,GAAG,iBAAiB,CAAC,GAChF;IACD,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAGA"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
7
7
|
import { useCallback, useEffect, useRef, useState } from "../../../../react/react.js";
|
|
8
|
+
import { createClaudeCodeEventState, reduceClaudeCodeEventState, } from "./event-state-reducer.js";
|
|
8
9
|
import { REQUEST_ERROR } from "../../../errors/index.js";
|
|
9
10
|
/** Default delay before reconnecting after disconnect */
|
|
10
11
|
const DEFAULT_RECONNECT_DELAY_MS = 1_000;
|
|
@@ -48,16 +49,9 @@ const DEFAULT_MAX_EVENT_HISTORY = 100;
|
|
|
48
49
|
export function useClaudeCodeStream(options) {
|
|
49
50
|
const { url, runId, autoConnect = true, autoReconnect = true, maxReconnectAttempts = 5, reconnectDelay = DEFAULT_RECONNECT_DELAY_MS, keepEventHistory = false, maxEventHistory = DEFAULT_MAX_EVENT_HISTORY, onEvent, onConnect, onDisconnect, onError, onComplete, } = options;
|
|
50
51
|
const [state, setState] = useState({
|
|
52
|
+
...createClaudeCodeEventState(),
|
|
51
53
|
isConnected: false,
|
|
52
|
-
isRunning: false,
|
|
53
|
-
currentIteration: 0,
|
|
54
|
-
maxIterations: 20,
|
|
55
|
-
text: "",
|
|
56
|
-
currentTool: null,
|
|
57
|
-
toolCalls: [],
|
|
58
54
|
allToolCalls: [],
|
|
59
|
-
result: null,
|
|
60
|
-
error: null,
|
|
61
55
|
events: [],
|
|
62
56
|
});
|
|
63
57
|
const eventSourceRef = useRef(null);
|
|
@@ -67,76 +61,13 @@ export function useClaudeCodeStream(options) {
|
|
|
67
61
|
const processEvent = useCallback((event) => {
|
|
68
62
|
onEvent?.(event);
|
|
69
63
|
setState((prev) => {
|
|
70
|
-
const newState =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
newState.isRunning = true;
|
|
78
|
-
newState.currentIteration = event.iteration;
|
|
79
|
-
newState.maxIterations = event.maxIterations;
|
|
80
|
-
newState.toolCalls = [];
|
|
81
|
-
newState.currentTool = null;
|
|
82
|
-
break;
|
|
83
|
-
case "text_delta":
|
|
84
|
-
newState.text = prev.text + event.content;
|
|
85
|
-
break;
|
|
86
|
-
case "text_complete":
|
|
87
|
-
newState.text = event.content;
|
|
88
|
-
break;
|
|
89
|
-
case "tool_call_start":
|
|
90
|
-
newState.currentTool = {
|
|
91
|
-
id: event.toolCallId,
|
|
92
|
-
name: event.toolName,
|
|
93
|
-
input: {},
|
|
94
|
-
};
|
|
95
|
-
break;
|
|
96
|
-
case "tool_call_complete":
|
|
97
|
-
newState.currentTool = null;
|
|
98
|
-
newState.toolCalls = [
|
|
99
|
-
...prev.toolCalls,
|
|
100
|
-
{
|
|
101
|
-
id: event.toolCallId,
|
|
102
|
-
name: event.toolName,
|
|
103
|
-
input: event.input,
|
|
104
|
-
},
|
|
105
|
-
];
|
|
106
|
-
break;
|
|
107
|
-
case "tool_result":
|
|
108
|
-
// Update the tool call with its result
|
|
109
|
-
newState.toolCalls = prev.toolCalls.map((tc) => tc.id === event.toolCallId
|
|
110
|
-
? { ...tc, output: event.output, isError: event.isError }
|
|
111
|
-
: tc);
|
|
112
|
-
// Add to all tool calls
|
|
113
|
-
newState.allToolCalls = [
|
|
114
|
-
...prev.allToolCalls,
|
|
115
|
-
{
|
|
116
|
-
iteration: event.iteration || prev.currentIteration,
|
|
117
|
-
id: event.toolCallId,
|
|
118
|
-
name: event.toolName,
|
|
119
|
-
input: prev.toolCalls.find((tc) => tc.id === event.toolCallId)?.input || {},
|
|
120
|
-
output: event.output,
|
|
121
|
-
isError: event.isError,
|
|
122
|
-
},
|
|
123
|
-
];
|
|
124
|
-
break;
|
|
125
|
-
case "iteration_complete":
|
|
126
|
-
newState.currentTool = null;
|
|
127
|
-
break;
|
|
128
|
-
case "complete":
|
|
129
|
-
newState.isRunning = false;
|
|
130
|
-
newState.result = event.result;
|
|
131
|
-
newState.currentTool = null;
|
|
132
|
-
onComplete?.(event.result);
|
|
133
|
-
break;
|
|
134
|
-
case "error":
|
|
135
|
-
newState.error = event.message;
|
|
136
|
-
if (!event.recoverable) {
|
|
137
|
-
newState.isRunning = false;
|
|
138
|
-
}
|
|
139
|
-
break;
|
|
64
|
+
const newState = reduceClaudeCodeEventState(prev, event, {
|
|
65
|
+
keepEventHistory,
|
|
66
|
+
maxEventHistory,
|
|
67
|
+
trackAllToolCalls: true,
|
|
68
|
+
});
|
|
69
|
+
if (event.type === "complete") {
|
|
70
|
+
onComplete?.(event.result);
|
|
140
71
|
}
|
|
141
72
|
return newState;
|
|
142
73
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ClaudeCodeEventExtended, ClaudeCodeResult } from "../types.js";
|
|
2
|
+
import { type ClaudeCodeEventState } from "./event-state-reducer.js";
|
|
2
3
|
/**
|
|
3
4
|
* Pending approval state
|
|
4
5
|
*/
|
|
@@ -22,41 +23,15 @@ export interface PendingInput {
|
|
|
22
23
|
/**
|
|
23
24
|
* State for Claude Code WebSocket
|
|
24
25
|
*/
|
|
25
|
-
export interface UseClaudeCodeWebSocketState {
|
|
26
|
+
export interface UseClaudeCodeWebSocketState extends ClaudeCodeEventState {
|
|
26
27
|
/** Whether currently connected */
|
|
27
28
|
isConnected: boolean;
|
|
28
|
-
/** Whether agent is currently executing */
|
|
29
|
-
isRunning: boolean;
|
|
30
29
|
/** Whether agent was cancelled */
|
|
31
30
|
isCancelled: boolean;
|
|
32
|
-
/** Current iteration number */
|
|
33
|
-
currentIteration: number;
|
|
34
|
-
/** Maximum iterations allowed */
|
|
35
|
-
maxIterations: number;
|
|
36
|
-
/** Accumulated text output */
|
|
37
|
-
text: string;
|
|
38
|
-
/** Current tool being executed (if any) */
|
|
39
|
-
currentTool: {
|
|
40
|
-
id: string;
|
|
41
|
-
name: string;
|
|
42
|
-
input: Record<string, unknown>;
|
|
43
|
-
} | null;
|
|
44
|
-
/** Tool calls in current iteration */
|
|
45
|
-
toolCalls: Array<{
|
|
46
|
-
id: string;
|
|
47
|
-
name: string;
|
|
48
|
-
input: Record<string, unknown>;
|
|
49
|
-
output?: string;
|
|
50
|
-
isError?: boolean;
|
|
51
|
-
}>;
|
|
52
31
|
/** Pending approval requests */
|
|
53
32
|
pendingApprovals: PendingApproval[];
|
|
54
33
|
/** Pending input request (if any) */
|
|
55
34
|
pendingInput: PendingInput | null;
|
|
56
|
-
/** Final result (when complete) */
|
|
57
|
-
result: ClaudeCodeResult | null;
|
|
58
|
-
/** Error message (if any) */
|
|
59
|
-
error: string | null;
|
|
60
35
|
}
|
|
61
36
|
/**
|
|
62
37
|
* Options for useClaudeCodeWebSocket hook
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-claude-code-websocket.d.ts","sourceRoot":"","sources":["../../../../../src/src/workflow/claude-code/react/use-claude-code-websocket.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAGV,uBAAuB,EACvB,gBAAgB,EAEjB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"use-claude-code-websocket.d.ts","sourceRoot":"","sources":["../../../../../src/src/workflow/claude-code/react/use-claude-code-websocket.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAGV,uBAAuB,EACvB,gBAAgB,EAEjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,KAAK,oBAAoB,EAI1B,MAAM,0BAA0B,CAAC;AASlC;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,oBAAoB;IACvE,kCAAkC;IAClC,WAAW,EAAE,OAAO,CAAC;IAErB,kCAAkC;IAClC,WAAW,EAAE,OAAO,CAAC;IAErB,gCAAgC;IAChC,gBAAgB,EAAE,eAAe,EAAE,CAAC;IAEpC,qCAAqC;IACrC,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,6BAA6B;IAC7B,GAAG,EAAE,MAAM,CAAC;IAEZ,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IAEd,4BAA4B;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,8BAA8B;IAC9B,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB,6BAA6B;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAE9B,2BAA2B;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,yBAAyB;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,gBAAgB;IAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,uBAAuB,KAAK,IAAI,CAAC;IACnD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAChD,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAC;IACxD,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;CAChD;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C,2BAA2B;IAC3B,OAAO,EAAE,MAAM,IAAI,CAAC;IAEpB,gCAAgC;IAChC,UAAU,EAAE,MAAM,IAAI,CAAC;IAEvB,iCAAiC;IACjC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAElC,kCAAkC;IAClC,OAAO,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAEtC,iCAAiC;IACjC,MAAM,EAAE,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAEtD,sBAAsB;IACtB,SAAS,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,6BAA6B,GACrC,2BAA2B,GAAG,6BAA6B,CAkR7D"}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
7
7
|
import { useCallback, useEffect, useRef, useState } from "../../../../react/react.js";
|
|
8
|
+
import { createClaudeCodeEventState, isClaudeCodeCoreEvent, reduceClaudeCodeEventState, } from "./event-state-reducer.js";
|
|
8
9
|
import { NETWORK_ERROR, REQUEST_ERROR } from "../../../errors/index.js";
|
|
9
10
|
/** Default delay before reconnecting after disconnect */
|
|
10
11
|
const DEFAULT_RECONNECT_DELAY_MS = 1_000;
|
|
@@ -52,18 +53,11 @@ const DEFAULT_PING_INTERVAL_MS = 30_000;
|
|
|
52
53
|
export function useClaudeCodeWebSocket(options) {
|
|
53
54
|
const { url, runId, autoConnect = true, autoReconnect = true, maxReconnectAttempts = 5, reconnectDelay = DEFAULT_RECONNECT_DELAY_MS, pingInterval = DEFAULT_PING_INTERVAL_MS, onEvent, onConnect, onDisconnect, onError, onComplete, onApprovalRequest, onInputRequest, } = options;
|
|
54
55
|
const [state, setState] = useState({
|
|
56
|
+
...createClaudeCodeEventState(),
|
|
55
57
|
isConnected: false,
|
|
56
|
-
isRunning: false,
|
|
57
58
|
isCancelled: false,
|
|
58
|
-
currentIteration: 0,
|
|
59
|
-
maxIterations: 20,
|
|
60
|
-
text: "",
|
|
61
|
-
currentTool: null,
|
|
62
|
-
toolCalls: [],
|
|
63
59
|
pendingApprovals: [],
|
|
64
60
|
pendingInput: null,
|
|
65
|
-
result: null,
|
|
66
|
-
error: null,
|
|
67
61
|
});
|
|
68
62
|
const socketRef = useRef(null);
|
|
69
63
|
const reconnectAttemptsRef = useRef(0);
|
|
@@ -73,61 +67,15 @@ export function useClaudeCodeWebSocket(options) {
|
|
|
73
67
|
const processEvent = useCallback((event) => {
|
|
74
68
|
onEvent?.(event);
|
|
75
69
|
setState((prev) => {
|
|
76
|
-
const newState =
|
|
70
|
+
const newState = isClaudeCodeCoreEvent(event)
|
|
71
|
+
? reduceClaudeCodeEventState(prev, event)
|
|
72
|
+
: { ...prev };
|
|
77
73
|
switch (event.type) {
|
|
78
|
-
case "iteration_start":
|
|
79
|
-
newState.isRunning = true;
|
|
80
|
-
newState.currentIteration = event.iteration;
|
|
81
|
-
newState.maxIterations = event.maxIterations;
|
|
82
|
-
newState.toolCalls = [];
|
|
83
|
-
newState.currentTool = null;
|
|
84
|
-
break;
|
|
85
|
-
case "text_delta":
|
|
86
|
-
newState.text = prev.text + event.content;
|
|
87
|
-
break;
|
|
88
|
-
case "text_complete":
|
|
89
|
-
newState.text = event.content;
|
|
90
|
-
break;
|
|
91
|
-
case "tool_call_start":
|
|
92
|
-
newState.currentTool = {
|
|
93
|
-
id: event.toolCallId,
|
|
94
|
-
name: event.toolName,
|
|
95
|
-
input: {},
|
|
96
|
-
};
|
|
97
|
-
break;
|
|
98
|
-
case "tool_call_complete":
|
|
99
|
-
newState.currentTool = null;
|
|
100
|
-
newState.toolCalls = [
|
|
101
|
-
...prev.toolCalls,
|
|
102
|
-
{
|
|
103
|
-
id: event.toolCallId,
|
|
104
|
-
name: event.toolName,
|
|
105
|
-
input: event.input,
|
|
106
|
-
},
|
|
107
|
-
];
|
|
108
|
-
break;
|
|
109
|
-
case "tool_result":
|
|
110
|
-
newState.toolCalls = prev.toolCalls.map((tc) => tc.id === event.toolCallId
|
|
111
|
-
? { ...tc, output: event.output, isError: event.isError }
|
|
112
|
-
: tc);
|
|
113
|
-
break;
|
|
114
|
-
case "iteration_complete":
|
|
115
|
-
newState.currentTool = null;
|
|
116
|
-
break;
|
|
117
74
|
case "complete":
|
|
118
|
-
newState.isRunning = false;
|
|
119
|
-
newState.result = event.result;
|
|
120
|
-
newState.currentTool = null;
|
|
121
75
|
newState.pendingApprovals = [];
|
|
122
76
|
newState.pendingInput = null;
|
|
123
77
|
onComplete?.(event.result);
|
|
124
78
|
break;
|
|
125
|
-
case "error":
|
|
126
|
-
newState.error = event.message;
|
|
127
|
-
if (!event.recoverable) {
|
|
128
|
-
newState.isRunning = false;
|
|
129
|
-
}
|
|
130
|
-
break;
|
|
131
79
|
case "cancelled":
|
|
132
80
|
newState.isRunning = false;
|
|
133
81
|
newState.isCancelled = true;
|