@yolk-sdk/agent 0.1.0-canary.20 → 0.1.0-canary.21

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 (55) hide show
  1. package/README.md +21 -1
  2. package/dist/client/state.d.mts +4 -2
  3. package/dist/client/state.d.mts.map +1 -1
  4. package/dist/client/state.mjs +42 -22
  5. package/dist/client/state.mjs.map +1 -1
  6. package/dist/loop/error.d.mts +3 -2
  7. package/dist/loop/error.d.mts.map +1 -1
  8. package/dist/loop/error.mjs +6 -3
  9. package/dist/loop/error.mjs.map +1 -1
  10. package/dist/loop/run.d.mts.map +1 -1
  11. package/dist/loop/run.mjs +17 -3
  12. package/dist/loop/run.mjs.map +1 -1
  13. package/dist/loop/services/loop-config.mjs +1 -1
  14. package/dist/loop/services/loop-config.mjs.map +1 -1
  15. package/dist/protocol/event.d.mts +17 -5
  16. package/dist/protocol/event.d.mts.map +1 -1
  17. package/dist/protocol/event.mjs +24 -3
  18. package/dist/protocol/event.mjs.map +1 -1
  19. package/dist/protocol/index.d.mts +2 -2
  20. package/dist/protocol/index.d.mts.map +1 -1
  21. package/dist/protocol/index.mjs +2 -2
  22. package/dist/providers/anthropic/claude-provider.d.mts.map +1 -1
  23. package/dist/providers/anthropic/claude-provider.mjs +36 -15
  24. package/dist/providers/anthropic/claude-provider.mjs.map +1 -1
  25. package/dist/providers/openai/codex-provider.d.mts.map +1 -1
  26. package/dist/providers/openai/codex-provider.mjs +59 -17
  27. package/dist/providers/openai/codex-provider.mjs.map +1 -1
  28. package/dist/providers/openai/provider.d.mts.map +1 -1
  29. package/dist/providers/openai/provider.mjs +16 -10
  30. package/dist/providers/openai/provider.mjs.map +1 -1
  31. package/dist/providers/provider-error.d.mts +32 -0
  32. package/dist/providers/provider-error.d.mts.map +1 -0
  33. package/dist/providers/provider-error.mjs +91 -0
  34. package/dist/providers/provider-error.mjs.map +1 -0
  35. package/dist/react/chat-core.d.mts +3 -1
  36. package/dist/react/chat-core.d.mts.map +1 -1
  37. package/dist/react/chat-core.mjs +42 -6
  38. package/dist/react/chat-core.mjs.map +1 -1
  39. package/dist/react/chat-items.d.mts +8 -2
  40. package/dist/react/chat-items.d.mts.map +1 -1
  41. package/dist/react/chat-items.mjs +16 -9
  42. package/dist/react/chat-items.mjs.map +1 -1
  43. package/package.json +1 -1
  44. package/src/client/state.ts +43 -18
  45. package/src/loop/error.ts +6 -3
  46. package/src/loop/run.ts +27 -4
  47. package/src/loop/services/loop-config.ts +1 -1
  48. package/src/protocol/event.ts +26 -2
  49. package/src/protocol/index.ts +2 -0
  50. package/src/providers/anthropic/claude-provider.ts +51 -22
  51. package/src/providers/openai/codex-provider.ts +81 -19
  52. package/src/providers/openai/provider.ts +22 -18
  53. package/src/providers/provider-error.ts +213 -0
  54. package/src/react/chat-core.ts +46 -5
  55. package/src/react/chat-items.ts +10 -3
@@ -1,7 +1,9 @@
1
1
  import {
2
2
  hitlResponseEvent,
3
+ type AgentError,
3
4
  type AgentEvent,
4
5
  type AgentMessage,
6
+ type AgentRetry,
5
7
  type Content,
6
8
  type HitlResponse,
7
9
  type UserMessage
@@ -31,6 +33,8 @@ export type AgentRunStatus = 'idle' | 'running' | 'waiting' | 'done' | 'error' |
31
33
  export type AgentChatState = {
32
34
  readonly status: AgentRunStatus
33
35
  readonly error: string | null
36
+ readonly errorInfo: AgentError | null
37
+ readonly retryInfo: AgentRetry | null
34
38
  readonly chatMessages: ReadonlyArray<AgentChatMessage>
35
39
  readonly sessionEvents: ReadonlyArray<AgentChatSessionEvent>
36
40
  readonly seenEventIds: ReadonlyArray<string>
@@ -39,6 +43,8 @@ export type AgentChatState = {
39
43
  export const initialAgentChatState: AgentChatState = {
40
44
  status: 'idle',
41
45
  error: null,
46
+ errorInfo: null,
47
+ retryInfo: null,
42
48
  chatMessages: [],
43
49
  sessionEvents: [],
44
50
  seenEventIds: []
@@ -52,6 +58,9 @@ const rememberEvent = (state: AgentChatState, event: AgentEvent): AgentChatState
52
58
  ? state
53
59
  : { ...state, seenEventIds: [...state.seenEventIds, event.eventId] }
54
60
 
61
+ const clearRetryInfo = (state: AgentChatState): AgentChatState =>
62
+ state.retryInfo === null ? state : { ...state, retryInfo: null }
63
+
55
64
  export type AgentChatAction =
56
65
  | { readonly _tag: 'HydrateMessage'; readonly message: AgentMessage }
57
66
  | { readonly _tag: 'Submit'; readonly message: UserMessage }
@@ -73,13 +82,17 @@ export const reduceAgentChatState = (
73
82
  return {
74
83
  ...state,
75
84
  chatMessages: appendProtocolMessage(state.chatMessages, action.message),
76
- error: null
85
+ error: null,
86
+ errorInfo: null,
87
+ retryInfo: null
77
88
  }
78
89
  case 'Submit':
79
90
  return {
80
91
  ...state,
81
92
  status: 'running',
82
93
  error: null,
94
+ errorInfo: null,
95
+ retryInfo: null,
83
96
  seenEventIds: [],
84
97
  chatMessages: appendProtocolMessage(state.chatMessages, action.message),
85
98
  sessionEvents: [
@@ -92,6 +105,8 @@ export const reduceAgentChatState = (
92
105
  ...state,
93
106
  chatMessages: appendProtocolMessage(state.chatMessages, action.message),
94
107
  error: null,
108
+ errorInfo: null,
109
+ retryInfo: null,
95
110
  sessionEvents: [
96
111
  ...state.sessionEvents,
97
112
  ProtocolMessageAppended.make({ message: action.message })
@@ -102,6 +117,8 @@ export const reduceAgentChatState = (
102
117
  ...state,
103
118
  status: 'running',
104
119
  error: null,
120
+ errorInfo: null,
121
+ retryInfo: null,
105
122
  seenEventIds: [],
106
123
  chatMessages: applyAgentEventToChatMessages(
107
124
  state.chatMessages,
@@ -118,6 +135,8 @@ export const reduceAgentChatState = (
118
135
  return {
119
136
  ...state,
120
137
  error: null,
138
+ errorInfo: null,
139
+ retryInfo: null,
121
140
  chatMessages: next.messages,
122
141
  sessionEvents: [
123
142
  ...state.sessionEvents,
@@ -139,6 +158,8 @@ export const reduceAgentChatState = (
139
158
  ...state,
140
159
  status: 'running',
141
160
  error: null,
161
+ errorInfo: null,
162
+ retryInfo: null,
142
163
  seenEventIds: [],
143
164
  chatMessages: next.messages,
144
165
  sessionEvents: [
@@ -161,6 +182,8 @@ export const reduceAgentChatState = (
161
182
  ...state,
162
183
  status: 'running',
163
184
  error: null,
185
+ errorInfo: null,
186
+ retryInfo: null,
164
187
  seenEventIds: [],
165
188
  chatMessages: next.messages,
166
189
  sessionEvents: [
@@ -185,6 +208,8 @@ export const reduceAgentChatState = (
185
208
  ...state,
186
209
  status: 'running',
187
210
  error: null,
211
+ errorInfo: null,
212
+ retryInfo: null,
188
213
  chatMessages: applyAgentEventToChatMessages(state.chatMessages, action.event, action)
189
214
  },
190
215
  action.event
@@ -195,6 +220,8 @@ export const reduceAgentChatState = (
195
220
  ...state,
196
221
  status: 'error',
197
222
  error: action.event.message,
223
+ errorInfo: action.event,
224
+ retryInfo: null,
198
225
  chatMessages: applyAgentEventToChatMessages(state.chatMessages, action.event, action)
199
226
  },
200
227
  action.event
@@ -205,6 +232,8 @@ export const reduceAgentChatState = (
205
232
  ...state,
206
233
  status: 'done',
207
234
  error: null,
235
+ errorInfo: null,
236
+ retryInfo: null,
208
237
  chatMessages: applyAgentEventToChatMessages(state.chatMessages, action.event, action)
209
238
  },
210
239
  action.event
@@ -215,13 +244,23 @@ export const reduceAgentChatState = (
215
244
  ...state,
216
245
  status: 'waiting',
217
246
  error: null,
247
+ errorInfo: null,
248
+ retryInfo: null,
218
249
  chatMessages: applyAgentEventToChatMessages(state.chatMessages, action.event, action)
219
250
  },
220
251
  action.event
221
252
  )
222
- case 'AssistantMessage':
223
253
  case 'AgentRetry':
254
+ return rememberEvent(
255
+ {
256
+ ...state,
257
+ retryInfo: action.event,
258
+ chatMessages: applyAgentEventToChatMessages(state.chatMessages, action.event, action)
259
+ },
260
+ action.event
261
+ )
224
262
  case 'CompactionEnd':
263
+ case 'AssistantMessage':
225
264
  case 'CompactionStart':
226
265
  case 'LLMReasoningDelta':
227
266
  case 'LLMStreamEnd':
@@ -246,10 +285,10 @@ export const reduceAgentChatState = (
246
285
  case 'TurnStart':
247
286
  case 'UsageUpdate':
248
287
  return rememberEvent(
249
- {
288
+ clearRetryInfo({
250
289
  ...state,
251
290
  chatMessages: applyAgentEventToChatMessages(state.chatMessages, action.event, action)
252
- },
291
+ }),
253
292
  action.event
254
293
  )
255
294
  }
@@ -259,11 +298,13 @@ export const reduceAgentChatState = (
259
298
  ...state,
260
299
  status: 'error',
261
300
  error: action.message,
301
+ errorInfo: null,
302
+ retryInfo: null,
262
303
  chatMessages: markChatError(state.chatMessages, action.message)
263
304
  }
264
305
  }
265
306
  case 'Abort':
266
- return { ...state, status: 'aborted', error: null }
307
+ return { ...state, status: 'aborted', error: null, errorInfo: null, retryInfo: null }
267
308
  }
268
309
  }
269
310
 
@@ -1,6 +1,7 @@
1
1
  import { Array as Arr, Option } from 'effect'
2
2
  import {
3
3
  contentText,
4
+ type AgentRetry,
4
5
  type QuestionRequest,
5
6
  type QuestionResponse,
6
7
  type ToolApprovalRequest,
@@ -100,6 +101,7 @@ export type AgentChatItem =
100
101
  }
101
102
  | { readonly _tag: 'UserDraft'; readonly id: string; readonly text: string }
102
103
  | { readonly _tag: 'AssistantDraft'; readonly id: string; readonly text: string }
104
+ | { readonly _tag: 'Retry'; readonly id: string; readonly retry: AgentRetry }
103
105
  | { readonly _tag: 'AssistantStatus'; readonly id: string; readonly label: string }
104
106
  | { readonly _tag: 'Error'; readonly id: string; readonly message: string }
105
107
 
@@ -107,6 +109,7 @@ export type BuildAgentChatItemsInput = {
107
109
  readonly messages: ReadonlyArray<AgentChatMessage>
108
110
  readonly isRunning: boolean
109
111
  readonly activeToolLabel: Option.Option<string>
112
+ readonly retryInfo?: AgentRetry | null
110
113
  }
111
114
 
112
115
  export const dedupeAgentChatToolRunItems = (
@@ -122,8 +125,7 @@ export const dedupeAgentChatToolRunItems = (
122
125
  }
123
126
 
124
127
  return items.filter(
125
- (item, index) =>
126
- item._tag !== 'ToolRun' || latestIndexByToolCallId.get(item.call.id) === index
128
+ (item, index) => item._tag !== 'ToolRun' || latestIndexByToolCallId.get(item.call.id) === index
127
129
  )
128
130
  }
129
131
 
@@ -313,7 +315,8 @@ const itemFromPart = (
313
315
  export const buildAgentChatItems = ({
314
316
  messages,
315
317
  isRunning,
316
- activeToolLabel
318
+ activeToolLabel,
319
+ retryInfo
317
320
  }: BuildAgentChatItemsInput): ReadonlyArray<AgentChatItem> => {
318
321
  const items = dedupeAgentChatToolRunItems(
319
322
  Arr.getSomes(
@@ -322,6 +325,10 @@ export const buildAgentChatItems = ({
322
325
  )
323
326
 
324
327
  if (isRunning) {
328
+ if (retryInfo !== undefined && retryInfo !== null) {
329
+ return [...items, { _tag: 'Retry', id: 'agent-retry', retry: retryInfo }]
330
+ }
331
+
325
332
  return [
326
333
  ...items,
327
334
  {