@yolk-sdk/agent 0.1.0-canary.21 → 0.1.0-canary.23
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/README.md +36 -8
- package/dist/loop/run.d.mts.map +1 -1
- package/dist/loop/run.mjs +38 -19
- package/dist/loop/run.mjs.map +1 -1
- package/dist/protocol/content.d.mts +2 -1
- package/dist/protocol/content.d.mts.map +1 -1
- package/dist/protocol/content.mjs +8 -1
- package/dist/protocol/content.mjs.map +1 -1
- package/dist/protocol/index.d.mts +3 -3
- package/dist/protocol/index.d.mts.map +1 -1
- package/dist/protocol/index.mjs +3 -3
- package/dist/protocol/message.d.mts +20 -1
- package/dist/protocol/message.d.mts.map +1 -1
- package/dist/protocol/message.mjs +59 -1
- package/dist/protocol/message.mjs.map +1 -1
- package/dist/providers/anthropic/claude-provider.d.mts +6 -0
- package/dist/providers/anthropic/claude-provider.d.mts.map +1 -1
- package/dist/providers/anthropic/claude-provider.mjs +47 -24
- package/dist/providers/anthropic/claude-provider.mjs.map +1 -1
- package/dist/providers/openai/codex-provider.d.mts.map +1 -1
- package/dist/providers/openai/codex-provider.mjs +4 -2
- package/dist/providers/openai/codex-provider.mjs.map +1 -1
- package/dist/providers/openai/provider.d.mts.map +1 -1
- package/dist/providers/openai/provider.mjs +4 -2
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/transcript.d.mts +9 -0
- package/dist/providers/transcript.d.mts.map +1 -0
- package/dist/providers/transcript.mjs +17 -0
- package/dist/providers/transcript.mjs.map +1 -0
- package/package.json +1 -1
- package/src/loop/run.ts +56 -17
- package/src/protocol/content.ts +11 -0
- package/src/protocol/index.ts +10 -1
- package/src/protocol/message.ts +127 -0
- package/src/providers/anthropic/claude-provider.ts +78 -34
- package/src/providers/openai/codex-provider.ts +4 -1
- package/src/providers/openai/provider.ts +4 -2
- package/src/providers/transcript.ts +24 -0
- package/src/tools/README.md +3 -2
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
AgentUsage,
|
|
13
13
|
ToolCall,
|
|
14
14
|
attachmentSourceDataUrl,
|
|
15
|
+
attachmentSourceUrl,
|
|
15
16
|
assistantContent,
|
|
16
17
|
assistantHostToolCalls,
|
|
17
18
|
contentParts,
|
|
@@ -43,6 +44,7 @@ import {
|
|
|
43
44
|
providerFailureCause,
|
|
44
45
|
providerFailureRetryable
|
|
45
46
|
} from '../provider-error.ts'
|
|
47
|
+
import { validateProviderTranscript } from '../transcript.ts'
|
|
46
48
|
|
|
47
49
|
export type OpenAiCodexReasoningSummary = 'auto' | 'concise' | 'detailed'
|
|
48
50
|
|
|
@@ -263,7 +265,7 @@ const userPartToCodexInputPart = (
|
|
|
263
265
|
case 'Text':
|
|
264
266
|
return Effect.succeed({ type: 'input_text', text: part.text })
|
|
265
267
|
case 'Image':
|
|
266
|
-
return Option.match(
|
|
268
|
+
return Option.match(attachmentSourceUrl(part.source, part.mimeType), {
|
|
267
269
|
onNone: () => Effect.fail(unsupportedContentError('Unresolved image source')),
|
|
268
270
|
onSome: url => Effect.succeed({
|
|
269
271
|
type: 'input_image',
|
|
@@ -377,6 +379,7 @@ export const toOpenAiCodexRequestBody = (
|
|
|
377
379
|
}
|
|
378
380
|
): Effect.Effect<OpenAiCodexRequestBody, LLMError> =>
|
|
379
381
|
Effect.gen(function* () {
|
|
382
|
+
yield* validateProviderTranscript(request.messages)
|
|
380
383
|
const input = Arr.flatten(yield* Effect.forEach(request.messages, messageToCodexInput))
|
|
381
384
|
|
|
382
385
|
const body: Omit<OpenAiCodexRequestBody, 'tools'> = {
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
AgentInputUsage,
|
|
13
13
|
AgentOutputUsage,
|
|
14
14
|
AgentUsage,
|
|
15
|
-
attachmentSourceDataUrl,
|
|
16
15
|
attachmentSourceText,
|
|
16
|
+
attachmentSourceUrl,
|
|
17
17
|
assistantContent,
|
|
18
18
|
assistantHostToolCalls,
|
|
19
19
|
isTextDocumentMimeType,
|
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
providerFailureCause,
|
|
41
41
|
providerFailureRetryable
|
|
42
42
|
} from '../provider-error.ts'
|
|
43
|
+
import { validateProviderTranscript } from '../transcript.ts'
|
|
43
44
|
|
|
44
45
|
export type OpenAiProviderConfig = {
|
|
45
46
|
readonly chatCompletionsUrl?: string
|
|
@@ -228,7 +229,7 @@ const contentPartToUserPart = (
|
|
|
228
229
|
case 'Text':
|
|
229
230
|
return Effect.succeed({ type: 'text', text: part.text })
|
|
230
231
|
case 'Image':
|
|
231
|
-
return Option.match(
|
|
232
|
+
return Option.match(attachmentSourceUrl(part.source, part.mimeType), {
|
|
232
233
|
onNone: () => Effect.fail(unsupportedContentError('Unresolved image source')),
|
|
233
234
|
onSome: url => Effect.succeed({ type: 'image_url', image_url: { url } })
|
|
234
235
|
})
|
|
@@ -340,6 +341,7 @@ export const toOpenAiRequestBody = (
|
|
|
340
341
|
config?: { readonly maxCompletionTokens?: number }
|
|
341
342
|
): Effect.Effect<OpenAiRequestBody, LLMError> =>
|
|
342
343
|
Effect.gen(function* () {
|
|
344
|
+
yield* validateProviderTranscript(request.messages)
|
|
343
345
|
const systemMessage: OpenAiMessage = { role: 'system', content: request.systemPrompt }
|
|
344
346
|
const requestMessages = yield* Effect.forEach(request.messages, toOpenAiMessage)
|
|
345
347
|
const messages = [systemMessage, ...requestMessages]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Effect } from 'effect'
|
|
2
|
+
import {
|
|
3
|
+
validateNoDanglingHostToolCalls,
|
|
4
|
+
type AgentMessage
|
|
5
|
+
} from '@yolk-sdk/agent/protocol'
|
|
6
|
+
import { LLMError } from '@yolk-sdk/agent/loop'
|
|
7
|
+
|
|
8
|
+
export const validateProviderTranscript = (
|
|
9
|
+
messages: ReadonlyArray<AgentMessage>
|
|
10
|
+
): Effect.Effect<void, LLMError> => {
|
|
11
|
+
const validation = validateNoDanglingHostToolCalls(messages)
|
|
12
|
+
|
|
13
|
+
if (validation._tag === 'Valid') {
|
|
14
|
+
return Effect.void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return Effect.fail(
|
|
18
|
+
new LLMError({
|
|
19
|
+
cause: 'validation_error',
|
|
20
|
+
message: validation.message,
|
|
21
|
+
retryable: false
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
}
|
package/src/tools/README.md
CHANGED
|
@@ -41,8 +41,9 @@ return Effect.fail(modelVisibleToolError({
|
|
|
41
41
|
}))
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
Thrown `ToolError`s become model-visible failed tool results plus `ToolExecutionError` events,
|
|
45
|
+
so keep messages safe and non-secret. Reserve stream failure for provider/runtime defects,
|
|
46
|
+
aborts, and implementation bugs outside typed tool execution.
|
|
46
47
|
|
|
47
48
|
## Task subagents
|
|
48
49
|
|