@celljs/ta-client 4.7.0 → 4.9.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.
Files changed (36) hide show
  1. package/README.en.md +2 -2
  2. package/README.md +3 -3
  3. package/esm/common/session-reducer.d.ts +21 -11
  4. package/esm/common/session-reducer.js +55 -4
  5. package/esm/common/session-store.d.ts +50 -3
  6. package/esm/common/session-store.js +145 -15
  7. package/esm/common/ta-connection.d.ts +27 -2
  8. package/esm/common/ta-connection.js +96 -12
  9. package/lib/common/session-reducer.d.ts +21 -11
  10. package/lib/common/session-reducer.js +55 -4
  11. package/lib/common/session-store.d.ts +50 -3
  12. package/lib/common/session-store.js +145 -15
  13. package/lib/common/ta-connection.d.ts +27 -2
  14. package/lib/common/ta-connection.js +95 -11
  15. package/package.json +4 -3
  16. package/esm/common/index.js.map +0 -1
  17. package/esm/common/session-reducer.js.map +0 -1
  18. package/esm/common/session-store.js.map +0 -1
  19. package/esm/common/ta-connection.js.map +0 -1
  20. package/lib/common/index.d.ts.map +0 -1
  21. package/lib/common/index.js.map +0 -1
  22. package/lib/common/session-reducer.d.ts.map +0 -1
  23. package/lib/common/session-reducer.js.map +0 -1
  24. package/lib/common/session-reducer.spec.d.ts +0 -2
  25. package/lib/common/session-reducer.spec.d.ts.map +0 -1
  26. package/lib/common/session-reducer.spec.js +0 -100
  27. package/lib/common/session-reducer.spec.js.map +0 -1
  28. package/lib/common/session-store.d.ts.map +0 -1
  29. package/lib/common/session-store.js.map +0 -1
  30. package/lib/common/ta-connection.d.ts.map +0 -1
  31. package/lib/common/ta-connection.js.map +0 -1
  32. package/src/common/index.ts +0 -3
  33. package/src/common/session-reducer.spec.ts +0 -112
  34. package/src/common/session-reducer.ts +0 -185
  35. package/src/common/session-store.ts +0 -188
  36. package/src/common/ta-connection.ts +0 -325
@@ -1,112 +0,0 @@
1
- import { describe, expect, it } from 'bun:test';
2
- import type { TaEvent } from '@celljs/ta-protocol';
3
- import { SessionReducer, type SessionState } from './session-reducer';
4
-
5
- const run = (events: unknown[], from: SessionState = SessionReducer.initial()) => (events as TaEvent[]).reduce(SessionReducer.reduce, from);
6
- const assistant = (content: unknown[] = []) => ({ role: 'assistant', content });
7
-
8
- describe('SessionReducer', () => {
9
- it('is working from agent_start to agent_settled', () => {
10
- expect(run([{ type: 'agent_start' }]).working).toBe(true);
11
- expect(run([{ type: 'agent_start' }, { type: 'agent_end' }]).working).toBe(true);
12
- expect(run([{ type: 'agent_start' }, { type: 'agent_settled' }]).working).toBe(false);
13
- });
14
-
15
- it('builds an assistant message from deltas and takes the final one', () => {
16
- const streaming = run([
17
- { type: 'message_start', message: assistant() },
18
- { type: 'message_update', assistantMessageEvent: { type: 'text_start', contentIndex: 0 } },
19
- { type: 'message_update', assistantMessageEvent: { type: 'text_delta', contentIndex: 0, delta: 'Hel' } },
20
- { type: 'message_update', assistantMessageEvent: { type: 'text_delta', contentIndex: 0, delta: 'lo' } },
21
- ]);
22
- expect((streaming.messages[0] as { content?: unknown }).content).toEqual([{ type: 'text', text: 'Hello' }]);
23
- const final = assistant([{ type: 'text', text: 'Hello.' }]);
24
- expect(run([{ type: 'message_end', message: final }], streaming).messages).toEqual([final] as never);
25
- });
26
-
27
- it('keeps thinking and tool calls apart by content index', () => {
28
- const state = run([
29
- { type: 'message_start', message: assistant() },
30
- { type: 'message_update', assistantMessageEvent: { type: 'thinking_start', contentIndex: 0 } },
31
- { type: 'message_update', assistantMessageEvent: { type: 'thinking_delta', contentIndex: 0, delta: 'hm' } },
32
- { type: 'message_update', assistantMessageEvent: { type: 'toolcall_start', contentIndex: 1, id: 'c1', toolName: 'bash' } },
33
- ]);
34
- expect((state.messages[0] as { content?: unknown }).content).toEqual([
35
- { type: 'thinking', thinking: 'hm' },
36
- { type: 'toolCall', id: 'c1', name: 'bash', arguments: {} },
37
- ] as never);
38
- });
39
-
40
- it('takes the usage of a streaming message, and the arguments of a tool call as they come', () => {
41
- const usage = { input: 10, output: 3 };
42
- const state = run([
43
- { type: 'message_start', message: assistant() },
44
- { type: 'message_update', usage, assistantMessageEvent: { type: 'toolcall_start', contentIndex: 0, id: 'c1', toolName: 'bash' } },
45
- { type: 'message_update', usage, assistantMessageEvent: { type: 'toolcall_delta', contentIndex: 0, delta: '{"comm' } },
46
- { type: 'message_update', usage, assistantMessageEvent: { type: 'toolcall_delta', contentIndex: 0, delta: 'and":"ls"}' } },
47
- ]);
48
- expect(state.messages[0]).toMatchObject({ usage, content: [{ type: 'toolCall', id: 'c1', partialJson: '{"command":"ls"}' }] });
49
- });
50
-
51
- it('knows where a run starts, and when pi compacts or retries', () => {
52
- const started = run([{ type: 'message_start', message: { role: 'user', content: 'a' } }, { type: 'agent_start' }]);
53
- expect(started.runStart).toBe(1);
54
- const compacting = run([{ type: 'compaction_start', reason: 'threshold' }], started);
55
- expect(compacting.compacting).toBe('threshold');
56
- expect(run([{ type: 'compaction_end', reason: 'threshold', aborted: false, willRetry: false }], compacting).compacting).toBeUndefined();
57
- const retrying = run([{ type: 'auto_retry_start', attempt: 1, maxAttempts: 3, delayMs: 2000, errorMessage: 'overloaded' }], started);
58
- expect(retrying.retry).toEqual({ attempt: 1, maxAttempts: 3, delayMs: 2000, errorMessage: 'overloaded' });
59
- expect(run([{ type: 'auto_retry_end', success: true, attempt: 1 }], retrying).retry).toBeUndefined();
60
- expect(run([{ type: 'agent_settled', aborted: false }], retrying).retry).toBeUndefined();
61
- });
62
-
63
- it('follows a tool run', () => {
64
- const started = run([{ type: 'tool_execution_start', toolCallId: 'c1', toolName: 'bash', args: { command: 'ls' } }]);
65
- expect(started.tools.c1).toEqual({ toolName: 'bash', args: { command: 'ls' }, status: 'running' });
66
- const updated = run([{ type: 'tool_execution_update', toolCallId: 'c1', partialResult: 'a' }], started);
67
- expect(updated.tools.c1.result).toBe('a');
68
- const ended = run([{ type: 'tool_execution_end', toolCallId: 'c1', result: 'b', isError: true }], updated);
69
- expect(ended.tools.c1).toMatchObject({ result: 'b', status: 'error' });
70
- });
71
-
72
- it('tracks dialogs until they are resolved, and ignores the rest of the UI requests', () => {
73
- const dialog = { type: 'extension_ui_request', id: 'u1', method: 'confirm', title: 't', message: 'm' };
74
- const waiting = run([dialog, { type: 'extension_ui_request', id: 'u2', method: 'notify', message: 'hi' }]);
75
- expect(waiting.pendingUi).toEqual([dialog] as never);
76
- expect(run([{ type: 'ui_request_resolved', id: 'u1' }], waiting).pendingUi).toEqual([]);
77
- });
78
-
79
- it('tells nested tool calls by their parent', () => {
80
- const state = run([{ type: 'tool_execution_start', toolCallId: 'n1', toolName: 'read', args: {}, parentToolCallId: 'c1' }]);
81
- expect(state.tools.n1.parentToolCallId).toBe('c1');
82
- });
83
-
84
- it('tracks calls of client tools until they are resolved', () => {
85
- const request = { type: 'client_tool_request', id: 't1', toolName: 'pick', input: {} };
86
- const waiting = run([request]);
87
- expect(waiting.pendingClientTools).toEqual([request] as never);
88
- expect(run([{ type: 'client_tool_resolved', id: 't1' }], waiting).pendingClientTools).toEqual([]);
89
- });
90
-
91
- it('keeps the latest notices', () => {
92
- const notices = Array.from({ length: 25 }, (_, i) => ({ type: 'extension_ui_request', id: `n${i}`, method: 'notify', message: `m${i}` }));
93
- const state = run(notices);
94
- expect(state.notices).toHaveLength(20);
95
- expect(state.notices.at(-1)).toEqual({ id: 'n24', message: 'm24', type: 'info' });
96
- });
97
-
98
- it('keeps what extensions set with setStatus', () => {
99
- const set = run([{ type: 'extension_ui_request', id: 'u', method: 'setStatus', statusKey: 'k', statusText: 'on' }]);
100
- expect(set.status).toEqual({ k: 'on' });
101
- expect(run([{ type: 'extension_ui_request', id: 'u', method: 'setStatus', statusKey: 'k' }], set).status).toEqual({});
102
- });
103
-
104
- it('does not change the state for events it does not use', () => {
105
- const state = SessionReducer.initial();
106
- expect(run([{ type: 'turn_start' }], state)).toBe(state);
107
- });
108
-
109
- it('marks a closed session', () => {
110
- expect(run([{ type: 'agent_start' }, { type: 'session_closed' }])).toMatchObject({ closed: true, working: false });
111
- });
112
- });
@@ -1,185 +0,0 @@
1
- import type { RpcExtensionUIRequest, TaClientToolRequest, TaCommandResult, TaEvent } from '@celljs/ta-protocol';
2
-
3
- export type SessionMessage = TaCommandResult<'get_messages'>['messages'][number];
4
-
5
- export interface ToolRun {
6
- toolName: string;
7
- args: unknown;
8
- /** The latest partial result while it runs, then the result. */
9
- result?: unknown;
10
- status: 'running' | 'done' | 'error';
11
- /** Set for a call another tool made, such as a codemode script. */
12
- parentToolCallId?: string;
13
- }
14
-
15
- /** A message of `notify`. */
16
- export interface Notice {
17
- id: string;
18
- message: string;
19
- type: 'info' | 'warning' | 'error';
20
- }
21
-
22
- /** pi retries a failed request of the model by itself: `auto_retry_start`. */
23
- export interface RetryState {
24
- attempt: number;
25
- maxAttempts: number;
26
- delayMs: number;
27
- errorMessage: string;
28
- }
29
-
30
- /** What a UI shows of a session. */
31
- export interface SessionState {
32
- /** The agent is working, from the start of a run until it has settled. */
33
- working: boolean;
34
- messages: SessionMessage[];
35
- /** By tool call id. */
36
- tools: Record<string, ToolRun>;
37
- /** Dialogs waiting for an answer. */
38
- pendingUi: RpcExtensionUIRequest[];
39
- /** Calls of client tools waiting for a result. */
40
- pendingClientTools: TaClientToolRequest[];
41
- /** The latest messages of `notify`, oldest first. */
42
- notices: Notice[];
43
- /** What extensions show with `setStatus`. */
44
- status: Record<string, string>;
45
- closed: boolean;
46
- /** The index in `messages` where the run of now starts: unknown for a run that started before this client attached. */
47
- runStart?: number;
48
- /** pi compacts the conversation, for this reason. */
49
- compacting?: 'manual' | 'threshold' | 'overflow';
50
- /** pi waits to retry a failed request of the model. */
51
- retry?: RetryState;
52
- }
53
-
54
- interface ContentBlock {
55
- type: string;
56
- [key: string]: unknown;
57
- }
58
-
59
- type StreamDelta = { type: string; contentIndex?: number; delta?: string; id?: string; toolName?: string };
60
- type Retry = { attempt: number; maxAttempts: number; delayMs: number; errorMessage: string };
61
-
62
- export namespace SessionReducer {
63
- const DIALOGS = new Set(['select', 'confirm', 'input', 'editor']);
64
- const MAX_NOTICES = 20;
65
-
66
- export function initial(): SessionState {
67
- return { working: false, messages: [], tools: {}, pendingUi: [], pendingClientTools: [], notices: [], status: {}, closed: false };
68
- }
69
-
70
- /** The next state; the previous one stays valid, so that UIs can compare by identity. */
71
- export function reduce(state: SessionState, event: TaEvent): SessionState {
72
- switch (event.type) {
73
- case 'agent_start':
74
- return { ...state, working: true, runStart: state.messages.length };
75
- case 'agent_settled':
76
- return { ...state, working: false, retry: undefined };
77
- case 'message_start':
78
- return { ...state, messages: [...state.messages, event.message] };
79
- case 'message_update': {
80
- // The usage so far: some APIs count while they stream, others only at the end.
81
- const { usage } = event as { usage?: unknown };
82
- return withLastMessage(state, message => withUsage(applyDelta(message, event.assistantMessageEvent as StreamDelta), usage));
83
- }
84
- case 'message_end':
85
- return withLastMessage(state, () => event.message);
86
- case 'tool_execution_start': {
87
- const { parentToolCallId } = event as { parentToolCallId?: string };
88
- const run: ToolRun = { toolName: event.toolName, args: event.args, status: 'running' };
89
- return withTool(state, event.toolCallId, parentToolCallId ? { ...run, parentToolCallId } : run);
90
- }
91
- case 'tool_execution_update':
92
- return withTool(state, event.toolCallId, { ...state.tools[event.toolCallId], result: event.partialResult });
93
- case 'tool_execution_end':
94
- return withTool(state, event.toolCallId, { ...state.tools[event.toolCallId], result: event.result, status: event.isError ? 'error' : 'done' });
95
- case 'extension_ui_request':
96
- return applyUiRequest(state, event);
97
- case 'ui_request_resolved':
98
- return { ...state, pendingUi: state.pendingUi.filter(request => request.id !== event.id) };
99
- case 'client_tool_request':
100
- return { ...state, pendingClientTools: [...state.pendingClientTools, event] };
101
- case 'client_tool_resolved':
102
- return { ...state, pendingClientTools: state.pendingClientTools.filter(request => request.id !== event.id) };
103
- case 'compaction_start':
104
- return { ...state, compacting: event.reason };
105
- case 'compaction_end':
106
- return { ...state, compacting: undefined };
107
- case 'auto_retry_start': {
108
- const { attempt, maxAttempts, delayMs, errorMessage } = event as Retry;
109
- return { ...state, retry: { attempt, maxAttempts, delayMs, errorMessage } };
110
- }
111
- case 'auto_retry_end':
112
- return { ...state, retry: undefined };
113
- case 'session_closed':
114
- return { ...state, closed: true, working: false, pendingUi: [], pendingClientTools: [] };
115
- default:
116
- return state;
117
- }
118
- }
119
-
120
- function withLastMessage(state: SessionState, update: (message: SessionMessage) => SessionMessage): SessionState {
121
- if (!state.messages.length) {
122
- return state;
123
- }
124
- const last = state.messages.length - 1;
125
- return { ...state, messages: [...state.messages.slice(0, last), update(state.messages[last])] };
126
- }
127
-
128
- function withUsage(message: SessionMessage, usage: unknown): SessionMessage {
129
- if (!usage || message.role !== 'assistant' || (message as { usage?: unknown }).usage === usage) {
130
- return message;
131
- }
132
- return { ...message, usage } as SessionMessage;
133
- }
134
-
135
- function withTool(state: SessionState, toolCallId: string, run: ToolRun): SessionState {
136
- return { ...state, tools: { ...state.tools, [toolCallId]: run } };
137
- }
138
-
139
- function applyUiRequest(state: SessionState, request: RpcExtensionUIRequest): SessionState {
140
- if (DIALOGS.has(request.method)) {
141
- return { ...state, pendingUi: [...state.pendingUi, request] };
142
- }
143
- if (request.method === 'notify') {
144
- const notice: Notice = { id: request.id, message: request.message, type: request.notifyType ?? 'info' };
145
- return { ...state, notices: [...state.notices, notice].slice(-MAX_NOTICES) };
146
- }
147
- if (request.method === 'setStatus') {
148
- const { [request.statusKey]: _old, ...status } = state.status;
149
- return { ...state, status: request.statusText === undefined ? status : { ...status, [request.statusKey]: request.statusText } };
150
- }
151
- return state;
152
- }
153
-
154
- function applyDelta(message: SessionMessage, delta: StreamDelta): SessionMessage {
155
- if (delta.contentIndex === undefined || message.role !== 'assistant') {
156
- return message;
157
- }
158
- const content = [...(message.content as unknown as ContentBlock[])];
159
- const block = nextBlock(content[delta.contentIndex], delta);
160
- if (block) {
161
- content[delta.contentIndex] = block;
162
- }
163
- return { ...message, content } as unknown as SessionMessage;
164
- }
165
-
166
- function nextBlock(block: ContentBlock | undefined, delta: StreamDelta): ContentBlock | undefined {
167
- switch (delta.type) {
168
- case 'text_start':
169
- return { type: 'text', text: '' };
170
- case 'thinking_start':
171
- return { type: 'thinking', thinking: '' };
172
- case 'toolcall_start':
173
- return { type: 'toolCall', id: delta.id, name: delta.toolName, arguments: {} };
174
- case 'text_delta':
175
- return block && { ...block, text: `${block.text ?? ''}${delta.delta}` };
176
- case 'thinking_delta':
177
- return block && { ...block, thinking: `${block.thinking ?? ''}${delta.delta}` };
178
- case 'toolcall_delta':
179
- // The arguments as they come, JSON not yet whole: what the model has written so far.
180
- return block && { ...block, partialJson: `${block.partialJson ?? ''}${delta.delta}` };
181
- default:
182
- return undefined;
183
- }
184
- }
185
- }
@@ -1,188 +0,0 @@
1
- import type {
2
- RpcExtensionUIResponse,
3
- TaAttachResult,
4
- TaClientToolDefinition,
5
- TaClientToolRequest,
6
- TaClientToolResult,
7
- TaEvent,
8
- TaEventEnvelope,
9
- TaPromptInput,
10
- TaPromptReceipt,
11
- TaSessionInfo,
12
- } from '@celljs/ta-protocol';
13
- import { SessionReducer, type SessionState } from './session-reducer';
14
- import type { TaConnection } from './ta-connection';
15
-
16
- type Listener = (state: SessionState) => void;
17
-
18
- /**
19
- * A tool this client runs. Open the session with its `definition` in `clientTools`, and give the tool
20
- * to the store, which runs each call and sends the result. Its output is what the model reads; a
21
- * thrown error becomes a failed call.
22
- */
23
- export interface ClientTool {
24
- definition: TaClientToolDefinition;
25
- run(input: unknown, request: TaClientToolRequest): Promise<string> | string;
26
- }
27
-
28
- export interface SessionStoreOptions {
29
- /** The tools of the session this client runs. Other clients may run them too: the first result counts. */
30
- clientTools?: ClientTool[];
31
- }
32
-
33
- /**
34
- * The state of one open session on a client: for any UI to render and subscribe to. It catches up by
35
- * itself after a reconnect, from the events it missed or, if those are gone, from the session.
36
- */
37
- export class SessionStore {
38
- protected current = SessionReducer.initial();
39
- protected lastSeq?: number;
40
- protected readonly listeners = new Set<Listener>();
41
- protected readonly eventListeners = new Set<(event: TaEvent) => void>();
42
- protected readonly stop: (() => void)[] = [];
43
- protected readonly clientTools: Map<string, ClientTool>;
44
- /** Calls of client tools this store is running or answering now, by id. */
45
- protected readonly running = new Set<string>();
46
- /** Results not yet taken by the server, by call id. */
47
- protected readonly results = new Map<string, TaClientToolResult>();
48
-
49
- constructor(
50
- protected readonly connection: TaConnection,
51
- readonly sessionId: string,
52
- options: SessionStoreOptions = {},
53
- ) {
54
- this.clientTools = new Map((options.clientTools ?? []).map(tool => [tool.definition.name, tool]));
55
- }
56
-
57
- get state(): SessionState {
58
- return this.current;
59
- }
60
-
61
- /** Starts following the session. */
62
- async attach(): Promise<TaSessionInfo> {
63
- this.stop.push(
64
- this.connection.onEvents(events => this.apply(events)),
65
- this.connection.onOpen(() => void this.attachAgain()),
66
- );
67
- return (await this.attachAgain()).info;
68
- }
69
-
70
- /** Stops following it. The session goes on. */
71
- async detach(): Promise<void> {
72
- for (const stop of this.stop.splice(0)) {
73
- stop();
74
- }
75
- await this.connection.server.detach(this.sessionId);
76
- }
77
-
78
- subscribe(listener: Listener): () => void {
79
- this.listeners.add(listener);
80
- return () => this.listeners.delete(listener);
81
- }
82
-
83
- /** Each new event of the session, once the state has taken it in. */
84
- onEvent(listener: (event: TaEvent) => void): () => void {
85
- this.eventListeners.add(listener);
86
- return () => this.eventListeners.delete(listener);
87
- }
88
-
89
- /** Sends a message with a new id; a resend after a lost connection must reuse the id. */
90
- prompt(message: string, input: Partial<TaPromptInput> = {}): Promise<TaPromptReceipt> {
91
- return this.connection.server.prompt(this.sessionId, { clientMessageId: crypto.randomUUID(), ...input, message });
92
- }
93
-
94
- respondUi(response: RpcExtensionUIResponse): Promise<boolean> {
95
- return this.connection.server.respondUi(this.sessionId, response);
96
- }
97
-
98
- protected async attachAgain(): Promise<TaAttachResult> {
99
- const result = await this.connection.server.attach(this.sessionId, this.lastSeq);
100
- if (this.lastSeq === undefined || result.gap) {
101
- await this.reload();
102
- this.lastSeq = result.lastSeq;
103
- }
104
- this.apply(result.events);
105
- this.update({ ...this.current, pendingUi: result.pendingUi, pendingClientTools: result.pendingClientTools, working: result.info.isStreaming });
106
- return result;
107
- }
108
-
109
- protected async reload(): Promise<void> {
110
- const { messages } = await this.connection.server.getMessages(this.sessionId);
111
- this.update({ ...this.current, messages, tools: {} });
112
- }
113
-
114
- protected apply(events: TaEventEnvelope[]): void {
115
- let state = this.current;
116
- let replaced = false;
117
- const applied: TaEvent[] = [];
118
- for (const { sessionId, seq, event } of events) {
119
- if (sessionId !== this.sessionId || (this.lastSeq !== undefined && seq <= this.lastSeq)) {
120
- continue;
121
- }
122
- this.lastSeq = seq;
123
- state = SessionReducer.reduce(state, event);
124
- replaced ||= event.type === 'session_replaced';
125
- applied.push(event);
126
- }
127
- // One notification per batch: a UI renders once however many deltas arrived.
128
- this.update(state);
129
- for (const event of applied) {
130
- for (const listener of this.eventListeners) {
131
- listener(event);
132
- }
133
- }
134
- if (replaced) {
135
- void this.reload();
136
- }
137
- }
138
-
139
- protected update(state: SessionState): void {
140
- if (state !== this.current) {
141
- this.current = state;
142
- for (const listener of this.listeners) {
143
- listener(state);
144
- }
145
- this.runClientTools(state);
146
- }
147
- }
148
-
149
- protected runClientTools(state: SessionState): void {
150
- for (const request of state.pendingClientTools) {
151
- const tool = this.clientTools.get(request.toolName);
152
- if (tool && !this.running.has(request.id)) {
153
- this.running.add(request.id);
154
- void this.answer(tool, request);
155
- }
156
- }
157
- for (const id of this.results.keys()) {
158
- if (!state.pendingClientTools.some(request => request.id === id)) {
159
- this.results.delete(id);
160
- }
161
- }
162
- }
163
-
164
- /** Runs a call once: a result that could not be sent is sent again after a reconnect, not made again. */
165
- protected async answer(tool: ClientTool, request: TaClientToolRequest): Promise<void> {
166
- try {
167
- let result = this.results.get(request.id);
168
- if (!result) {
169
- result = await this.run(tool, request);
170
- this.results.set(request.id, result);
171
- }
172
- await this.connection.server.respondClientTool(this.sessionId, result);
173
- this.results.delete(request.id);
174
- } catch {
175
- // The connection was lost; the reconnect sends the result if the call still waits.
176
- } finally {
177
- this.running.delete(request.id);
178
- }
179
- }
180
-
181
- protected async run(tool: ClientTool, request: TaClientToolRequest): Promise<TaClientToolResult> {
182
- try {
183
- return { id: request.id, output: await tool.run(request.input, request) };
184
- } catch (error) {
185
- return { id: request.id, output: error instanceof Error ? error.message : String(error), isError: true };
186
- }
187
- }
188
- }