@yolk-sdk/agent 0.1.0-canary.80 → 0.1.0-canary.81
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 +5 -2
- package/dist/protocol/event.d.mts +17 -1
- package/dist/protocol/event.d.mts.map +1 -1
- package/dist/protocol/event.mjs +28 -2
- package/dist/protocol/event.mjs.map +1 -1
- package/dist/protocol/index.d.mts +2 -2
- package/dist/protocol/index.d.mts.map +1 -1
- package/dist/protocol/index.mjs +2 -2
- package/dist/providers/openai/provider.d.mts.map +1 -1
- package/dist/providers/openai/provider.mjs +55 -9
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/provider-error.d.mts +2 -1
- package/dist/providers/provider-error.d.mts.map +1 -1
- package/dist/providers/provider-error.mjs +1 -0
- package/dist/providers/provider-error.mjs.map +1 -1
- package/dist/react/chat-items.d.mts +33 -33
- package/dist/react/chat-items.d.mts.map +1 -1
- package/dist/react/chat-messages.d.mts +40 -40
- package/dist/react/chat-messages.d.mts.map +1 -1
- package/dist/skillset/merge.d.mts +2 -2
- package/package.json +1 -1
- package/src/protocol/event.ts +27 -1
- package/src/protocol/index.ts +3 -0
- package/src/providers/openai/provider.ts +90 -5
- package/src/providers/provider-error.ts +8 -1
package/README.md
CHANGED
|
@@ -371,8 +371,11 @@ and object-root identity are unchanged.
|
|
|
371
371
|
Provider adapters classify safe failure metadata at the boundary. The loop owns bounded retry
|
|
372
372
|
policy and emits protocol-visible retry/error state:
|
|
373
373
|
|
|
374
|
-
- `ProviderErrorInfo` carries safe provider id, failure kind, HTTP status, provider code,
|
|
375
|
-
optional `
|
|
374
|
+
- `ProviderErrorInfo` carries safe provider id, failure kind, HTTP status, provider code, optional
|
|
375
|
+
`retryAfterMs`, and optional `stream` diagnostics (`ProviderStreamDiagnostics`) on chat
|
|
376
|
+
`unexpected_content_type` / `incomplete_stream` failures. Diagnostics contain counters and
|
|
377
|
+
milestones, never transcript content, raw headers, or body fragments. See the
|
|
378
|
+
[stream diagnostics guide](https://github.com/magoz/yolk-sdk/blob/main/apps/docs/content/docs/troubleshooting.mdx#diagnose-chat-stream-failures-with-stream-diagnostics).
|
|
376
379
|
- Chat Completions and Responses HTTP failures copy the envelope string `code` (falling back to
|
|
377
380
|
`type`) into `provider.providerCode`; free-text upstream bodies stay out of `LLMError`.
|
|
378
381
|
- `AgentRetry.provider` exposes current retry metadata and chosen `delayMs`.
|
|
@@ -10,12 +10,28 @@ declare const AgentErrorCode: Schema.Literals<readonly ["validation_error", "pro
|
|
|
10
10
|
type AgentErrorCode = typeof AgentErrorCode.Type;
|
|
11
11
|
declare const ProviderFailureKind: Schema.Literals<readonly ["rate_limit", "overloaded", "server_error", "network", "stream", "auth", "context_overflow", "invalid_response", "unknown"]>;
|
|
12
12
|
type ProviderFailureKind = typeof ProviderFailureKind.Type;
|
|
13
|
+
declare const ProviderStreamProtocol: Schema.Literals<readonly ["chat-completions", "messages", "responses"]>;
|
|
14
|
+
type ProviderStreamProtocol = typeof ProviderStreamProtocol.Type;
|
|
15
|
+
/** `unknown` means no Content-Type header was present. */
|
|
16
|
+
declare const ProviderStreamResponseFormat: Schema.Literals<readonly ["sse", "json", "other", "unknown"]>;
|
|
17
|
+
type ProviderStreamResponseFormat = typeof ProviderStreamResponseFormat.Type;
|
|
18
|
+
declare const ProviderStreamDiagnostics_base: Schema.Class<ProviderStreamDiagnostics, Schema.Struct<{
|
|
19
|
+
readonly protocol: Schema.Literals<readonly ["chat-completions", "messages", "responses"]>;
|
|
20
|
+
readonly responseFormat: Schema.Literals<readonly ["sse", "json", "other", "unknown"]>; /** Bytes received from HTTP body chunks before text decoding. */
|
|
21
|
+
readonly receivedBytes: Schema.Natural; /** Undelivered tail characters pending in the SSE buffer, in UTF-16 code units. */
|
|
22
|
+
readonly bufferedChars: Schema.Natural; /** Whether text or reasoning output was actually emitted to the consumer. */
|
|
23
|
+
readonly outputStarted: Schema.Boolean; /** Whether a terminal SSE frame ([DONE] or a processed finish reason) was seen. */
|
|
24
|
+
readonly terminalSeen: Schema.Boolean;
|
|
25
|
+
}>, {}>;
|
|
26
|
+
/** Stream failure metadata; never retain transcript content, raw headers, or body fragments. */
|
|
27
|
+
declare class ProviderStreamDiagnostics extends ProviderStreamDiagnostics_base {}
|
|
13
28
|
declare const ProviderErrorInfo_base: Schema.Class<ProviderErrorInfo, Schema.Struct<{
|
|
14
29
|
readonly provider: Schema.Trimmed;
|
|
15
30
|
readonly kind: Schema.Literals<readonly ["rate_limit", "overloaded", "server_error", "network", "stream", "auth", "context_overflow", "invalid_response", "unknown"]>;
|
|
16
31
|
readonly status: Schema.optional<Schema.Number>;
|
|
17
32
|
readonly providerCode: Schema.optional<Schema.String>;
|
|
18
33
|
readonly retryAfterMs: Schema.optional<Schema.Number>;
|
|
34
|
+
readonly stream: Schema.optional<typeof ProviderStreamDiagnostics>;
|
|
19
35
|
}>, {}>;
|
|
20
36
|
declare class ProviderErrorInfo extends ProviderErrorInfo_base {}
|
|
21
37
|
declare const AgentStart_base: Schema.Class<AgentStart, Schema.TaggedStruct<"AgentStart", {
|
|
@@ -258,5 +274,5 @@ type TerminalAgentEvent = Extract<AgentEvent, {
|
|
|
258
274
|
}>;
|
|
259
275
|
declare const isTerminalAgentEvent: (event: AgentEvent) => event is TerminalAgentEvent;
|
|
260
276
|
//#endregion
|
|
261
|
-
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, TerminalAgentEvent, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, makeSubagentRunId };
|
|
277
|
+
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderStreamDiagnostics, ProviderStreamProtocol, ProviderStreamResponseFormat, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, TerminalAgentEvent, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, makeSubagentRunId };
|
|
262
278
|
//# sourceMappingURL=event.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.d.mts","names":[],"sources":["../../src/protocol/event.ts"],"mappings":";;;;;;cAuBa,cAAA,EAAc,MAAA,CAAA,QAAA;AAAA,KAEf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,cAAA,EAAc,MAAA,CAAA,QAAA;AAAA,KAiBf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,mBAAA,EAAmB,MAAA,CAAA,QAAA;AAAA,KAYpB,mBAAA,UAA6B,mBAAA,CAAoB,IAAI;AAAA,cAAA,sBAAA
|
|
1
|
+
{"version":3,"file":"event.d.mts","names":[],"sources":["../../src/protocol/event.ts"],"mappings":";;;;;;cAuBa,cAAA,EAAc,MAAA,CAAA,QAAA;AAAA,KAEf,cAAA,UAAwB,cAAA,CAAe,IAAI;AAAA,cAE1C,cAAA,EAAc,MAAA,CAAA,QAAA;AAAA,KAiBf,cAAA,UAAwB,cAAA,CAAe,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AAA,cAAA,SAAA,YAAA,SAAA,YAAA,SAAA,gBAAA,SAAA,qBAAA,SAAA,qBAAA,SAAA,mBAAA,SAAA,kBAAA,SAAA,iBAAA,SAAA,gBAAA,SAAA,iBAAA,SAAA,oBAAA,SAAA,qBAAA,SAAA,sBAAA,SAAA,kBAAA,SAAA,kBAAA,SAAA,eAAA,SAAA,iBAAA;AAAA,KAmCX,UAAA,UAAoB,UAAA,CAAW,IAAI;AAAA,KAEnC,kBAAA,GAAqB,OAAO,CACtC,UAAA;EAAA,SACW,IAAA;AAAA;AAAA,cAGA,oBAAA,GAAwB,KAAA,EAAO,UAAA,KAAa,KAAA,IAAS,kBAGjB"}
|
package/dist/protocol/event.mjs
CHANGED
|
@@ -41,12 +41,38 @@ const ProviderFailureKind = Schema$1.Literals([
|
|
|
41
41
|
"invalid_response",
|
|
42
42
|
"unknown"
|
|
43
43
|
]);
|
|
44
|
+
const ProviderStreamProtocol = Schema$1.Literals([
|
|
45
|
+
"chat-completions",
|
|
46
|
+
"messages",
|
|
47
|
+
"responses"
|
|
48
|
+
]);
|
|
49
|
+
/** `unknown` means no Content-Type header was present. */
|
|
50
|
+
const ProviderStreamResponseFormat = Schema$1.Literals([
|
|
51
|
+
"sse",
|
|
52
|
+
"json",
|
|
53
|
+
"other",
|
|
54
|
+
"unknown"
|
|
55
|
+
]);
|
|
56
|
+
/** Stream failure metadata; never retain transcript content, raw headers, or body fragments. */
|
|
57
|
+
var ProviderStreamDiagnostics = class extends Schema$1.Class("ProviderStreamDiagnostics")({
|
|
58
|
+
protocol: ProviderStreamProtocol,
|
|
59
|
+
responseFormat: ProviderStreamResponseFormat,
|
|
60
|
+
/** Bytes received from HTTP body chunks before text decoding. */
|
|
61
|
+
receivedBytes: Schema$1.Natural,
|
|
62
|
+
/** Undelivered tail characters pending in the SSE buffer, in UTF-16 code units. */
|
|
63
|
+
bufferedChars: Schema$1.Natural,
|
|
64
|
+
/** Whether text or reasoning output was actually emitted to the consumer. */
|
|
65
|
+
outputStarted: Schema$1.Boolean,
|
|
66
|
+
/** Whether a terminal SSE frame ([DONE] or a processed finish reason) was seen. */
|
|
67
|
+
terminalSeen: Schema$1.Boolean
|
|
68
|
+
}) {};
|
|
44
69
|
var ProviderErrorInfo = class extends Schema$1.Class("ProviderErrorInfo")({
|
|
45
70
|
provider: NonEmptyTrimmedString,
|
|
46
71
|
kind: ProviderFailureKind,
|
|
47
72
|
status: Schema$1.optional(Schema$1.Number),
|
|
48
73
|
providerCode: Schema$1.optional(Schema$1.String),
|
|
49
|
-
retryAfterMs: Schema$1.optional(Schema$1.Number)
|
|
74
|
+
retryAfterMs: Schema$1.optional(Schema$1.Number),
|
|
75
|
+
stream: Schema$1.optional(ProviderStreamDiagnostics)
|
|
50
76
|
}) {};
|
|
51
77
|
var AgentStart = class extends Schema$1.TaggedClass()("AgentStart", { ...EventIdentity }) {};
|
|
52
78
|
var AgentError = class extends Schema$1.TaggedClass()("AgentError", {
|
|
@@ -291,6 +317,6 @@ const AgentEvent = Schema$1.Union([
|
|
|
291
317
|
]);
|
|
292
318
|
const isTerminalAgentEvent = (event) => Predicate.isTagged(event, "AgentEnd") || Predicate.isTagged(event, "AgentError") || Predicate.isTagged(event, "AgentAwaitingInput");
|
|
293
319
|
//#endregion
|
|
294
|
-
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, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, makeSubagentRunId };
|
|
320
|
+
export { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderStreamDiagnostics, ProviderStreamProtocol, ProviderStreamResponseFormat, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, makeSubagentRunId };
|
|
295
321
|
|
|
296
322
|
//# sourceMappingURL=event.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.mjs","names":["Schema"],"sources":["../../src/protocol/event.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\nimport { Match, Predicate } from 'effect'\nimport { AssistantAgentMessage, AgentMessage, UserMessage } 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'])\n\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])\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])\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 textSoFar: Schema.optional(Schema.String)\n}) {}\n\nexport class LLMReasoningDelta extends Schema.TaggedClass<LLMReasoningDelta>()(\n 'LLMReasoningDelta',\n {\n ...EventIdentity,\n text: Schema.String,\n reasoningSoFar: Schema.optional(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 UserMessageEvent extends Schema.TaggedClass<UserMessageEvent>()('UserMessage', {\n ...EventIdentity,\n message: UserMessage\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\n/** The host owns outstanding execution; this event only settles admission. */\nexport class ToolExecutionAccepted extends Schema.TaggedClass<ToolExecutionAccepted>()(\n 'ToolExecutionAccepted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\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\ntype QuestionAnswerCopyFields = {\n questionId: QuestionAnswer['questionId']\n optionIds?: QuestionAnswer['optionIds']\n customAnswer?: QuestionAnswer['customAnswer']\n}\n\nconst questionAnswerValue = (answer: QuestionAnswer) =>\n QuestionAnswer.make(\n (() => {\n const fields: QuestionAnswerCopyFields = {\n questionId: answer.questionId\n }\n\n if (answer.optionIds !== undefined) {\n fields.optionIds = [...answer.optionIds]\n }\n\n if (answer.customAnswer !== undefined) {\n fields.customAnswer = answer.customAnswer\n }\n\n return fields\n })()\n )\n\ntype QuestionResponseCopyFields = {\n requestId: QuestionResponse['requestId']\n toolCallId: QuestionResponse['toolCallId']\n outcome: QuestionResponse['outcome']\n source: QuestionResponse['source']\n answers?: QuestionResponse['answers']\n reason?: QuestionResponse['reason']\n}\n\nconst questionResponseValue = (response: QuestionResponse) =>\n QuestionResponse.make(\n (() => {\n const fields: QuestionResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.answers !== undefined) {\n fields.answers = response.answers.map(answer => questionAnswerValue(answer))\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype ToolApprovalResponseCopyFields = {\n requestId: ToolApprovalResponse['requestId']\n toolCallId: ToolApprovalResponse['toolCallId']\n decision: ToolApprovalResponse['decision']\n source: ToolApprovalResponse['source']\n reason?: ToolApprovalResponse['reason']\n}\n\nconst toolApprovalResponseValue = (response: ToolApprovalResponse) =>\n ToolApprovalResponse.make(\n (() => {\n const fields: ToolApprovalResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n decision: response.decision,\n source: response.source\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\nexport const hitlResponseEvent = (response: HitlResponse): AgentEvent =>\n Match.value(response).pipe(\n Match.tag('QuestionResponse', current => {\n const responseValue = questionResponseValue(current)\n\n return current.outcome === 'answered'\n ? QuestionAnswered.make({ response: responseValue })\n : QuestionCancelled.make({ response: responseValue })\n }),\n Match.tag('ToolApprovalResponse', current => {\n const responseValue = toolApprovalResponseValue(current)\n\n return current.decision === 'approved'\n ? ToolApprovalGranted.make({ toolCallId: current.toolCallId, response: responseValue })\n : ToolApprovalDenied.make({\n toolCallId: current.toolCallId,\n reason: current.reason ?? 'Denied by user',\n response: responseValue\n })\n }),\n Match.exhaustive\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 UserMessageEvent,\n AssistantMessageEvent,\n ToolApprovalRequested,\n ToolApprovalGranted,\n ToolApprovalDenied,\n QuestionRequested,\n QuestionAnswered,\n QuestionCancelled,\n ToolExecutionStarted,\n ToolExecutionAccepted,\n ToolExecutionCompleted,\n ToolExecutionError,\n ProviderToolResult,\n SubagentStarted,\n SubagentCompleted\n])\n\nexport type AgentEvent = typeof AgentEvent.Type\n\nexport type TerminalAgentEvent = Extract<\n AgentEvent,\n { readonly _tag: 'AgentEnd' | 'AgentError' | 'AgentAwaitingInput' }\n>\n\nexport const isTerminalAgentEvent = (event: AgentEvent): event is TerminalAgentEvent =>\n Predicate.isTagged(event, 'AgentEnd') ||\n Predicate.isTagged(event, 'AgentError') ||\n Predicate.isTagged(event, 'AgentAwaitingInput')\n"],"mappings":";;;;;;AAgBA,MAAM,wBAAwBA,SAAO,QAAQ,KAAKA,SAAO,MAAMA,SAAO,WAAW,CAAC,CAAC;AAEnF,MAAM,gBAAgB;CACpB,SAASA,SAAO,SAAS,qBAAqB;CAC9C,aAAaA,SAAO,SAASA,SAAO,MAAM;AAC5C;AAEA,MAAa,iBAAiBA,SAAO,SAAS;CAAC;CAAW;CAAa;AAAO,CAAC;AAI/E,MAAa,iBAAiBA,SAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,MAAa,sBAAsBA,SAAO,SAAS;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,IAAa,oBAAb,cAAuCA,SAAO,MAAyB,mBAAmB,EAAE;CAC1F,UAAU;CACV,MAAM;CACN,QAAQA,SAAO,SAASA,SAAO,MAAM;CACrC,cAAcA,SAAO,SAASA,SAAO,MAAM;CAC3C,cAAcA,SAAO,SAASA,SAAO,MAAM;AAC7C,CAAC,EAAE,CAAC;AAEJ,IAAa,aAAb,cAAgCA,SAAO,YAAwB,EAAE,cAAc,EAC7E,GAAG,cACL,CAAC,EAAE,CAAC;AAEJ,IAAa,aAAb,cAAgCA,SAAO,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AM,QAAQ,EAAE,KACpB,MAAM,IAAI,qBAAoB,YAAW;CACvC,MAAM,gBAAgB,sBAAsB,OAAO;CAEnD,OAAO,QAAQ,YAAY,aACvB,iBAAiB,KAAK,EAAE,UAAU,cAAc,CAAC,IACjD,kBAAkB,KAAK,EAAE,UAAU,cAAc,CAAC;AACxD,CAAC,GACD,MAAM,IAAI,yBAAwB,YAAW;CAC3C,MAAM,gBAAgB,0BAA0B,OAAO;CAEvD,OAAO,QAAQ,aAAa,aACxB,oBAAoB,KAAK;EAAE,YAAY,QAAQ;EAAY,UAAU;CAAc,CAAC,IACpF,mBAAmB,KAAK;EACtB,YAAY,QAAQ;EACpB,QAAQ,QAAQ,UAAU;EAC1B,UAAU;CACZ,CAAC;AACP,CAAC,GACD,MAAM,UACR;AAEF,MAAa,aAAaA,SAAO,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;CACA;CACA;AACF,CAAC;AASD,MAAa,wBAAwB,UACnC,UAAU,SAAS,OAAO,UAAU,KACpC,UAAU,SAAS,OAAO,YAAY,KACtC,UAAU,SAAS,OAAO,oBAAoB"}
|
|
1
|
+
{"version":3,"file":"event.mjs","names":["Schema"],"sources":["../../src/protocol/event.ts"],"sourcesContent":["import * as Schema from 'effect/Schema'\nimport { Match, Predicate } from 'effect'\nimport { AssistantAgentMessage, AgentMessage, UserMessage } 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'])\n\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])\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])\n\nexport type ProviderFailureKind = typeof ProviderFailureKind.Type\n\nexport const ProviderStreamProtocol = Schema.Literals(['chat-completions', 'messages', 'responses'])\n\nexport type ProviderStreamProtocol = typeof ProviderStreamProtocol.Type\n\n/** `unknown` means no Content-Type header was present. */\nexport const ProviderStreamResponseFormat = Schema.Literals(['sse', 'json', 'other', 'unknown'])\n\nexport type ProviderStreamResponseFormat = typeof ProviderStreamResponseFormat.Type\n\n/** Stream failure metadata; never retain transcript content, raw headers, or body fragments. */\nexport class ProviderStreamDiagnostics extends Schema.Class<ProviderStreamDiagnostics>(\n 'ProviderStreamDiagnostics'\n)({\n protocol: ProviderStreamProtocol,\n responseFormat: ProviderStreamResponseFormat,\n /** Bytes received from HTTP body chunks before text decoding. */\n receivedBytes: Schema.Natural,\n /** Undelivered tail characters pending in the SSE buffer, in UTF-16 code units. */\n bufferedChars: Schema.Natural,\n /** Whether text or reasoning output was actually emitted to the consumer. */\n outputStarted: Schema.Boolean,\n /** Whether a terminal SSE frame ([DONE] or a processed finish reason) was seen. */\n terminalSeen: Schema.Boolean\n}) {}\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 stream: Schema.optional(ProviderStreamDiagnostics)\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 textSoFar: Schema.optional(Schema.String)\n}) {}\n\nexport class LLMReasoningDelta extends Schema.TaggedClass<LLMReasoningDelta>()(\n 'LLMReasoningDelta',\n {\n ...EventIdentity,\n text: Schema.String,\n reasoningSoFar: Schema.optional(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 UserMessageEvent extends Schema.TaggedClass<UserMessageEvent>()('UserMessage', {\n ...EventIdentity,\n message: UserMessage\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\n/** The host owns outstanding execution; this event only settles admission. */\nexport class ToolExecutionAccepted extends Schema.TaggedClass<ToolExecutionAccepted>()(\n 'ToolExecutionAccepted',\n {\n ...EventIdentity,\n call: ToolCall,\n result: ToolResult\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\ntype QuestionAnswerCopyFields = {\n questionId: QuestionAnswer['questionId']\n optionIds?: QuestionAnswer['optionIds']\n customAnswer?: QuestionAnswer['customAnswer']\n}\n\nconst questionAnswerValue = (answer: QuestionAnswer) =>\n QuestionAnswer.make(\n (() => {\n const fields: QuestionAnswerCopyFields = {\n questionId: answer.questionId\n }\n\n if (answer.optionIds !== undefined) {\n fields.optionIds = [...answer.optionIds]\n }\n\n if (answer.customAnswer !== undefined) {\n fields.customAnswer = answer.customAnswer\n }\n\n return fields\n })()\n )\n\ntype QuestionResponseCopyFields = {\n requestId: QuestionResponse['requestId']\n toolCallId: QuestionResponse['toolCallId']\n outcome: QuestionResponse['outcome']\n source: QuestionResponse['source']\n answers?: QuestionResponse['answers']\n reason?: QuestionResponse['reason']\n}\n\nconst questionResponseValue = (response: QuestionResponse) =>\n QuestionResponse.make(\n (() => {\n const fields: QuestionResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n outcome: response.outcome,\n source: response.source\n }\n\n if (response.answers !== undefined) {\n fields.answers = response.answers.map(answer => questionAnswerValue(answer))\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\ntype ToolApprovalResponseCopyFields = {\n requestId: ToolApprovalResponse['requestId']\n toolCallId: ToolApprovalResponse['toolCallId']\n decision: ToolApprovalResponse['decision']\n source: ToolApprovalResponse['source']\n reason?: ToolApprovalResponse['reason']\n}\n\nconst toolApprovalResponseValue = (response: ToolApprovalResponse) =>\n ToolApprovalResponse.make(\n (() => {\n const fields: ToolApprovalResponseCopyFields = {\n requestId: response.requestId,\n toolCallId: response.toolCallId,\n decision: response.decision,\n source: response.source\n }\n\n if (response.reason !== undefined) {\n fields.reason = response.reason\n }\n\n return fields\n })()\n )\n\nexport const hitlResponseEvent = (response: HitlResponse): AgentEvent =>\n Match.value(response).pipe(\n Match.tag('QuestionResponse', current => {\n const responseValue = questionResponseValue(current)\n\n return current.outcome === 'answered'\n ? QuestionAnswered.make({ response: responseValue })\n : QuestionCancelled.make({ response: responseValue })\n }),\n Match.tag('ToolApprovalResponse', current => {\n const responseValue = toolApprovalResponseValue(current)\n\n return current.decision === 'approved'\n ? ToolApprovalGranted.make({ toolCallId: current.toolCallId, response: responseValue })\n : ToolApprovalDenied.make({\n toolCallId: current.toolCallId,\n reason: current.reason ?? 'Denied by user',\n response: responseValue\n })\n }),\n Match.exhaustive\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 UserMessageEvent,\n AssistantMessageEvent,\n ToolApprovalRequested,\n ToolApprovalGranted,\n ToolApprovalDenied,\n QuestionRequested,\n QuestionAnswered,\n QuestionCancelled,\n ToolExecutionStarted,\n ToolExecutionAccepted,\n ToolExecutionCompleted,\n ToolExecutionError,\n ProviderToolResult,\n SubagentStarted,\n SubagentCompleted\n])\n\nexport type AgentEvent = typeof AgentEvent.Type\n\nexport type TerminalAgentEvent = Extract<\n AgentEvent,\n { readonly _tag: 'AgentEnd' | 'AgentError' | 'AgentAwaitingInput' }\n>\n\nexport const isTerminalAgentEvent = (event: AgentEvent): event is TerminalAgentEvent =>\n Predicate.isTagged(event, 'AgentEnd') ||\n Predicate.isTagged(event, 'AgentError') ||\n Predicate.isTagged(event, 'AgentAwaitingInput')\n"],"mappings":";;;;;;AAgBA,MAAM,wBAAwBA,SAAO,QAAQ,KAAKA,SAAO,MAAMA,SAAO,WAAW,CAAC,CAAC;AAEnF,MAAM,gBAAgB;CACpB,SAASA,SAAO,SAAS,qBAAqB;CAC9C,aAAaA,SAAO,SAASA,SAAO,MAAM;AAC5C;AAEA,MAAa,iBAAiBA,SAAO,SAAS;CAAC;CAAW;CAAa;AAAO,CAAC;AAI/E,MAAa,iBAAiBA,SAAO,SAAS;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,MAAa,sBAAsBA,SAAO,SAAS;CACjD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAID,MAAa,yBAAyBA,SAAO,SAAS;CAAC;CAAoB;CAAY;AAAW,CAAC;;AAKnG,MAAa,+BAA+BA,SAAO,SAAS;CAAC;CAAO;CAAQ;CAAS;AAAS,CAAC;;AAK/F,IAAa,4BAAb,cAA+CA,SAAO,MACpD,2BACF,EAAE;CACA,UAAU;CACV,gBAAgB;;CAEhB,eAAeA,SAAO;;CAEtB,eAAeA,SAAO;;CAEtB,eAAeA,SAAO;;CAEtB,cAAcA,SAAO;AACvB,CAAC,EAAE,CAAC;AAEJ,IAAa,oBAAb,cAAuCA,SAAO,MAAyB,mBAAmB,EAAE;CAC1F,UAAU;CACV,MAAM;CACN,QAAQA,SAAO,SAASA,SAAO,MAAM;CACrC,cAAcA,SAAO,SAASA,SAAO,MAAM;CAC3C,cAAcA,SAAO,SAASA,SAAO,MAAM;CAC3C,QAAQA,SAAO,SAAS,yBAAyB;AACnD,CAAC,EAAE,CAAC;AAEJ,IAAa,aAAb,cAAgCA,SAAO,YAAwB,EAAE,cAAc,EAC7E,GAAG,cACL,CAAC,EAAE,CAAC;AAEJ,IAAa,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AAqB,aAChC,MAAM,MAAM,QAAQ,EAAE,KACpB,MAAM,IAAI,qBAAoB,YAAW;CACvC,MAAM,gBAAgB,sBAAsB,OAAO;CAEnD,OAAO,QAAQ,YAAY,aACvB,iBAAiB,KAAK,EAAE,UAAU,cAAc,CAAC,IACjD,kBAAkB,KAAK,EAAE,UAAU,cAAc,CAAC;AACxD,CAAC,GACD,MAAM,IAAI,yBAAwB,YAAW;CAC3C,MAAM,gBAAgB,0BAA0B,OAAO;CAEvD,OAAO,QAAQ,aAAa,aACxB,oBAAoB,KAAK;EAAE,YAAY,QAAQ;EAAY,UAAU;CAAc,CAAC,IACpF,mBAAmB,KAAK;EACtB,YAAY,QAAQ;EACpB,QAAQ,QAAQ,UAAU;EAC1B,UAAU;CACZ,CAAC;AACP,CAAC,GACD,MAAM,UACR;AAEF,MAAa,aAAaA,SAAO,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;CACA;CACA;AACF,CAAC;AASD,MAAa,wBAAwB,UACnC,UAAU,SAAS,OAAO,UAAU,KACpC,UAAU,SAAS,OAAO,YAAY,KACtC,UAAU,SAAS,OAAO,oBAAoB"}
|
|
@@ -3,12 +3,12 @@ import { AttachmentContentPart, AttachmentSource, AttachmentSourceResolver, Audi
|
|
|
3
3
|
import { BackgroundToolAccepted, BackgroundToolExecution, BackgroundToolInput, ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, PlainHitlResponse, PlainQuestionAnswer, PlainQuestionResponse, PlainToolApprovalResponse, QuestionAnswer, QuestionOption, QuestionPrompt, QuestionRequest, QuestionResponse, QuestionResponseOutcome, QuestionResponseStructuredContent, QuestionToolParams, ToolApprovalDecision, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalResponse, ToolCall, ToolDef, ToolJsonSchema, ToolJsonSchemaObject, ToolResult, decodeBackgroundToolInput, decodeToolJsonSchema, decodeToolJsonSchemaObject, formatQuestionResponseContent, isToolJsonSchemaObject, makeBackgroundToolAcceptedResult, makeErrorToolResult, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, questionResponseStructuredContent } from "./tool.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, DanglingHostToolCall, HostToolCallPart, MessageAnnotations, MessageAuthor, MessageEnvelope, ProviderToolCallPart, ProviderToolResultPart, RepairDanglingHostToolCallsOptions, ToolResultMessage, TranscriptInvariantValidation, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText, danglingHostToolCalls, messageContextText, prependMessageContextToContent, repairDanglingHostToolCalls, resolveMessageAttachmentSources, resolveMessagesAttachmentSources, toolResultMessageFromResult, validateNoDanglingHostToolCalls } 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, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, TerminalAgentEvent, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, makeSubagentRunId } from "./event.mjs";
|
|
6
|
+
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderStreamDiagnostics, ProviderStreamProtocol, ProviderStreamResponseFormat, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, TerminalAgentEvent, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, 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, BackgroundToolAccepted, BackgroundToolExecution, BackgroundToolInput, CompactionEnd, CompactionStart, Content, ContentPart, type DanglingHostToolCall, DocumentPart, type ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, type MessageEnvelope, MessageId, 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, type RepairDanglingHostToolCallsOptions, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, type TerminalAgentEvent, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolJsonSchema, ToolJsonSchemaObject, ToolResult, ToolResultMessage, type TranscriptInvariantValidation, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, UserMessageEvent, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, decodeBackgroundToolInput, decodeToolJsonSchema, decodeToolJsonSchemaObject, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTerminalAgentEvent, isTextDocumentMimeType, isToolJsonSchemaObject, makeBackgroundToolAcceptedResult, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, resolveMessageAttachmentSources, resolveMessagesAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, toolResultMessageFromResult, urlAttachmentSource, validateNoDanglingHostToolCalls, 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, BackgroundToolAccepted, BackgroundToolExecution, BackgroundToolInput, CompactionEnd, CompactionStart, Content, ContentPart, type DanglingHostToolCall, DocumentPart, type ErrorToolResultInput, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, type MessageEnvelope, MessageId, PlainHitlResponse, type PlainQuestionAnswer, type PlainQuestionResponse, type PlainToolApprovalResponse, ProviderErrorInfo, ProviderFailureKind, ProviderStreamDiagnostics, ProviderStreamProtocol, ProviderStreamResponseFormat, ProviderToolCallPart, ProviderToolResult, ProviderToolResultPart, QuestionAnswer, QuestionAnswered, QuestionCancelled, QuestionOption, QuestionPrompt, QuestionRequest, QuestionRequested, QuestionResponse, QuestionResponseInput, QuestionResponseOutcome, type QuestionResponseStructuredContent, QuestionToolParams, RefAttachmentSource, type RepairDanglingHostToolCallsOptions, SessionSnapshot, SubagentCompleted, SubagentStarted, SubagentStatus, type TerminalAgentEvent, TextPart, ToolApprovalDecision, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalMode, ToolApprovalPolicy, ToolApprovalRequest, ToolApprovalRequested, ToolApprovalResponse, ToolApprovalResponseInput, ToolCall, ToolDef, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolJsonSchema, ToolJsonSchemaObject, ToolResult, ToolResultMessage, type TranscriptInvariantValidation, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, UserMessageEvent, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, decodeBackgroundToolInput, decodeToolJsonSchema, decodeToolJsonSchemaObject, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTerminalAgentEvent, isTextDocumentMimeType, isToolJsonSchemaObject, makeBackgroundToolAcceptedResult, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, resolveMessageAttachmentSources, resolveMessagesAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, toolResultMessageFromResult, urlAttachmentSource, validateNoDanglingHostToolCalls, 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":";;;;;;;;;;KAiMY,SAAA"}
|
package/dist/protocol/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { BackgroundToolAccepted, BackgroundToolExecution, BackgroundToolInput, H
|
|
|
3
3
|
import { AgentContentCapabilities, AgentModelCapabilities, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities } from "./capability.mjs";
|
|
4
4
|
import { AgentMessage, AssistantAgentMessage, AssistantPart, AssistantReasoningPart, AssistantTextPart, HostToolCallPart, MessageAnnotations, MessageAuthor, ProviderToolCallPart, ProviderToolResultPart, ToolResultMessage, UserMessage, assistantContent, assistantHostToolCalls, assistantReasoningText, danglingHostToolCalls, messageContextText, prependMessageContextToContent, repairDanglingHostToolCalls, resolveMessageAttachmentSources, resolveMessagesAttachmentSources, toolResultMessageFromResult, validateNoDanglingHostToolCalls } 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, ProviderErrorInfo, ProviderFailureKind, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, makeSubagentRunId } from "./event.mjs";
|
|
6
|
+
import { AgentAwaitingInput, AgentEnd, AgentError, AgentErrorCode, AgentEvent, AgentRetry, AgentStart, AssistantMessageEvent, CompactionEnd, CompactionStart, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderErrorInfo, ProviderFailureKind, ProviderStreamDiagnostics, ProviderStreamProtocol, ProviderStreamResponseFormat, ProviderToolResult, QuestionAnswered, QuestionCancelled, QuestionRequested, SubagentCompleted, SubagentStarted, SubagentStatus, ToolApprovalDenied, ToolApprovalGranted, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, TurnEnd, TurnStart, UsageUpdate, UserMessageEvent, hitlResponseEvent, isTerminalAgentEvent, 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, BackgroundToolAccepted, BackgroundToolExecution, BackgroundToolInput, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, PlainHitlResponse, 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, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolJsonSchema, ToolJsonSchemaObject, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, UserMessageEvent, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, decodeBackgroundToolInput, decodeToolJsonSchema, decodeToolJsonSchemaObject, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTerminalAgentEvent, isTextDocumentMimeType, isToolJsonSchemaObject, makeBackgroundToolAcceptedResult, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, resolveMessageAttachmentSources, resolveMessagesAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, toolResultMessageFromResult, urlAttachmentSource, validateNoDanglingHostToolCalls, 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, BackgroundToolAccepted, BackgroundToolExecution, BackgroundToolInput, CompactionEnd, CompactionStart, Content, ContentPart, DocumentPart, HitlRequest, HitlResponse, HitlResponseSource, HostToolCallPart, ImagePart, InlineBase64AttachmentSource, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, MessageAnnotations, MessageAuthor, PlainHitlResponse, ProviderErrorInfo, ProviderFailureKind, ProviderStreamDiagnostics, ProviderStreamProtocol, ProviderStreamResponseFormat, 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, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolJsonSchema, ToolJsonSchemaObject, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UrlAttachmentSource, UsageUpdate, UserInput, UserMessage, UserMessageEvent, addAgentUsage, appendTextToContent, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceBase64, attachmentSourceDataUrl, attachmentSourcePreview, attachmentSourceText, attachmentSourceUrl, contentPartPreview, contentPartText, contentParts, contentPreview, contentText, danglingHostToolCalls, decodeBackgroundToolInput, decodeToolJsonSchema, decodeToolJsonSchemaObject, documentPartFromText, formatQuestionResponseContent, hitlResponseEvent, inferTextDocumentMimeType, inlineBase64AttachmentSource, inlineBase64Source, isContentEmpty, isTerminalAgentEvent, isTextDocumentMimeType, isToolJsonSchemaObject, makeBackgroundToolAcceptedResult, makeErrorToolResult, makeSubagentRunId, messageContextText, plainHitlResponse, plainQuestionAnswer, plainQuestionResponse, plainToolApprovalResponse, prependMessageContextToContent, questionResponseStructuredContent, refAttachmentSource, repairDanglingHostToolCalls, replaceLoneSurrogates, replaceLoneSurrogatesDeep, resolveContentAttachmentSources, resolveMessageAttachmentSources, resolveMessagesAttachmentSources, textDocumentMimeTypeFromFilename, textImageDocumentModelCapabilities, textImageModelCapabilities, textOnlyModelCapabilities, textToBase64Utf8, toolResultMessageFromResult, urlAttachmentSource, validateNoDanglingHostToolCalls, zeroAgentUsage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.mts","names":[],"sources":["../../../src/providers/openai/provider.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"provider.d.mts","names":[],"sources":["../../../src/providers/openai/provider.ts"],"mappings":";;;;;;;KA6DK,sBAAA;EAAA,SACM,EAAA;EAAA,SACA,IAAI;AAAA;;KAIH,mBAAA;EAAA,UACA,GAAA,WAAc,QAAA,CAAO,IAAI;AAAA;AAAA,KAgJzB,oBAAA;EAAA,SACD,kBAAA;EAAA,SACA,mBAAA,UAlJC;EAAA,SAoJD,oBAAA;EAAA,SACA,YAAA,GAAe,QAAA,CAAS,MAAA;EArJE;AAAA;AAgJrC;;;EAhJqC,SA2J1B,SAAA,GAAY,mBAAA,EANG;EAAA,SAQf,qBAAA,4CASmB;EAAA,SAPnB,gBAAA;EAQyB;;;;EAAA,SAHzB,SAAA,YAfA;EAAA,SAiBA,gBAAA,GAAmB,sBAAA;EAAA,SACnB,MAAA,EAAQ,QAAA,CAAS,QAAA;AAAA;AAAA,KAGvB,qBAAA;EAAA,SACM,IAAA;EAAA,SACA,IAAI;AAAA;AAAA,KAGV,sBAAA;EAAA,SACM,IAAA;EAAA,SACA,SAAA;IAAA,SACE,GAAA;EAAA;AAAA;AAAA,KAIR,iBAAA,YAA6B,aAAA,CAAc,qBAAA,GAAwB,sBAAA;AAAA,KAEnE,cAAA;EAAA,SACM,EA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AAmB,KAAA,CAAA,KAAA,CAAA,WAAA,EAAA,QAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { classifyProviderFailure, providerErrorInfo, providerFailureCause, providerFailureRetryable } from "../provider-error.mjs";
|
|
2
2
|
import { validateProviderTranscript } from "../transcript.mjs";
|
|
3
3
|
import { Config, Context, Effect, Layer, Match, Option, Predicate, Redacted, Ref, Stream } from "effect";
|
|
4
|
-
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceText, attachmentSourceUrl, isTextDocumentMimeType, messageContextText, prependMessageContextToContent, replaceLoneSurrogatesDeep } from "@yolk-sdk/agent/protocol";
|
|
4
|
+
import { AgentInputUsage, AgentOutputUsage, AgentUsage, ProviderStreamDiagnostics, ToolCall, assistantContent, assistantHostToolCalls, assistantReasoningText, attachmentSourceText, attachmentSourceUrl, isTextDocumentMimeType, messageContextText, prependMessageContextToContent, replaceLoneSurrogatesDeep } from "@yolk-sdk/agent/protocol";
|
|
5
5
|
import * as Schema$1 from "effect/Schema";
|
|
6
6
|
import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
|
|
7
7
|
import { LLMDone, LLMError, LLMProvider, LLMReasoningDelta as LLMReasoningDelta$1, LLMTextDelta as LLMTextDelta$1, LLMToolCall, LLMUsage } from "@yolk-sdk/agent/loop";
|
|
@@ -353,7 +353,9 @@ const initialOpenAiChatStreamState = {
|
|
|
353
353
|
finishReason: void 0,
|
|
354
354
|
hasTerminal: false,
|
|
355
355
|
streamClosed: false,
|
|
356
|
-
usage: void 0
|
|
356
|
+
usage: void 0,
|
|
357
|
+
receivedBytes: 0,
|
|
358
|
+
outputStarted: false
|
|
357
359
|
};
|
|
358
360
|
const splitCompleteChatSseBlocks = (buffer) => {
|
|
359
361
|
const blocks = buffer.replace(/\r\n/g, "\n").split(/\n\n|\n\r|\r\r|\r\n/);
|
|
@@ -429,7 +431,8 @@ const processChatStreamPayload = (providerIdentity, reasoningContent, state, pay
|
|
|
429
431
|
toolCalls,
|
|
430
432
|
finishReason,
|
|
431
433
|
hasTerminal: state.hasTerminal || finishReason !== void 0,
|
|
432
|
-
usage
|
|
434
|
+
usage,
|
|
435
|
+
outputStarted: state.outputStarted || events.length > 0
|
|
433
436
|
},
|
|
434
437
|
events
|
|
435
438
|
};
|
|
@@ -451,6 +454,14 @@ const processChatStreamBlock = (providerIdentity, reasoningContent, state, block
|
|
|
451
454
|
};
|
|
452
455
|
return yield* processChatStreamPayload(providerIdentity, reasoningContent, current, payload);
|
|
453
456
|
});
|
|
457
|
+
const chatStreamDiagnostics = (responseFormat, state) => ProviderStreamDiagnostics.make({
|
|
458
|
+
protocol: "chat-completions",
|
|
459
|
+
responseFormat,
|
|
460
|
+
receivedBytes: state.receivedBytes,
|
|
461
|
+
bufferedChars: state.buffer.length,
|
|
462
|
+
outputStarted: state.outputStarted,
|
|
463
|
+
terminalSeen: state.hasTerminal
|
|
464
|
+
});
|
|
454
465
|
const processChatStreamText = (providerIdentity, reasoningContent, state, text) => Effect.gen(function* () {
|
|
455
466
|
const split = splitCompleteChatSseBlocks(`${state.buffer}${text}`);
|
|
456
467
|
let current = {
|
|
@@ -468,7 +479,7 @@ const processChatStreamText = (providerIdentity, reasoningContent, state, text)
|
|
|
468
479
|
events
|
|
469
480
|
};
|
|
470
481
|
});
|
|
471
|
-
const finalizeChatStreamState = (providerIdentity, state) => Effect.gen(function* () {
|
|
482
|
+
const finalizeChatStreamState = (providerIdentity, responseFormat, state) => Effect.gen(function* () {
|
|
472
483
|
if (!state.hasTerminal) return yield* Effect.fail(new LLMError({
|
|
473
484
|
cause: "invalid_response",
|
|
474
485
|
message: `${providerIdentity.name} stream ended before a terminal chunk`,
|
|
@@ -476,7 +487,8 @@ const finalizeChatStreamState = (providerIdentity, state) => Effect.gen(function
|
|
|
476
487
|
provider: providerErrorInfo({
|
|
477
488
|
provider: providerIdentity.id,
|
|
478
489
|
kind: "invalid_response",
|
|
479
|
-
providerCode: "incomplete_stream"
|
|
490
|
+
providerCode: "incomplete_stream",
|
|
491
|
+
stream: chatStreamDiagnostics(responseFormat, state)
|
|
480
492
|
})
|
|
481
493
|
}));
|
|
482
494
|
if (state.finishReason === "length" || state.finishReason === "content_filter") return yield* Effect.fail(new LLMError({
|
|
@@ -525,13 +537,46 @@ const finalizeChatStreamState = (providerIdentity, state) => Effect.gen(function
|
|
|
525
537
|
}
|
|
526
538
|
return events;
|
|
527
539
|
});
|
|
528
|
-
const
|
|
529
|
-
|
|
540
|
+
const chatStreamResponseFormat = (contentType) => {
|
|
541
|
+
if (contentType === void 0) return "unknown";
|
|
542
|
+
const mediaType = contentType.split(";", 1)[0].trim().toLowerCase();
|
|
543
|
+
if (mediaType === "text/event-stream") return "sse";
|
|
544
|
+
if (mediaType === "application/json" || mediaType.endsWith("+json")) return "json";
|
|
545
|
+
return "other";
|
|
546
|
+
};
|
|
547
|
+
const expectChatSseResponse = (providerIdentity, response) => {
|
|
548
|
+
const responseFormat = chatStreamResponseFormat(response.headers["content-type"]);
|
|
549
|
+
if (responseFormat === "sse" || responseFormat === "unknown") return Effect.succeed(responseFormat);
|
|
550
|
+
return Effect.fail(new LLMError({
|
|
551
|
+
cause: "invalid_response",
|
|
552
|
+
message: `${providerIdentity.name} streaming response was not an SSE stream`,
|
|
553
|
+
retryable: false,
|
|
554
|
+
provider: providerErrorInfo({
|
|
555
|
+
provider: providerIdentity.id,
|
|
556
|
+
kind: "invalid_response",
|
|
557
|
+
status: response.status,
|
|
558
|
+
providerCode: "unexpected_content_type",
|
|
559
|
+
stream: ProviderStreamDiagnostics.make({
|
|
560
|
+
protocol: "chat-completions",
|
|
561
|
+
responseFormat,
|
|
562
|
+
receivedBytes: 0,
|
|
563
|
+
bufferedChars: 0,
|
|
564
|
+
outputStarted: false,
|
|
565
|
+
terminalSeen: false
|
|
566
|
+
})
|
|
567
|
+
})
|
|
568
|
+
}));
|
|
569
|
+
};
|
|
570
|
+
const streamOpenAiChatResponse = (providerIdentity, reasoningContent, responseFormat, response) => Stream.unwrap(Ref.make(initialOpenAiChatStreamState).pipe(Effect.map((stateRef) => {
|
|
571
|
+
const chunks = response.stream.pipe(Stream.mapError(toHttpClientLlmError(providerIdentity, true)), Stream.tap((chunk) => Ref.update(stateRef, (state) => ({
|
|
572
|
+
...state,
|
|
573
|
+
receivedBytes: state.receivedBytes + chunk.byteLength
|
|
574
|
+
}))), Stream.decodeText, Stream.mapEffect((chunk) => Effect.gen(function* () {
|
|
530
575
|
const step = yield* processChatStreamText(providerIdentity, reasoningContent, yield* Ref.get(stateRef), chunk);
|
|
531
576
|
yield* Ref.set(stateRef, step.state);
|
|
532
577
|
return step.events;
|
|
533
578
|
})), Stream.flatMap((events) => Stream.fromIterable(events)));
|
|
534
|
-
const finalEvents = Stream.fromEffect(Ref.get(stateRef).pipe(Effect.flatMap((state) => finalizeChatStreamState(providerIdentity, state)))).pipe(Stream.flatMap((events) => Stream.fromIterable(events)));
|
|
579
|
+
const finalEvents = Stream.fromEffect(Ref.get(stateRef).pipe(Effect.flatMap((state) => finalizeChatStreamState(providerIdentity, responseFormat, state)))).pipe(Stream.flatMap((events) => Stream.fromIterable(events)));
|
|
535
580
|
return chunks.pipe(Stream.concat(finalEvents));
|
|
536
581
|
})));
|
|
537
582
|
const toHttpClientLlmError = (providerIdentity, retryable) => (error) => new LLMError({
|
|
@@ -615,7 +660,8 @@ const sendOpenAiRequest = (config, request, client) => Effect.gen(function* () {
|
|
|
615
660
|
const streamOpenAiRequest = (config, request, client) => Stream.unwrap(Effect.gen(function* () {
|
|
616
661
|
const providerIdentity = config.providerIdentity ?? defaultOpenAiProviderIdentity;
|
|
617
662
|
const response = yield* postOpenAiRequest(config, providerIdentity, yield* sendOpenAiRequestBody(config, request, providerIdentity), client);
|
|
618
|
-
|
|
663
|
+
const responseFormat = yield* expectChatSseResponse(providerIdentity, response);
|
|
664
|
+
return streamOpenAiChatResponse(providerIdentity, config.reasoningContent ?? false, responseFormat, response);
|
|
619
665
|
}));
|
|
620
666
|
const openAiProviderStream = (config, request, client) => config.streaming === true ? streamOpenAiRequest(config, request, client) : Stream.fromEffect(sendOpenAiRequest(config, request, client)).pipe(Stream.flatMap((events) => Stream.fromIterable(events)));
|
|
621
667
|
const makeOpenAiProviderLayer = (config) => Layer.effect(LLMProvider, Effect.gen(function* () {
|