@yolk-sdk/agent 0.1.0-canary.19 → 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.
- package/README.md +25 -1
- package/dist/client/attachments.d.mts +8 -0
- package/dist/client/attachments.d.mts.map +1 -0
- package/dist/client/attachments.mjs +36 -0
- package/dist/client/attachments.mjs.map +1 -0
- package/dist/client/index.d.mts +2 -1
- package/dist/client/index.mjs +2 -1
- package/dist/client/state.d.mts +4 -2
- package/dist/client/state.d.mts.map +1 -1
- package/dist/client/state.mjs +42 -22
- package/dist/client/state.mjs.map +1 -1
- package/dist/client/transport.d.mts +1 -1
- package/dist/client/transport.mjs +1 -1
- package/dist/compaction/transformer.d.mts +1 -1
- package/dist/loop/error.d.mts +3 -2
- package/dist/loop/error.d.mts.map +1 -1
- package/dist/loop/error.mjs +6 -3
- package/dist/loop/error.mjs.map +1 -1
- package/dist/loop/llm-event.d.mts +1 -1
- package/dist/loop/llm-event.mjs +1 -1
- package/dist/loop/run.d.mts +1 -1
- package/dist/loop/run.d.mts.map +1 -1
- package/dist/loop/run.mjs +18 -4
- package/dist/loop/run.mjs.map +1 -1
- package/dist/loop/services/context-transformer.d.mts +1 -1
- package/dist/loop/services/llm-provider.d.mts +1 -1
- package/dist/loop/services/loop-config.mjs +1 -1
- package/dist/loop/services/loop-config.mjs.map +1 -1
- package/dist/loop/services/tool-executor.d.mts +1 -1
- package/dist/loop/testing/faux-provider.mjs +1 -1
- package/dist/loop/testing/test-tool-executor.mjs +1 -1
- package/dist/protocol/content.d.mts +15 -1
- package/dist/protocol/content.d.mts.map +1 -1
- package/dist/protocol/content.mjs +76 -1
- package/dist/protocol/content.mjs.map +1 -1
- package/dist/protocol/event.d.mts +17 -5
- package/dist/protocol/event.d.mts.map +1 -1
- package/dist/protocol/event.mjs +24 -3
- package/dist/protocol/event.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/providers/anthropic/claude-provider.d.mts.map +1 -1
- package/dist/providers/anthropic/claude-provider.mjs +48 -17
- package/dist/providers/anthropic/claude-provider.mjs.map +1 -1
- package/dist/providers/openai/codex-provider.d.mts +1 -1
- package/dist/providers/openai/codex-provider.d.mts.map +1 -1
- package/dist/providers/openai/codex-provider.mjs +60 -18
- 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 +28 -12
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/provider-error.d.mts +32 -0
- package/dist/providers/provider-error.d.mts.map +1 -0
- package/dist/providers/provider-error.mjs +91 -0
- package/dist/providers/provider-error.mjs.map +1 -0
- package/dist/react/chat-core.d.mts +3 -1
- package/dist/react/chat-core.d.mts.map +1 -1
- package/dist/react/chat-core.mjs +42 -6
- package/dist/react/chat-core.mjs.map +1 -1
- package/dist/react/chat-items.d.mts +8 -2
- package/dist/react/chat-items.d.mts.map +1 -1
- package/dist/react/chat-items.mjs +17 -10
- package/dist/react/chat-items.mjs.map +1 -1
- package/dist/react/chat-messages.mjs +1 -1
- package/dist/react/chat-session-events.d.mts +1 -1
- package/dist/react/chat-session-events.mjs +1 -1
- package/dist/react/use-agent-chat.mjs +1 -1
- package/dist/runtime/error.d.mts +1 -1
- package/dist/runtime/error.mjs +1 -1
- package/dist/runtime/run-runtime.d.mts +1 -1
- package/dist/runtime/session-event-store.d.mts +1 -1
- package/dist/runtime/session-event-store.mjs +1 -1
- package/dist/tools/question.d.mts +1 -1
- package/dist/tools/question.mjs +1 -1
- package/dist/tools/registry.d.mts +1 -1
- package/dist/tools/registry.mjs +1 -1
- package/dist/tools/task.d.mts +1 -1
- package/dist/tools/task.mjs +1 -1
- package/dist/voice/tool-bridge.mjs +1 -1
- package/package.json +1 -1
- package/src/client/attachments.ts +45 -0
- package/src/client/index.ts +1 -0
- package/src/client/state.ts +43 -18
- package/src/loop/error.ts +6 -3
- package/src/loop/run.ts +27 -4
- package/src/loop/services/loop-config.ts +1 -1
- package/src/protocol/content.ts +129 -0
- package/src/protocol/event.ts +26 -2
- package/src/protocol/index.ts +8 -0
- package/src/providers/anthropic/claude-provider.ts +74 -23
- package/src/providers/openai/codex-provider.ts +81 -19
- package/src/providers/openai/provider.ts +45 -19
- package/src/providers/provider-error.ts +213 -0
- package/src/react/chat-core.ts +46 -5
- package/src/react/chat-items.ts +10 -3
|
@@ -6,17 +6,28 @@ import * as Schema from "effect/Schema";
|
|
|
6
6
|
//#region src/protocol/event.d.ts
|
|
7
7
|
declare const SubagentStatus: Schema.Literals<readonly ["running", "completed", "error"]>;
|
|
8
8
|
type SubagentStatus = typeof SubagentStatus.Type;
|
|
9
|
-
declare const AgentErrorCode: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
9
|
+
declare const AgentErrorCode: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "overloaded", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
10
10
|
type AgentErrorCode = typeof AgentErrorCode.Type;
|
|
11
|
+
declare const ProviderFailureKind: Schema.Literals<readonly ["rate_limit", "overloaded", "server_error", "network", "stream", "auth", "context_overflow", "invalid_response", "unknown"]>;
|
|
12
|
+
type ProviderFailureKind = typeof ProviderFailureKind.Type;
|
|
13
|
+
declare const ProviderErrorInfo_base: Schema.Class<ProviderErrorInfo, Schema.Struct<{
|
|
14
|
+
readonly provider: Schema.Trimmed;
|
|
15
|
+
readonly kind: Schema.Literals<readonly ["rate_limit", "overloaded", "server_error", "network", "stream", "auth", "context_overflow", "invalid_response", "unknown"]>;
|
|
16
|
+
readonly status: Schema.optional<Schema.Number>;
|
|
17
|
+
readonly providerCode: Schema.optional<Schema.String>;
|
|
18
|
+
readonly retryAfterMs: Schema.optional<Schema.Number>;
|
|
19
|
+
}>, {}>;
|
|
20
|
+
declare class ProviderErrorInfo extends ProviderErrorInfo_base {}
|
|
11
21
|
declare const AgentStart_base: Schema.Class<AgentStart, Schema.TaggedStruct<"AgentStart", {
|
|
12
22
|
readonly eventId: Schema.optional<Schema.Trimmed>;
|
|
13
23
|
readonly createdAtMs: Schema.optional<Schema.Number>;
|
|
14
24
|
}>, {}>;
|
|
15
25
|
declare class AgentStart extends AgentStart_base {}
|
|
16
26
|
declare const AgentError_base: Schema.Class<AgentError, Schema.TaggedStruct<"AgentError", {
|
|
17
|
-
readonly code: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
27
|
+
readonly code: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "overloaded", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
18
28
|
readonly message: Schema.String;
|
|
19
29
|
readonly retryable: Schema.Boolean;
|
|
30
|
+
readonly provider: Schema.optional<typeof ProviderErrorInfo>;
|
|
20
31
|
readonly eventId: Schema.optional<Schema.Trimmed>;
|
|
21
32
|
readonly createdAtMs: Schema.optional<Schema.Number>;
|
|
22
33
|
}>, {}>;
|
|
@@ -46,9 +57,10 @@ declare const UsageUpdate_base: Schema.Class<UsageUpdate, Schema.TaggedStruct<"U
|
|
|
46
57
|
declare class UsageUpdate extends UsageUpdate_base {}
|
|
47
58
|
declare const AgentRetry_base: Schema.Class<AgentRetry, Schema.TaggedStruct<"AgentRetry", {
|
|
48
59
|
readonly attempt: Schema.Number;
|
|
49
|
-
readonly reason: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
60
|
+
readonly reason: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "overloaded", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
50
61
|
readonly delayMs: Schema.Number;
|
|
51
62
|
readonly message: Schema.String;
|
|
63
|
+
readonly provider: Schema.optional<typeof ProviderErrorInfo>;
|
|
52
64
|
readonly eventId: Schema.optional<Schema.Trimmed>;
|
|
53
65
|
readonly createdAtMs: Schema.optional<Schema.Number>;
|
|
54
66
|
}>, {}>;
|
|
@@ -186,7 +198,7 @@ declare class ToolExecutionCompleted extends ToolExecutionCompleted_base {}
|
|
|
186
198
|
declare const ToolExecutionError_base: Schema.Class<ToolExecutionError, Schema.TaggedStruct<"ToolExecutionError", {
|
|
187
199
|
readonly call: typeof ToolCall;
|
|
188
200
|
readonly message: Schema.String;
|
|
189
|
-
readonly code: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
201
|
+
readonly code: Schema.Literals<readonly ["validation_error", "provider_error", "rate_limit", "overloaded", "context_overflow", "invalid_response", "tool_error", "tool_denied", "tool_timeout", "store_error", "aborted", "session_not_found", "conflict", "unknown"]>;
|
|
190
202
|
readonly eventId: Schema.optional<Schema.Trimmed>;
|
|
191
203
|
readonly createdAtMs: Schema.optional<Schema.Number>;
|
|
192
204
|
}>, {}>;
|
|
@@ -226,5 +238,5 @@ declare const hitlResponseEvent: (response: HitlResponse) => AgentEvent;
|
|
|
226
238
|
declare const AgentEvent: Schema.Union<readonly [typeof AgentStart, typeof AgentError, typeof AgentEnd, typeof AgentAwaitingInput, typeof UsageUpdate, typeof AgentRetry, typeof CompactionStart, typeof CompactionEnd, typeof TurnStart, typeof TurnEnd, typeof LLMStreamStart, typeof LLMTextDelta, typeof LLMReasoningDelta, typeof ToolInputStart, typeof ToolInputDelta, typeof ToolInputEnd, typeof LLMStreamEnd, typeof AssistantMessageEvent, typeof ToolApprovalRequested, typeof ToolApprovalGranted, typeof ToolApprovalDenied, typeof QuestionRequested, typeof QuestionAnswered, typeof QuestionCancelled, typeof ToolExecutionStarted, typeof ToolExecutionCompleted, typeof ToolExecutionError, typeof ProviderToolResult, typeof SubagentStarted, typeof SubagentCompleted]>;
|
|
227
239
|
type AgentEvent = typeof AgentEvent.Type;
|
|
228
240
|
//#endregion
|
|
229
|
-
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId };
|
|
241
|
+
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId };
|
|
230
242
|
//# sourceMappingURL=event.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.mts","names":[],"sources":["../../src/protocol/event.ts"],"mappings":";;;;;;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AAA,SAAA,qBAAA,SAAA,qBAAA,SAAA,mBAAA,SAAA,kBAAA,SAAA,iBAAA,SAAA,gBAAA,SAAA,iBAAA,SAAA,oBAAA,SAAA,sBAAA,SAAA,kBAAA,SAAA,kBAAA,SAAA,eAAA,SAAA,iBAAA;AAAA,KAgCX,UAAA,UAAoB,UAAA,CAAW,IAAI"}
|
package/dist/protocol/event.mjs
CHANGED
|
@@ -17,6 +17,7 @@ const AgentErrorCode = Schema.Literals([
|
|
|
17
17
|
"validation_error",
|
|
18
18
|
"provider_error",
|
|
19
19
|
"rate_limit",
|
|
20
|
+
"overloaded",
|
|
20
21
|
"context_overflow",
|
|
21
22
|
"invalid_response",
|
|
22
23
|
"tool_error",
|
|
@@ -28,12 +29,31 @@ const AgentErrorCode = Schema.Literals([
|
|
|
28
29
|
"conflict",
|
|
29
30
|
"unknown"
|
|
30
31
|
]);
|
|
32
|
+
const ProviderFailureKind = Schema.Literals([
|
|
33
|
+
"rate_limit",
|
|
34
|
+
"overloaded",
|
|
35
|
+
"server_error",
|
|
36
|
+
"network",
|
|
37
|
+
"stream",
|
|
38
|
+
"auth",
|
|
39
|
+
"context_overflow",
|
|
40
|
+
"invalid_response",
|
|
41
|
+
"unknown"
|
|
42
|
+
]);
|
|
43
|
+
var ProviderErrorInfo = class extends Schema.Class("ProviderErrorInfo")({
|
|
44
|
+
provider: NonEmptyTrimmedString,
|
|
45
|
+
kind: ProviderFailureKind,
|
|
46
|
+
status: Schema.optional(Schema.Number),
|
|
47
|
+
providerCode: Schema.optional(Schema.String),
|
|
48
|
+
retryAfterMs: Schema.optional(Schema.Number)
|
|
49
|
+
}) {};
|
|
31
50
|
var AgentStart = class extends Schema.TaggedClass()("AgentStart", { ...EventIdentity }) {};
|
|
32
51
|
var AgentError = class extends Schema.TaggedClass()("AgentError", {
|
|
33
52
|
...EventIdentity,
|
|
34
53
|
code: AgentErrorCode,
|
|
35
54
|
message: Schema.String,
|
|
36
|
-
retryable: Schema.Boolean
|
|
55
|
+
retryable: Schema.Boolean,
|
|
56
|
+
provider: Schema.optional(ProviderErrorInfo)
|
|
37
57
|
}) {};
|
|
38
58
|
var AgentEnd = class extends Schema.TaggedClass()("AgentEnd", {
|
|
39
59
|
...EventIdentity,
|
|
@@ -57,7 +77,8 @@ var AgentRetry = class extends Schema.TaggedClass()("AgentRetry", {
|
|
|
57
77
|
attempt: Schema.Number,
|
|
58
78
|
reason: AgentErrorCode,
|
|
59
79
|
delayMs: Schema.Number,
|
|
60
|
-
message: Schema.String
|
|
80
|
+
message: Schema.String,
|
|
81
|
+
provider: Schema.optional(ProviderErrorInfo)
|
|
61
82
|
}) {};
|
|
62
83
|
var CompactionStart = class extends Schema.TaggedClass()("CompactionStart", {
|
|
63
84
|
...EventIdentity,
|
|
@@ -252,6 +273,6 @@ const AgentEvent = Schema.Union([
|
|
|
252
273
|
SubagentCompleted
|
|
253
274
|
]);
|
|
254
275
|
//#endregion
|
|
255
|
-
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId };
|
|
276
|
+
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId };
|
|
256
277
|
|
|
257
278
|
//# sourceMappingURL=event.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.mjs","names":[],"sources":["../../src/protocol/event.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\nimport { AssistantAgentMessage, AgentMessage } from './message.ts'\nimport {\n HitlRequest,\n QuestionAnswer,\n QuestionRequest,\n QuestionResponse,\n ToolApprovalRequest,\n ToolApprovalResponse,\n ToolCall,\n ToolResult,\n type HitlResponse\n} from './tool.ts'\nimport { AgentUsage } from './usage.ts'\n\nconst NonEmptyTrimmedString = Schema.Trimmed.pipe(Schema.check(Schema.isNonEmpty()))\n\nconst EventIdentity = {\n eventId: Schema.optional(NonEmptyTrimmedString),\n createdAtMs: Schema.optional(Schema.Number)\n}\n\nexport const SubagentStatus = Schema.Literals(['running', 'completed', 'error'])\nexport type SubagentStatus = typeof SubagentStatus.Type\n\nexport const AgentErrorCode = Schema.Literals([\n 'validation_error',\n 'provider_error',\n 'rate_limit',\n 'context_overflow',\n 'invalid_response',\n 'tool_error',\n 'tool_denied',\n 'tool_timeout',\n 'store_error',\n 'aborted',\n 'session_not_found',\n 'conflict',\n 'unknown'\n])\nexport type AgentErrorCode = typeof AgentErrorCode.Type\n\nexport class AgentStart extends Schema.TaggedClass<AgentStart>()('AgentStart', {\n ...EventIdentity\n}) {}\n\nexport class AgentError extends Schema.TaggedClass<AgentError>()('AgentError', {\n ...EventIdentity,\n code: AgentErrorCode,\n message: Schema.String,\n retryable: Schema.Boolean\n}) {}\n\nexport class AgentEnd extends Schema.TaggedClass<AgentEnd>()('AgentEnd', {\n ...EventIdentity,\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n}) {}\n\nexport class AgentAwaitingInput extends Schema.TaggedClass<AgentAwaitingInput>()(\n 'AgentAwaitingInput',\n {\n ...EventIdentity,\n requests: Schema.NonEmptyArray(HitlRequest),\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n }\n) {}\n\nexport class UsageUpdate extends Schema.TaggedClass<UsageUpdate>()('UsageUpdate', {\n ...EventIdentity,\n usage: AgentUsage\n}) {}\n\nexport class AgentRetry extends Schema.TaggedClass<AgentRetry>()('AgentRetry', {\n ...EventIdentity,\n attempt: Schema.Number,\n reason: AgentErrorCode,\n delayMs: Schema.Number,\n message: Schema.String\n}) {}\n\nexport class CompactionStart extends Schema.TaggedClass<CompactionStart>()('CompactionStart', {\n ...EventIdentity,\n strategy: Schema.String\n}) {}\n\nexport class CompactionEnd extends Schema.TaggedClass<CompactionEnd>()('CompactionEnd', {\n ...EventIdentity,\n strategy: Schema.String,\n beforeTokens: Schema.optional(Schema.Number),\n afterTokens: Schema.optional(Schema.Number)\n}) {}\n\nexport class TurnStart extends Schema.TaggedClass<TurnStart>()('TurnStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class TurnEnd extends Schema.TaggedClass<TurnEnd>()('TurnEnd', {\n ...EventIdentity,\n turn: Schema.Number,\n reason: Schema.Literals(['stop', 'tool_use'])\n}) {}\n\nexport class LLMStreamStart extends Schema.TaggedClass<LLMStreamStart>()('LLMStreamStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class LLMTextDelta extends Schema.TaggedClass<LLMTextDelta>()('LLMTextDelta', {\n ...EventIdentity,\n text: Schema.String\n}) {}\n\nexport class LLMReasoningDelta extends Schema.TaggedClass<LLMReasoningDelta>()(\n 'LLMReasoningDelta',\n {\n ...EventIdentity,\n text: Schema.String\n }\n) {}\n\nexport class ToolInputStart extends Schema.TaggedClass<ToolInputStart>()('ToolInputStart', {\n ...EventIdentity,\n id: Schema.String,\n name: Schema.optional(Schema.String)\n}) {}\n\nexport class ToolInputDelta extends Schema.TaggedClass<ToolInputDelta>()('ToolInputDelta', {\n ...EventIdentity,\n id: Schema.String,\n delta: Schema.String\n}) {}\n\nexport class ToolInputEnd extends Schema.TaggedClass<ToolInputEnd>()('ToolInputEnd', {\n ...EventIdentity,\n call: ToolCall\n}) {}\n\nexport class ToolApprovalRequested extends Schema.TaggedClass<ToolApprovalRequested>()(\n 'ToolApprovalRequested',\n {\n ...EventIdentity,\n call: ToolCall,\n request: Schema.optional(ToolApprovalRequest)\n }\n) {}\n\nexport class ToolApprovalGranted extends Schema.TaggedClass<ToolApprovalGranted>()(\n 'ToolApprovalGranted',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class ToolApprovalDenied extends Schema.TaggedClass<ToolApprovalDenied>()(\n 'ToolApprovalDenied',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n reason: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class QuestionRequested extends Schema.TaggedClass<QuestionRequested>()(\n 'QuestionRequested',\n {\n ...EventIdentity,\n request: QuestionRequest\n }\n) {}\n\nexport class QuestionAnswered extends Schema.TaggedClass<QuestionAnswered>()('QuestionAnswered', {\n ...EventIdentity,\n response: QuestionResponse\n}) {}\n\nexport class QuestionCancelled extends Schema.TaggedClass<QuestionCancelled>()(\n 'QuestionCancelled',\n {\n ...EventIdentity,\n response: QuestionResponse\n }\n) {}\n\nexport class LLMStreamEnd extends Schema.TaggedClass<LLMStreamEnd>()('LLMStreamEnd', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class AssistantMessageEvent extends Schema.TaggedClass<AssistantMessageEvent>()(\n 'AssistantMessage',\n {\n ...EventIdentity,\n message: AssistantAgentMessage\n }\n) {}\n\nexport class ToolExecutionStarted extends Schema.TaggedClass<ToolExecutionStarted>()(\n 'ToolExecutionStarted',\n {\n ...EventIdentity,\n call: ToolCall\n }\n) {}\n\nexport class ToolExecutionCompleted extends Schema.TaggedClass<ToolExecutionCompleted>()(\n 'ToolExecutionCompleted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class ToolExecutionError extends Schema.TaggedClass<ToolExecutionError>()(\n 'ToolExecutionError',\n {\n ...EventIdentity,\n call: ToolCall,\n message: Schema.String,\n code: AgentErrorCode\n }\n) {}\n\nexport class ProviderToolResult extends Schema.TaggedClass<ProviderToolResult>()(\n 'ProviderToolResult',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class SubagentStarted extends Schema.TaggedClass<SubagentStarted>()('SubagentStarted', {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String\n}) {}\n\nexport class SubagentCompleted extends Schema.TaggedClass<SubagentCompleted>()(\n 'SubagentCompleted',\n {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String,\n status: SubagentStatus,\n durationMs: Schema.Number,\n summary: Schema.optional(Schema.String)\n }\n) {}\n\nexport const makeSubagentRunId = (parentToolCallId: string) => `subagent:${parentToolCallId}`\n\nconst questionAnswerValue = (answer: QuestionAnswer) =>\n QuestionAnswer.make({\n questionId: answer.questionId,\n ...(answer.optionIds === undefined ? {} : { optionIds: [...answer.optionIds] }),\n ...(answer.customAnswer === undefined ? {} : { customAnswer: answer.customAnswer })\n })\n\nconst questionResponseValue = (response: QuestionResponse) =>\n QuestionResponse.make({\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source,\n ...(response.answers === undefined\n ? {}\n : { answers: response.answers.map(answer => questionAnswerValue(answer)) }),\n ...(response.reason === undefined ? {} : { reason: response.reason })\n })\n\nconst toolApprovalResponseValue = (response: ToolApprovalResponse) =>\n ToolApprovalResponse.make({\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n decision: response.decision,\n source: response.source,\n ...(response.reason === undefined ? {} : { reason: response.reason })\n })\n\nexport const hitlResponseEvent = (response: HitlResponse): AgentEvent => {\n switch (response._tag) {\n case 'QuestionResponse': {\n const responseValue = questionResponseValue(response)\n\n return response.outcome === 'answered'\n ? QuestionAnswered.make({ response: responseValue })\n : QuestionCancelled.make({ response: responseValue })\n }\n case 'ToolApprovalResponse': {\n const responseValue = toolApprovalResponseValue(response)\n\n return response.decision === 'approved'\n ? ToolApprovalGranted.make({ toolCallId: response.toolCallId, response: responseValue })\n : ToolApprovalDenied.make({\n toolCallId: response.toolCallId,\n reason: response.reason ?? 'Denied by user',\n response: responseValue\n })\n }\n }\n}\n\nexport const AgentEvent = Schema.Union([\n AgentStart,\n AgentError,\n AgentEnd,\n AgentAwaitingInput,\n UsageUpdate,\n AgentRetry,\n CompactionStart,\n CompactionEnd,\n TurnStart,\n TurnEnd,\n LLMStreamStart,\n LLMTextDelta,\n LLMReasoningDelta,\n ToolInputStart,\n ToolInputDelta,\n ToolInputEnd,\n LLMStreamEnd,\n AssistantMessageEvent,\n ToolApprovalRequested,\n ToolApprovalGranted,\n ToolApprovalDenied,\n QuestionRequested,\n QuestionAnswered,\n QuestionCancelled,\n ToolExecutionStarted,\n ToolExecutionCompleted,\n ToolExecutionError,\n ProviderToolResult,\n SubagentStarted,\n SubagentCompleted\n])\nexport type AgentEvent = typeof AgentEvent.Type\n"],"mappings":";;;;;AAeA,MAAM,wBAAwB,OAAO,QAAQ,KAAK,OAAO,MAAM,OAAO,WAAW,CAAC,CAAC;AAEnF,MAAM,gBAAgB;CACpB,SAAS,OAAO,SAAS,qBAAqB;CAC9C,aAAa,OAAO,SAAS,OAAO,MAAM;AAC5C;AAEA,MAAa,iBAAiB,OAAO,SAAS;CAAC;CAAW;CAAa;AAAO,CAAC;AAG/E,MAAa,iBAAiB,OAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;CAC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E,YAAY,SAAS;IAAY,UAAU;GAAc,CAAC,IACrF,mBAAmB,KAAK;IACtB,YAAY,SAAS;IACrB,QAAQ,SAAS,UAAU;IAC3B,UAAU;GACZ,CAAC;EACP;CACF;AACF;AAEA,MAAa,aAAa,OAAO,MAAM;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"event.mjs","names":[],"sources":["../../src/protocol/event.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\nimport { AssistantAgentMessage, AgentMessage } from './message.ts'\nimport {\n HitlRequest,\n QuestionAnswer,\n QuestionRequest,\n QuestionResponse,\n ToolApprovalRequest,\n ToolApprovalResponse,\n ToolCall,\n ToolResult,\n type HitlResponse\n} from './tool.ts'\nimport { AgentUsage } from './usage.ts'\n\nconst NonEmptyTrimmedString = Schema.Trimmed.pipe(Schema.check(Schema.isNonEmpty()))\n\nconst EventIdentity = {\n eventId: Schema.optional(NonEmptyTrimmedString),\n createdAtMs: Schema.optional(Schema.Number)\n}\n\nexport const SubagentStatus = Schema.Literals(['running', 'completed', 'error'])\nexport type SubagentStatus = typeof SubagentStatus.Type\n\nexport const AgentErrorCode = Schema.Literals([\n 'validation_error',\n 'provider_error',\n 'rate_limit',\n 'overloaded',\n 'context_overflow',\n 'invalid_response',\n 'tool_error',\n 'tool_denied',\n 'tool_timeout',\n 'store_error',\n 'aborted',\n 'session_not_found',\n 'conflict',\n 'unknown'\n])\nexport type AgentErrorCode = typeof AgentErrorCode.Type\n\nexport const ProviderFailureKind = Schema.Literals([\n 'rate_limit',\n 'overloaded',\n 'server_error',\n 'network',\n 'stream',\n 'auth',\n 'context_overflow',\n 'invalid_response',\n 'unknown'\n])\nexport type ProviderFailureKind = typeof ProviderFailureKind.Type\n\nexport class ProviderErrorInfo extends Schema.Class<ProviderErrorInfo>('ProviderErrorInfo')({\n provider: NonEmptyTrimmedString,\n kind: ProviderFailureKind,\n status: Schema.optional(Schema.Number),\n providerCode: Schema.optional(Schema.String),\n retryAfterMs: Schema.optional(Schema.Number)\n}) {}\n\nexport class AgentStart extends Schema.TaggedClass<AgentStart>()('AgentStart', {\n ...EventIdentity\n}) {}\n\nexport class AgentError extends Schema.TaggedClass<AgentError>()('AgentError', {\n ...EventIdentity,\n code: AgentErrorCode,\n message: Schema.String,\n retryable: Schema.Boolean,\n provider: Schema.optional(ProviderErrorInfo)\n}) {}\n\nexport class AgentEnd extends Schema.TaggedClass<AgentEnd>()('AgentEnd', {\n ...EventIdentity,\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n}) {}\n\nexport class AgentAwaitingInput extends Schema.TaggedClass<AgentAwaitingInput>()(\n 'AgentAwaitingInput',\n {\n ...EventIdentity,\n requests: Schema.NonEmptyArray(HitlRequest),\n messages: Schema.Array(AgentMessage),\n turns: Schema.Number,\n usage: AgentUsage\n }\n) {}\n\nexport class UsageUpdate extends Schema.TaggedClass<UsageUpdate>()('UsageUpdate', {\n ...EventIdentity,\n usage: AgentUsage\n}) {}\n\nexport class AgentRetry extends Schema.TaggedClass<AgentRetry>()('AgentRetry', {\n ...EventIdentity,\n attempt: Schema.Number,\n reason: AgentErrorCode,\n delayMs: Schema.Number,\n message: Schema.String,\n provider: Schema.optional(ProviderErrorInfo)\n}) {}\n\nexport class CompactionStart extends Schema.TaggedClass<CompactionStart>()('CompactionStart', {\n ...EventIdentity,\n strategy: Schema.String\n}) {}\n\nexport class CompactionEnd extends Schema.TaggedClass<CompactionEnd>()('CompactionEnd', {\n ...EventIdentity,\n strategy: Schema.String,\n beforeTokens: Schema.optional(Schema.Number),\n afterTokens: Schema.optional(Schema.Number)\n}) {}\n\nexport class TurnStart extends Schema.TaggedClass<TurnStart>()('TurnStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class TurnEnd extends Schema.TaggedClass<TurnEnd>()('TurnEnd', {\n ...EventIdentity,\n turn: Schema.Number,\n reason: Schema.Literals(['stop', 'tool_use'])\n}) {}\n\nexport class LLMStreamStart extends Schema.TaggedClass<LLMStreamStart>()('LLMStreamStart', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class LLMTextDelta extends Schema.TaggedClass<LLMTextDelta>()('LLMTextDelta', {\n ...EventIdentity,\n text: Schema.String\n}) {}\n\nexport class LLMReasoningDelta extends Schema.TaggedClass<LLMReasoningDelta>()(\n 'LLMReasoningDelta',\n {\n ...EventIdentity,\n text: Schema.String\n }\n) {}\n\nexport class ToolInputStart extends Schema.TaggedClass<ToolInputStart>()('ToolInputStart', {\n ...EventIdentity,\n id: Schema.String,\n name: Schema.optional(Schema.String)\n}) {}\n\nexport class ToolInputDelta extends Schema.TaggedClass<ToolInputDelta>()('ToolInputDelta', {\n ...EventIdentity,\n id: Schema.String,\n delta: Schema.String\n}) {}\n\nexport class ToolInputEnd extends Schema.TaggedClass<ToolInputEnd>()('ToolInputEnd', {\n ...EventIdentity,\n call: ToolCall\n}) {}\n\nexport class ToolApprovalRequested extends Schema.TaggedClass<ToolApprovalRequested>()(\n 'ToolApprovalRequested',\n {\n ...EventIdentity,\n call: ToolCall,\n request: Schema.optional(ToolApprovalRequest)\n }\n) {}\n\nexport class ToolApprovalGranted extends Schema.TaggedClass<ToolApprovalGranted>()(\n 'ToolApprovalGranted',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class ToolApprovalDenied extends Schema.TaggedClass<ToolApprovalDenied>()(\n 'ToolApprovalDenied',\n {\n ...EventIdentity,\n toolCallId: Schema.String,\n reason: Schema.String,\n response: Schema.optional(ToolApprovalResponse)\n }\n) {}\n\nexport class QuestionRequested extends Schema.TaggedClass<QuestionRequested>()(\n 'QuestionRequested',\n {\n ...EventIdentity,\n request: QuestionRequest\n }\n) {}\n\nexport class QuestionAnswered extends Schema.TaggedClass<QuestionAnswered>()('QuestionAnswered', {\n ...EventIdentity,\n response: QuestionResponse\n}) {}\n\nexport class QuestionCancelled extends Schema.TaggedClass<QuestionCancelled>()(\n 'QuestionCancelled',\n {\n ...EventIdentity,\n response: QuestionResponse\n }\n) {}\n\nexport class LLMStreamEnd extends Schema.TaggedClass<LLMStreamEnd>()('LLMStreamEnd', {\n ...EventIdentity,\n turn: Schema.Number\n}) {}\n\nexport class AssistantMessageEvent extends Schema.TaggedClass<AssistantMessageEvent>()(\n 'AssistantMessage',\n {\n ...EventIdentity,\n message: AssistantAgentMessage\n }\n) {}\n\nexport class ToolExecutionStarted extends Schema.TaggedClass<ToolExecutionStarted>()(\n 'ToolExecutionStarted',\n {\n ...EventIdentity,\n call: ToolCall\n }\n) {}\n\nexport class ToolExecutionCompleted extends Schema.TaggedClass<ToolExecutionCompleted>()(\n 'ToolExecutionCompleted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class ToolExecutionError extends Schema.TaggedClass<ToolExecutionError>()(\n 'ToolExecutionError',\n {\n ...EventIdentity,\n call: ToolCall,\n message: Schema.String,\n code: AgentErrorCode\n }\n) {}\n\nexport class ProviderToolResult extends Schema.TaggedClass<ProviderToolResult>()(\n 'ProviderToolResult',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\n }\n) {}\n\nexport class SubagentStarted extends Schema.TaggedClass<SubagentStarted>()('SubagentStarted', {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String\n}) {}\n\nexport class SubagentCompleted extends Schema.TaggedClass<SubagentCompleted>()(\n 'SubagentCompleted',\n {\n ...EventIdentity,\n parentToolCallId: NonEmptyTrimmedString,\n subagentRunId: NonEmptyTrimmedString,\n subagentType: NonEmptyTrimmedString,\n description: Schema.String,\n model: Schema.String,\n status: SubagentStatus,\n durationMs: Schema.Number,\n summary: Schema.optional(Schema.String)\n }\n) {}\n\nexport const makeSubagentRunId = (parentToolCallId: string) => `subagent:${parentToolCallId}`\n\nconst questionAnswerValue = (answer: QuestionAnswer) =>\n QuestionAnswer.make({\n questionId: answer.questionId,\n ...(answer.optionIds === undefined ? {} : { optionIds: [...answer.optionIds] }),\n ...(answer.customAnswer === undefined ? {} : { customAnswer: answer.customAnswer })\n })\n\nconst questionResponseValue = (response: QuestionResponse) =>\n QuestionResponse.make({\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source,\n ...(response.answers === undefined\n ? {}\n : { answers: response.answers.map(answer => questionAnswerValue(answer)) }),\n ...(response.reason === undefined ? {} : { reason: response.reason })\n })\n\nconst toolApprovalResponseValue = (response: ToolApprovalResponse) =>\n ToolApprovalResponse.make({\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n decision: response.decision,\n source: response.source,\n ...(response.reason === undefined ? {} : { reason: response.reason })\n })\n\nexport const hitlResponseEvent = (response: HitlResponse): AgentEvent => {\n switch (response._tag) {\n case 'QuestionResponse': {\n const responseValue = questionResponseValue(response)\n\n return response.outcome === 'answered'\n ? QuestionAnswered.make({ response: responseValue })\n : QuestionCancelled.make({ response: responseValue })\n }\n case 'ToolApprovalResponse': {\n const responseValue = toolApprovalResponseValue(response)\n\n return response.decision === 'approved'\n ? ToolApprovalGranted.make({ toolCallId: response.toolCallId, response: responseValue })\n : ToolApprovalDenied.make({\n toolCallId: response.toolCallId,\n reason: response.reason ?? 'Denied by user',\n response: responseValue\n })\n }\n }\n}\n\nexport const AgentEvent = Schema.Union([\n AgentStart,\n AgentError,\n AgentEnd,\n AgentAwaitingInput,\n UsageUpdate,\n AgentRetry,\n CompactionStart,\n CompactionEnd,\n TurnStart,\n TurnEnd,\n LLMStreamStart,\n LLMTextDelta,\n LLMReasoningDelta,\n ToolInputStart,\n ToolInputDelta,\n ToolInputEnd,\n LLMStreamEnd,\n AssistantMessageEvent,\n ToolApprovalRequested,\n ToolApprovalGranted,\n ToolApprovalDenied,\n QuestionRequested,\n QuestionAnswered,\n QuestionCancelled,\n ToolExecutionStarted,\n ToolExecutionCompleted,\n ToolExecutionError,\n ProviderToolResult,\n SubagentStarted,\n SubagentCompleted\n])\nexport type AgentEvent = typeof AgentEvent.Type\n"],"mappings":";;;;;AAeA,MAAM,wBAAwB,OAAO,QAAQ,KAAK,OAAO,MAAM,OAAO,WAAW,CAAC,CAAC;AAEnF,MAAM,gBAAgB;CACpB,SAAS,OAAO,SAAS,qBAAqB;CAC9C,aAAa,OAAO,SAAS,OAAO,MAAM;AAC5C;AAEA,MAAa,iBAAiB,OAAO,SAAS;CAAC;CAAW;CAAa;AAAO,CAAC;AAG/E,MAAa,iBAAiB,OAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAa,sBAAsB,OAAO,SAAS;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAGD,IAAa,oBAAb,cAAuC,OAAO,MAAyB,mBAAmB,EAAE;CAC1F,UAAU;CACV,MAAM;CACN,QAAQ,OAAO,SAAS,OAAO,MAAM;CACrC,cAAc,OAAO,SAAS,OAAO,MAAM;CAC3C,cAAc,OAAO,SAAS,OAAO,MAAM;AAC7C,CAAC,EAAE,CAAC;AAEJ,IAAa,aAAb,cAAgC,OAAO,YAAwB,EAAE,cAAc,EAC7E,GAAG,cACL,CAAC,EAAE,CAAC;AAEJ,IAAa,aAAb,cAAgC,OAAO,YAAwB,EAAE,cAAc;CAC7E,GAAG;CACH,MAAM;CACN,SAAS,OAAO;CAChB,WAAW,OAAO;CAClB,UAAU,OAAO,SAAS,iBAAiB;AAC7C,CAAC,EAAE,CAAC;AAEJ,IAAa,WAAb,cAA8B,OAAO,YAAsB,EAAE,YAAY;CACvE,GAAG;CACH,UAAU,OAAO,MAAM,YAAY;CACnC,O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
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
2
|
-
import { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, refAttachmentSource, resolveContentAttachmentSources, urlAttachmentSource } from "./content.mjs";
|
|
2
|
+
import { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource } from "./content.mjs";
|
|
3
3
|
import { ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, PlainHitlResponse, PlainQuestionAnswer, PlainQuestionResponse, PlainToolApprovalResponse, QuestionAnswer, QuestionOption, QuestionPrompt, QuestionRequest, QuestionResponse, QuestionResponseOutcome, QuestionResponseStructuredContent, QuestionToolParams, ToolApprovalDecision, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalResponse, ToolCall, ToolDef, ToolResult, formatQuestionResponseContent, makeErrorToolResult, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, questionResponseStructuredContent } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, HostToolCallPart, MessageAnnotations, MessageAuthor, MessageEnvelope, ProviderToolCallPart, ProviderToolResultPart, ToolResultMessage, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText, messageContextText, prependMessageContextToContent } from "./message.mjs";
|
|
5
5
|
import { AgentInputUsage, AgentOutputUsage, AgentUsage, addAgentUsage, zeroAgentUsage } from "./usage.mjs";
|
|
6
|
-
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId } from "./event.mjs";
|
|
6
|
+
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId } from "./event.mjs";
|
|
7
7
|
import { AgentReasoningEffort } from "./reasoning.mjs";
|
|
8
8
|
import { AgentWebSocketClientMessage, AgentWebSocketServerMessage, QuestionResponseInput, SessionSnapshot, ToolApprovalResponseInput, UserInput } from "./session.mjs";
|
|
9
9
|
|
|
10
10
|
//#region src/protocol/index.d.ts
|
|
11
11
|
type MessageId = string;
|
|
12
12
|
//#endregion
|
|
13
|
-
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, type AttachmentContentPart, AttachmentSource, type AttachmentSourceResolver, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, type ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, type MessageEnvelope, MessageId, type PlainHitlResponse, type PlainQuestionAnswer, type PlainQuestionResponse, type PlainToolApprovalResponse, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, type QuestionResponseStructuredContent, QuestionToolParams, RefAttachmentSource, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, formatQuestionResponseContent, hitlResponseEvent, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, resolveContentAttachmentSources, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, urlAttachmentSource, zeroAgentUsage };
|
|
13
|
+
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, type AttachmentContentPart, AttachmentSource, type AttachmentSourceResolver, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, type ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, type MessageEnvelope, MessageId, type PlainHitlResponse, type PlainQuestionAnswer, type PlainQuestionResponse, type PlainToolApprovalResponse, ProviderErrorInfo, ProviderFailureKind, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, type QuestionResponseStructuredContent, QuestionToolParams, RefAttachmentSource, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, zeroAgentUsage };
|
|
14
14
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/protocol/index.ts"],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/protocol/index.ts"],"mappings":";;;;;;;;;;KAyJY,SAAA"}
|
package/dist/protocol/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
2
|
-
import { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, refAttachmentSource, resolveContentAttachmentSources, urlAttachmentSource } from "./content.mjs";
|
|
2
|
+
import { AttachmentSource, AudioPart, Content, ContentPart, DocumentPart, ImagePart, InlineBase64AttachmentSource, RefAttachmentSource, TextPart, UrlAttachmentSource, appendTextToContent, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textToBase64Utf8, urlAttachmentSource } from "./content.mjs";
|
|
3
3
|
import { HitlRequest, HitlResponse, HitlResponseSource, QuestionAnswer, QuestionOption, QuestionPrompt, QuestionRequest, QuestionResponse, QuestionResponseOutcome, QuestionToolParams, ToolApprovalDecision, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalResponse, ToolCall, ToolDef, ToolResult, formatQuestionResponseContent, makeErrorToolResult, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, questionResponseStructuredContent } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, HostToolCallPart, MessageAnnotations, MessageAuthor, ProviderToolCallPart, ProviderToolResultPart, ToolResultMessage, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText, messageContextText, prependMessageContextToContent } from "./message.mjs";
|
|
5
5
|
import { AgentInputUsage, AgentOutputUsage, AgentUsage, addAgentUsage, zeroAgentUsage } from "./usage.mjs";
|
|
6
|
-
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId } from "./event.mjs";
|
|
6
|
+
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, hitlResponseEvent, makeSubagentRunId } from "./event.mjs";
|
|
7
7
|
import { AgentReasoningEffort } from "./reasoning.mjs";
|
|
8
8
|
import { AgentWebSocketClientMessage, AgentWebSocketServerMessage, QuestionResponseInput, SessionSnapshot, ToolApprovalResponseInput, UserInput } from "./session.mjs";
|
|
9
|
-
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, AttachmentSource, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, QuestionToolParams, RefAttachmentSource, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, formatQuestionResponseContent, hitlResponseEvent, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, resolveContentAttachmentSources, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, urlAttachmentSource, zeroAgentUsage };
|
|
9
|
+
export { AgentAwaitingInput, AgentContentCapabilities, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentInputUsage, AgentMessage, AgentModelCapabilities, AgentOutputUsage, AgentReasoningEffort, AgentRetry, AgentStart, AgentUsage, AgentWebSocketClientMessage, AgentWebSocketServerMessage, AssistantAgentMessage, AssistantMessageEvent, AssistantPart, AssistantReasoningPart, AssistantTextPart, AttachmentSource, AudioPart, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, ProviderErrorInfo, ProviderFailureKind, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, QuestionToolParams, RefAttachmentSource, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTextDocumentMimeType, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, resolveContentAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, urlAttachmentSource, zeroAgentUsage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude-provider.d.mts","names":[],"sources":["../../../src/providers/anthropic/claude-provider.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file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A,MAAA;EAAA,SACA,KAAA,GAAQ,aAAA,CAAc,aAAA;AAAA;AAAA,cAmqBpB,4BAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA;EAAA,SAAoB,SAAA;EAAA,SAA6B,MAAA;AAAA,MAChD,MAAA,CAAO,MAAA,CAAO,oBAAA,EAAsB,QAAA;AAAA,cA6e1B,6BAAA,GACX,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cAoFd,gCAAA,GAAoC,MAAA,EAAQ,6BAAA,KAA6B,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { classifyProviderFailure, providerErrorInfo, providerFailureCause, providerFailureRetryable } from "../provider-error.mjs";
|
|
1
2
|
import { anthropicClaudeAuthorizationHeaders, anthropicClaudeCodeEntrypoint, anthropicClaudeCodeVersion, anthropicClaudeOAuthUserAgent } from "./claude.mjs";
|
|
3
|
+
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, attachmentSourceBase64, attachmentSourceText, isTextDocumentMimeType, messageContextText, prependMessageContextToContent } from "@yolk-sdk/agent/protocol";
|
|
2
4
|
import { Effect, Layer, Option, Ref, Stream } from "effect";
|
|
3
5
|
import { HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
4
6
|
import * as Schema from "effect/Schema";
|
|
5
|
-
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, attachmentSourceBase64, messageContextText, prependMessageContextToContent } from "@yolk-sdk/agent/protocol";
|
|
6
7
|
import { LLMDone, LLMError, LLMProvider, LLMReasoningDelta as LLMReasoningDelta$1, LLMTextDelta as LLMTextDelta$1, LLMToolCall, LLMUsage } from "@yolk-sdk/agent/loop";
|
|
7
8
|
//#region src/providers/anthropic/claude-provider.ts
|
|
8
9
|
const anthropicClaudeSystemIdentity = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
@@ -190,6 +191,16 @@ const unsupportedContentError = (contentType) => new LLMError({
|
|
|
190
191
|
message: `${contentType} content is not supported by the Anthropic Claude provider yet`,
|
|
191
192
|
retryable: false
|
|
192
193
|
});
|
|
194
|
+
const textDocumentToAnthropicBlock = (part) => attachmentSourceText(part.source).pipe(Effect.mapError(() => unsupportedContentError("Invalid document text")), Effect.flatMap(Option.match({
|
|
195
|
+
onNone: () => Effect.fail(unsupportedContentError("Unresolved document source")),
|
|
196
|
+
onSome: (text) => {
|
|
197
|
+
const block = {
|
|
198
|
+
type: "text",
|
|
199
|
+
text: `Document: ${part.title ?? part.filename}\n\n${text}`
|
|
200
|
+
};
|
|
201
|
+
return Effect.succeed(block);
|
|
202
|
+
}
|
|
203
|
+
})));
|
|
193
204
|
const contentPartToUserBlock = (part) => {
|
|
194
205
|
switch (part._tag) {
|
|
195
206
|
case "Text": return Effect.succeed({
|
|
@@ -207,7 +218,7 @@ const contentPartToUserBlock = (part) => {
|
|
|
207
218
|
}
|
|
208
219
|
})
|
|
209
220
|
});
|
|
210
|
-
case "Document": return part.mimeType === "application/pdf" ? Option.match(attachmentSourceBase64(part.source), {
|
|
221
|
+
case "Document": return isTextDocumentMimeType(part.mimeType) ? textDocumentToAnthropicBlock(part) : part.mimeType === "application/pdf" ? Option.match(attachmentSourceBase64(part.source), {
|
|
211
222
|
onNone: () => Effect.fail(unsupportedContentError("Unresolved document source")),
|
|
212
223
|
onSome: (data) => Effect.succeed({
|
|
213
224
|
type: "document",
|
|
@@ -413,16 +424,15 @@ const toAnthropicClaudeRequestBody = (request, config) => Effect.gen(function* (
|
|
|
413
424
|
tools: request.tools.map(toAnthropicTool)
|
|
414
425
|
};
|
|
415
426
|
});
|
|
416
|
-
const
|
|
417
|
-
|
|
418
|
-
if (status === 413 || status === 400) return "context_overflow";
|
|
419
|
-
return "provider_error";
|
|
420
|
-
};
|
|
421
|
-
const isRetryableStatus = (status) => status === 429 || status >= 500;
|
|
422
|
-
const toHttpClientLlmError = (message, retryable) => (error) => new LLMError({
|
|
427
|
+
const anthropicClaudeProvider = "anthropic_claude";
|
|
428
|
+
const toHttpClientLlmError = (message, retryable, kind = "network") => (error) => new LLMError({
|
|
423
429
|
cause: "provider_error",
|
|
424
430
|
message: `${message}: ${error.message}`,
|
|
425
|
-
retryable
|
|
431
|
+
retryable,
|
|
432
|
+
provider: providerErrorInfo({
|
|
433
|
+
provider: anthropicClaudeProvider,
|
|
434
|
+
kind: retryable ? kind : "unknown"
|
|
435
|
+
})
|
|
426
436
|
});
|
|
427
437
|
const decodeJsonString = (raw, message) => Schema.decodeUnknownEffect(Schema.UnknownFromJsonString)(raw).pipe(Effect.mapError((error) => new LLMError({
|
|
428
438
|
cause: "invalid_response",
|
|
@@ -435,6 +445,20 @@ const stringField = (value, key) => {
|
|
|
435
445
|
const raw = field(value, key);
|
|
436
446
|
return typeof raw === "string" ? raw : void 0;
|
|
437
447
|
};
|
|
448
|
+
const providerSignalError = (input) => {
|
|
449
|
+
const provider = classifyProviderFailure({
|
|
450
|
+
provider: anthropicClaudeProvider,
|
|
451
|
+
message: input.message,
|
|
452
|
+
...input.providerCode === void 0 ? {} : { providerCode: input.providerCode },
|
|
453
|
+
...input.fallbackKind === void 0 ? {} : { fallbackKind: input.fallbackKind }
|
|
454
|
+
});
|
|
455
|
+
return new LLMError({
|
|
456
|
+
cause: providerFailureCause(provider.kind),
|
|
457
|
+
message: input.message,
|
|
458
|
+
retryable: providerFailureRetryable(provider.kind),
|
|
459
|
+
provider
|
|
460
|
+
});
|
|
461
|
+
};
|
|
438
462
|
const numberField = (value, key) => {
|
|
439
463
|
const raw = field(value, key);
|
|
440
464
|
return typeof raw === "number" ? raw : void 0;
|
|
@@ -628,10 +652,10 @@ const makeAnthropicStreamEmitter = () => {
|
|
|
628
652
|
});
|
|
629
653
|
if (type === "error") {
|
|
630
654
|
const error = field(data, "error");
|
|
631
|
-
|
|
632
|
-
|
|
655
|
+
const providerCode = stringField(error, "type") ?? stringField(error, "code");
|
|
656
|
+
return Effect.fail(providerSignalError({
|
|
633
657
|
message: stringField(error, "message") ?? "Anthropic Claude stream error",
|
|
634
|
-
|
|
658
|
+
...providerCode === void 0 ? {} : { providerCode }
|
|
635
659
|
}));
|
|
636
660
|
}
|
|
637
661
|
return Effect.succeed({
|
|
@@ -708,7 +732,7 @@ const finalizeBodyState = (emitData, state) => Effect.gen(function* () {
|
|
|
708
732
|
});
|
|
709
733
|
const streamAnthropicClaudeResponse = (response) => Stream.unwrap(Ref.make(initialBodyState).pipe(Effect.map((bodyStateRef) => {
|
|
710
734
|
const emitData = makeAnthropicStreamEmitter();
|
|
711
|
-
const chunks = response.stream.pipe(Stream.mapError(toHttpClientLlmError("Could not read Anthropic Claude stream",
|
|
735
|
+
const chunks = response.stream.pipe(Stream.mapError(toHttpClientLlmError("Could not read Anthropic Claude stream", true, "stream")), Stream.decodeText, Stream.mapEffect((chunk) => Effect.gen(function* () {
|
|
712
736
|
const step = yield* processBodyChunk(emitData, yield* Ref.get(bodyStateRef), chunk);
|
|
713
737
|
yield* Ref.set(bodyStateRef, step.bodyState);
|
|
714
738
|
return step.events;
|
|
@@ -738,10 +762,17 @@ const sendAnthropicClaudeRequest = (config, request, client, sessionId) => Effec
|
|
|
738
762
|
message: `Could not read Anthropic Claude error body: ${error.message}`,
|
|
739
763
|
retryable: false
|
|
740
764
|
})));
|
|
765
|
+
const provider = classifyProviderFailure({
|
|
766
|
+
provider: anthropicClaudeProvider,
|
|
767
|
+
status: response.status,
|
|
768
|
+
headers: response.headers,
|
|
769
|
+
body: errorText
|
|
770
|
+
});
|
|
741
771
|
return yield* Effect.fail(new LLMError({
|
|
742
|
-
cause:
|
|
743
|
-
message: `Anthropic Claude returned ${response.status}
|
|
744
|
-
retryable:
|
|
772
|
+
cause: providerFailureCause(provider.kind),
|
|
773
|
+
message: `Anthropic Claude returned ${response.status}`,
|
|
774
|
+
retryable: providerFailureRetryable(provider.kind),
|
|
775
|
+
provider
|
|
745
776
|
}));
|
|
746
777
|
}
|
|
747
778
|
return response;
|