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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +4 -0
  2. package/dist/client/attachments.d.mts +8 -0
  3. package/dist/client/attachments.d.mts.map +1 -0
  4. package/dist/client/attachments.mjs +36 -0
  5. package/dist/client/attachments.mjs.map +1 -0
  6. package/dist/client/index.d.mts +2 -1
  7. package/dist/client/index.mjs +2 -1
  8. package/dist/client/transport.d.mts +1 -1
  9. package/dist/client/transport.mjs +1 -1
  10. package/dist/compaction/transformer.d.mts +1 -1
  11. package/dist/loop/error.d.mts +1 -1
  12. package/dist/loop/error.mjs +1 -1
  13. package/dist/loop/llm-event.d.mts +1 -1
  14. package/dist/loop/llm-event.mjs +1 -1
  15. package/dist/loop/run.d.mts +1 -1
  16. package/dist/loop/run.mjs +1 -1
  17. package/dist/loop/services/context-transformer.d.mts +1 -1
  18. package/dist/loop/services/llm-provider.d.mts +1 -1
  19. package/dist/loop/services/tool-executor.d.mts +1 -1
  20. package/dist/loop/testing/faux-provider.mjs +1 -1
  21. package/dist/loop/testing/test-tool-executor.mjs +1 -1
  22. package/dist/protocol/content.d.mts +15 -1
  23. package/dist/protocol/content.d.mts.map +1 -1
  24. package/dist/protocol/content.mjs +76 -1
  25. package/dist/protocol/content.mjs.map +1 -1
  26. package/dist/protocol/index.d.mts +2 -2
  27. package/dist/protocol/index.d.mts.map +1 -1
  28. package/dist/protocol/index.mjs +2 -2
  29. package/dist/providers/anthropic/claude-provider.d.mts.map +1 -1
  30. package/dist/providers/anthropic/claude-provider.mjs +12 -2
  31. package/dist/providers/anthropic/claude-provider.mjs.map +1 -1
  32. package/dist/providers/openai/codex-provider.d.mts +1 -1
  33. package/dist/providers/openai/codex-provider.mjs +1 -1
  34. package/dist/providers/openai/provider.d.mts.map +1 -1
  35. package/dist/providers/openai/provider.mjs +12 -2
  36. package/dist/providers/openai/provider.mjs.map +1 -1
  37. package/dist/react/chat-items.d.mts +1 -1
  38. package/dist/react/chat-items.mjs +1 -1
  39. package/dist/react/chat-messages.mjs +1 -1
  40. package/dist/react/chat-session-events.d.mts +1 -1
  41. package/dist/react/chat-session-events.mjs +1 -1
  42. package/dist/react/use-agent-chat.mjs +1 -1
  43. package/dist/runtime/error.d.mts +1 -1
  44. package/dist/runtime/error.mjs +1 -1
  45. package/dist/runtime/run-runtime.d.mts +1 -1
  46. package/dist/runtime/session-event-store.d.mts +1 -1
  47. package/dist/runtime/session-event-store.mjs +1 -1
  48. package/dist/tools/question.d.mts +1 -1
  49. package/dist/tools/question.mjs +1 -1
  50. package/dist/tools/registry.d.mts +1 -1
  51. package/dist/tools/registry.mjs +1 -1
  52. package/dist/tools/task.d.mts +1 -1
  53. package/dist/tools/task.mjs +1 -1
  54. package/dist/voice/tool-bridge.mjs +1 -1
  55. package/package.json +1 -1
  56. package/src/client/attachments.ts +45 -0
  57. package/src/client/index.ts +1 -0
  58. package/src/protocol/content.ts +129 -0
  59. package/src/protocol/index.ts +6 -0
  60. package/src/providers/anthropic/claude-provider.ts +23 -1
  61. package/src/providers/openai/provider.ts +23 -1
package/README.md CHANGED
@@ -130,6 +130,10 @@ Build sources with `inlineBase64AttachmentSource`, `urlAttachmentSource`, or
130
130
  for simple apps, or persist `Ref` values and call `resolveContentAttachmentSources` at your storage
131
131
  boundary before provider execution. Host apps own upload, auth, retention, and ref hydration policy.
132
132
 
133
+ For text files, use `documentPartFromText`, `inferTextDocumentMimeType`, and the client helper
134
+ `documentPartFromTextFile` to create UTF-8 inline `DocumentPart` values without trusting filename
135
+ extensions over explicit non-text MIME types.
136
+
133
137
  Use model capabilities like `textOnlyModelCapabilities`, `textImageModelCapabilities`, or
134
138
  `textImageDocumentModelCapabilities` so the loop rejects unsupported inputs before provider calls.
135
139
 
@@ -0,0 +1,8 @@
1
+ //#region src/client/attachments.d.ts
2
+ declare const textFromBlob: (blob: Blob) => Promise<string>;
3
+ declare const documentPartFromTextFile: (file: File, options?: {
4
+ readonly title?: string;
5
+ }) => Promise<import("@yolk-sdk/agent/protocol").DocumentPart | undefined>;
6
+ //#endregion
7
+ export { documentPartFromTextFile, textFromBlob };
8
+ //# sourceMappingURL=attachments.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.d.mts","names":[],"sources":["../../src/client/attachments.ts"],"mappings":";cAEa,YAAA,GAAgB,IAAA,EAAM,IAAA,KAAI,OAAA;AAAA,cAqB1B,wBAAA,GACX,IAAA,EAAM,IAAA,EACN,OAAA;EAAA,SACW,KAAA;AAAA,MACV,OAAA,oCAAA,YAAA"}
@@ -0,0 +1,36 @@
1
+ import { documentPartFromText, inferTextDocumentMimeType } from "@yolk-sdk/agent/protocol";
2
+ //#region src/client/attachments.ts
3
+ const textFromBlob = (blob) => {
4
+ if (typeof blob.text === "function") return blob.text();
5
+ if (typeof FileReader === "undefined") return Promise.reject(/* @__PURE__ */ new Error("Could not read text"));
6
+ return new Promise((resolve, reject) => {
7
+ const reader = new FileReader();
8
+ reader.addEventListener("load", () => {
9
+ if (typeof reader.result === "string") {
10
+ resolve(reader.result);
11
+ return;
12
+ }
13
+ reject(/* @__PURE__ */ new Error("Could not read text"));
14
+ });
15
+ reader.addEventListener("error", () => reject(/* @__PURE__ */ new Error("Could not read text")));
16
+ reader.addEventListener("abort", () => reject(/* @__PURE__ */ new Error("Could not read text")));
17
+ reader.readAsText(blob);
18
+ });
19
+ };
20
+ const documentPartFromTextFile = async (file, options) => {
21
+ const mimeType = inferTextDocumentMimeType({
22
+ filename: file.name,
23
+ mimeType: file.type
24
+ });
25
+ if (mimeType === void 0) return void 0;
26
+ return documentPartFromText({
27
+ text: await textFromBlob(file),
28
+ filename: file.name,
29
+ mimeType,
30
+ title: options?.title
31
+ });
32
+ };
33
+ //#endregion
34
+ export { documentPartFromTextFile, textFromBlob };
35
+
36
+ //# sourceMappingURL=attachments.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachments.mjs","names":[],"sources":["../../src/client/attachments.ts"],"sourcesContent":["import { documentPartFromText, inferTextDocumentMimeType } from '@yolk-sdk/agent/protocol'\n\nexport const textFromBlob = (blob: Blob) => {\n if (typeof blob.text === 'function') return blob.text()\n if (typeof FileReader === 'undefined') return Promise.reject(new Error('Could not read text'))\n\n return new Promise<string>((resolve, reject) => {\n const reader = new FileReader()\n\n reader.addEventListener('load', () => {\n if (typeof reader.result === 'string') {\n resolve(reader.result)\n return\n }\n\n reject(new Error('Could not read text'))\n })\n reader.addEventListener('error', () => reject(new Error('Could not read text')))\n reader.addEventListener('abort', () => reject(new Error('Could not read text')))\n reader.readAsText(blob)\n })\n}\n\nexport const documentPartFromTextFile = async (\n file: File,\n options?: {\n readonly title?: string\n }\n) => {\n const mimeType = inferTextDocumentMimeType({\n filename: file.name,\n mimeType: file.type\n })\n\n if (mimeType === undefined) return undefined\n\n const text = await textFromBlob(file)\n\n return documentPartFromText({\n text,\n filename: file.name,\n mimeType,\n title: options?.title\n })\n}\n"],"mappings":";;AAEA,MAAa,gBAAgB,SAAe;CAC1C,IAAI,OAAO,KAAK,SAAS,YAAY,OAAO,KAAK,KAAK;CACtD,IAAI,OAAO,eAAe,aAAa,OAAO,QAAQ,uBAAO,IAAI,MAAM,qBAAqB,CAAC;CAE7F,OAAO,IAAI,SAAiB,SAAS,WAAW;EAC9C,MAAM,SAAS,IAAI,WAAW;EAE9B,OAAO,iBAAiB,cAAc;GACpC,IAAI,OAAO,OAAO,WAAW,UAAU;IACrC,QAAQ,OAAO,MAAM;IACrB;GACF;GAEA,uBAAO,IAAI,MAAM,qBAAqB,CAAC;EACzC,CAAC;EACD,OAAO,iBAAiB,eAAe,uBAAO,IAAI,MAAM,qBAAqB,CAAC,CAAC;EAC/E,OAAO,iBAAiB,eAAe,uBAAO,IAAI,MAAM,qBAAqB,CAAC,CAAC;EAC/E,OAAO,WAAW,IAAI;CACxB,CAAC;AACH;AAEA,MAAa,2BAA2B,OACtC,MACA,YAGG;CACH,MAAM,WAAW,0BAA0B;EACzC,UAAU,KAAK;EACf,UAAU,KAAK;CACjB,CAAC;CAED,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;CAInC,OAAO,qBAAqB;EAC1B,MAAA,MAHiB,aAAa,IAAI;EAIlC,UAAU,KAAK;EACf;EACA,OAAO,SAAS;CAClB,CAAC;AACH"}
@@ -1,3 +1,4 @@
1
+ import { documentPartFromTextFile, textFromBlob } from "./attachments.mjs";
1
2
  import { AgentClientState, AgentRunStatus, AgentToolRun, AgentTranscript, ApplyAgentEventOptions, appendAgentMessage, applyAgentEvent, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, submitAgentUserMessage, toolRunsFromHitlRequests } from "./state.mjs";
2
3
  import { AgentHttpResponseInfo, AgentTransportError, CancelAgentRunRequest, StreamAgentEventsRequest, StreamAgentRunEventsRequest, StreamCloudflareAgentEventsRequest, SubmitQuestionResponseRequest, SubmitToolApprovalResponseRequest, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitQuestionResponse, submitToolApprovalResponse } from "./transport.mjs";
3
- export { type AgentClientState, type AgentHttpResponseInfo, type AgentRunStatus, type AgentToolRun, type AgentTranscript, AgentTransportError, type ApplyAgentEventOptions, type CancelAgentRunRequest, type StreamAgentEventsRequest, type StreamAgentRunEventsRequest, type StreamCloudflareAgentEventsRequest, type SubmitQuestionResponseRequest, type SubmitToolApprovalResponseRequest, appendAgentMessage, applyAgentEvent, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitAgentUserMessage, submitQuestionResponse, submitToolApprovalResponse, toolRunsFromHitlRequests };
4
+ export { type AgentClientState, type AgentHttpResponseInfo, type AgentRunStatus, type AgentToolRun, type AgentTranscript, AgentTransportError, type ApplyAgentEventOptions, type CancelAgentRunRequest, type StreamAgentEventsRequest, type StreamAgentRunEventsRequest, type StreamCloudflareAgentEventsRequest, type SubmitQuestionResponseRequest, type SubmitToolApprovalResponseRequest, appendAgentMessage, applyAgentEvent, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, completedToolRuns, documentPartFromTextFile, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitAgentUserMessage, submitQuestionResponse, submitToolApprovalResponse, textFromBlob, toolRunsFromHitlRequests };
@@ -1,3 +1,4 @@
1
+ import { documentPartFromTextFile, textFromBlob } from "./attachments.mjs";
1
2
  import { appendAgentMessage, applyAgentEvent, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, submitAgentUserMessage, toolRunsFromHitlRequests } from "./state.mjs";
2
3
  import { AgentTransportError, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitQuestionResponse, submitToolApprovalResponse } from "./transport.mjs";
3
- export { AgentTransportError, appendAgentMessage, applyAgentEvent, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitAgentUserMessage, submitQuestionResponse, submitToolApprovalResponse, toolRunsFromHitlRequests };
4
+ export { AgentTransportError, appendAgentMessage, applyAgentEvent, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, completedToolRuns, documentPartFromTextFile, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitAgentUserMessage, submitQuestionResponse, submitToolApprovalResponse, textFromBlob, toolRunsFromHitlRequests };
@@ -1,8 +1,8 @@
1
1
  import { AgentTranscript } from "./state.mjs";
2
+ import { AgentEvent, AgentReasoningEffort, HitlResponse, QuestionResponse, ToolApprovalResponse } from "@yolk-sdk/agent/protocol";
2
3
  import { Cause, Effect, Layer, Stream } from "effect";
3
4
  import { HttpClient } from "effect/unstable/http";
4
5
  import * as Schema from "effect/Schema";
5
- import { AgentEvent, AgentReasoningEffort, HitlResponse, QuestionResponse, ToolApprovalResponse } from "@yolk-sdk/agent/protocol";
6
6
 
7
7
  //#region src/client/transport.d.ts
8
8
  declare const AgentTransportError_base: Schema.Class<AgentTransportError, Schema.TaggedStruct<"AgentTransportError", {
@@ -1,7 +1,7 @@
1
+ import { AgentEvent, AgentWebSocketServerMessage, QuestionResponseInput, ToolApprovalResponseInput, UserInput } from "@yolk-sdk/agent/protocol";
1
2
  import { Cause, Channel, Effect, Exit, Pull, Queue, Ref, Scope, Stream } from "effect";
2
3
  import { FetchHttpClient, HttpClient, HttpClientRequest } from "effect/unstable/http";
3
4
  import * as Schema from "effect/Schema";
4
- import { AgentEvent, AgentWebSocketServerMessage, QuestionResponseInput, ToolApprovalResponseInput, UserInput } from "@yolk-sdk/agent/protocol";
5
5
  //#region src/client/transport.ts
6
6
  var AgentTransportError = class extends Schema.TaggedErrorClass()("AgentTransportError", {
7
7
  message: Schema.String,
@@ -1,7 +1,7 @@
1
1
  import { TranscriptTokenEstimator } from "./estimator.mjs";
2
2
  import { CompactionResult } from "./window.mjs";
3
- import { Layer } from "effect";
4
3
  import { AgentMessage } from "@yolk-sdk/agent/protocol";
4
+ import { Layer } from "effect";
5
5
  import { ContextTransformer } from "@yolk-sdk/agent/loop";
6
6
 
7
7
  //#region src/compaction/transformer.d.ts
@@ -1,5 +1,5 @@
1
- import * as Schema from "effect/Schema";
2
1
  import { AgentError } from "@yolk-sdk/agent/protocol";
2
+ import * as Schema from "effect/Schema";
3
3
 
4
4
  //#region src/loop/error.d.ts
5
5
  declare const LLMError_base: Schema.Class<LLMError, Schema.TaggedStruct<"LLMError", {
@@ -1,5 +1,5 @@
1
- import * as Schema from "effect/Schema";
2
1
  import { AgentError } from "@yolk-sdk/agent/protocol";
2
+ import * as Schema from "effect/Schema";
3
3
  //#region src/loop/error.ts
4
4
  var LLMError = class extends Schema.TaggedErrorClass()("LLMError", {
5
5
  cause: Schema.Literals([
@@ -1,5 +1,5 @@
1
- import * as Schema from "effect/Schema";
2
1
  import { AgentUsage, ToolCall, ToolResult } from "@yolk-sdk/agent/protocol";
2
+ import * as Schema from "effect/Schema";
3
3
 
4
4
  //#region src/loop/llm-event.d.ts
5
5
  declare const LLMTextDelta_base: Schema.Class<LLMTextDelta, Schema.TaggedStruct<"TextDelta", {
@@ -1,5 +1,5 @@
1
- import * as Schema from "effect/Schema";
2
1
  import { AgentUsage, ToolCall, ToolResult } from "@yolk-sdk/agent/protocol";
2
+ import * as Schema from "effect/Schema";
3
3
  //#region src/loop/llm-event.ts
4
4
  var LLMTextDelta = class extends Schema.TaggedClass()("TextDelta", { text: Schema.String }) {};
5
5
  var LLMReasoningDelta = class extends Schema.TaggedClass()("ReasoningDelta", { text: Schema.String }) {};
@@ -3,8 +3,8 @@ import { ContextTransformer } from "./services/context-transformer.mjs";
3
3
  import { LLMProvider } from "./services/llm-provider.mjs";
4
4
  import { LoopConfig } from "./services/loop-config.mjs";
5
5
  import { ToolExecutor } from "./services/tool-executor.mjs";
6
- import { Stream } from "effect";
7
6
  import { AgentEvent, AgentMessage, AgentModelCapabilities, AgentReasoningEffort, AgentUsage, HitlResponse, ToolCall, ToolDef } from "@yolk-sdk/agent/protocol";
7
+ import { Stream } from "effect";
8
8
 
9
9
  //#region src/loop/run.d.ts
10
10
  type AgentLoopRunId = string;
package/dist/loop/run.mjs CHANGED
@@ -4,9 +4,9 @@ import { ContextTransformer } from "./services/context-transformer.mjs";
4
4
  import { LLMProvider } from "./services/llm-provider.mjs";
5
5
  import { LoopConfig } from "./services/loop-config.mjs";
6
6
  import { ToolExecutor } from "./services/tool-executor.mjs";
7
+ import { AgentAwaitingInput, AgentEnd, AgentRetry, AgentStart, AssistantMessageEvent, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionRequest, QuestionRequested, QuestionToolParams, SubagentCompleted, SubagentStarted, ToolApprovalRequest, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UsageUpdate, addAgentUsage, assistantHostToolCalls, contentParts, contentPreview, formatQuestionResponseContent, hitlResponseEvent, makeSubagentRunId, questionResponseStructuredContent, zeroAgentUsage } from "@yolk-sdk/agent/protocol";
7
8
  import { Clock, Effect, Ref, Stream } from "effect";
8
9
  import * as Schema from "effect/Schema";
9
- import { AgentAwaitingInput, AgentEnd, AgentRetry, AgentStart, AssistantMessageEvent, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionRequest, QuestionRequested, QuestionToolParams, SubagentCompleted, SubagentStarted, ToolApprovalRequest, ToolApprovalRequested, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, ToolResultMessage, TurnEnd, TurnStart, UsageUpdate, addAgentUsage, assistantHostToolCalls, contentParts, contentPreview, formatQuestionResponseContent, hitlResponseEvent, makeSubagentRunId, questionResponseStructuredContent, zeroAgentUsage } from "@yolk-sdk/agent/protocol";
10
10
  //#region src/loop/run.ts
11
11
  const questionToolName = "question";
12
12
  const objectField = (input, key) => input !== null && typeof input === "object" ? Object.getOwnPropertyDescriptor(input, key)?.value : void 0;
@@ -1,6 +1,6 @@
1
1
  import { ContextTransformError } from "../error.mjs";
2
- import { Context, Effect, Layer } from "effect";
3
2
  import { AgentEvent, AgentMessage } from "@yolk-sdk/agent/protocol";
3
+ import { Context, Effect, Layer } from "effect";
4
4
 
5
5
  //#region src/loop/services/context-transformer.d.ts
6
6
  type ContextTransformResult = {
@@ -1,7 +1,7 @@
1
1
  import { LLMEvent } from "../llm-event.mjs";
2
2
  import { LLMProviderError } from "../error.mjs";
3
- import { Context, Stream } from "effect";
4
3
  import { AgentMessage, AgentReasoningEffort, ToolDef } from "@yolk-sdk/agent/protocol";
4
+ import { Context, Stream } from "effect";
5
5
 
6
6
  //#region src/loop/services/llm-provider.d.ts
7
7
  type LLMRequest = {
@@ -1,6 +1,6 @@
1
1
  import { ToolError } from "../error.mjs";
2
- import { Context, Effect } from "effect";
3
2
  import { ToolCall, ToolResult } from "@yolk-sdk/agent/protocol";
3
+ import { Context, Effect } from "effect";
4
4
 
5
5
  //#region src/loop/services/tool-executor.d.ts
6
6
  declare const ToolExecutor_base: Context.ServiceClass<ToolExecutor, "@yolk-sdk/agent/loop/ToolExecutor", {
@@ -1,8 +1,8 @@
1
1
  import { FauxExhaustedError } from "../error.mjs";
2
2
  import { LLMDone, LLMReasoningDelta as LLMReasoningDelta$1, LLMTextDelta as LLMTextDelta$1, LLMToolCall, LLMUsage } from "../llm-event.mjs";
3
3
  import { LLMProvider } from "../services/llm-provider.mjs";
4
- import { Effect, Layer, Ref, Stream } from "effect";
5
4
  import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall } from "@yolk-sdk/agent/protocol";
5
+ import { Effect, Layer, Ref, Stream } from "effect";
6
6
  //#region src/loop/testing/faux-provider.ts
7
7
  const Reply = {
8
8
  text: (text) => ({ events: [...text.split("").map((character) => LLMTextDelta$1.make({ text: character })), LLMDone.make({ stopReason: "stop" })] }),
@@ -1,7 +1,7 @@
1
1
  import { ToolError } from "../error.mjs";
2
2
  import { ToolExecutor } from "../services/tool-executor.mjs";
3
- import { Effect, Layer } from "effect";
4
3
  import { ToolResult } from "@yolk-sdk/agent/protocol";
4
+ import { Effect, Layer } from "effect";
5
5
  //#region src/loop/testing/test-tool-executor.ts
6
6
  const TestToolExecutor = { layer: (resultsByName) => Layer.succeed(ToolExecutor, ToolExecutor.of({ execute: (call) => {
7
7
  const content = resultsByName[call.name];
@@ -63,7 +63,21 @@ declare const refAttachmentSource: (id: string) => RefAttachmentSource;
63
63
  declare const inlineBase64Source: (data: string) => InlineBase64AttachmentSource;
64
64
  declare const attachmentSourcePreview: (source: AttachmentSource) => string;
65
65
  declare const attachmentSourceDataUrl: (source: AttachmentSource, mimeType: string) => Option.Option<string>;
66
+ declare const isTextDocumentMimeType: (mimeType: string) => boolean;
67
+ declare const textDocumentMimeTypeFromFilename: (filename: string) => string | undefined;
68
+ declare const inferTextDocumentMimeType: (input: {
69
+ readonly filename: string;
70
+ readonly mimeType: string;
71
+ }) => string | undefined;
72
+ declare const textToBase64Utf8: (text: string) => string;
73
+ declare const documentPartFromText: (input: {
74
+ readonly text: string;
75
+ readonly filename: string;
76
+ readonly mimeType: string;
77
+ readonly title?: string;
78
+ }) => DocumentPart | undefined;
79
+ declare const attachmentSourceText: (source: AttachmentSource) => Effect.Effect<Option.Option<string>, unknown, never>;
66
80
  declare const attachmentSourceBase64: (source: AttachmentSource) => Option.Option<string>;
67
81
  //#endregion
68
- export { 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 };
82
+ export { 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 };
69
83
  //# sourceMappingURL=content.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"content.d.mts","names":[],"sources":["../../src/protocol/content.ts"],"mappings":";;;;cACuC,aAAA;;;cAE1B,QAAA,SAAiB,aAE5B;AAAA,cAAG,iCAAA;;;cAEQ,4BAAA,SAAqC,iCAKjD;AAAA,cAAG,wBAAA;;;cAES,mBAAA,SAA4B,wBAEvC;AAAA,cAAG,wBAAA;;;cAEQ,mBAAA,SAA4B,wBAEvC;AAAA,cAEW,gBAAA,EAAgB,MAAA,CAAA,KAAA,kBAAA,4BAAA,SAAA,mBAAA,SAAA,mBAAA;AAAA,KAKjB,gBAAA,UAA0B,gBAAA,CAAiB,IAAI;AAAA,cAAA,cAAA;;;;;;;;cAE9C,SAAA,SAAkB,cAO7B;AAAA,cAAG,iBAAA;;;;;;cAEQ,YAAA,SAAqB,iBAKhC;AAAA,cAAG,cAAA;;;;;;cAEQ,SAAA,SAAkB,cAK7B;AAAA,cAEW,WAAA,EAAW,MAAA,CAAA,KAAA,kBAAA,QAAA,SAAA,SAAA,SAAA,YAAA,SAAA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BAAA,KAAgB,MAAA,CAAA,MAAA"}
@@ -108,6 +108,81 @@ const attachmentSourceDataUrl = (source, mimeType) => {
108
108
  case "Ref": return Option.none();
109
109
  }
110
110
  };
111
+ const normalizeMimeType = (mimeType) => mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
112
+ const textDocumentMimeTypeByExtension = {
113
+ ".csv": "text/csv",
114
+ ".css": "text/css",
115
+ ".gql": "application/graphql",
116
+ ".graphql": "application/graphql",
117
+ ".html": "text/html",
118
+ ".js": "application/javascript",
119
+ ".jsx": "application/javascript",
120
+ ".json": "application/json",
121
+ ".jsonl": "application/x-ndjson",
122
+ ".md": "text/markdown",
123
+ ".markdown": "text/markdown",
124
+ ".sql": "application/sql",
125
+ ".toml": "application/toml",
126
+ ".ts": "application/typescript",
127
+ ".tsx": "application/typescript",
128
+ ".txt": "text/plain",
129
+ ".xml": "application/xml",
130
+ ".yaml": "application/yaml",
131
+ ".yml": "application/yaml"
132
+ };
133
+ const isUnknownDocumentMimeType = (mimeType) => mimeType.length === 0 || mimeType === "application/octet-stream" || mimeType === "binary/octet-stream";
134
+ const isTextDocumentMimeType = (mimeType) => {
135
+ const normalized = normalizeMimeType(mimeType);
136
+ return normalized.startsWith("text/") || normalized === "application/json" || normalized === "application/ld+json" || normalized === "application/jsonl" || normalized === "application/x-ndjson" || normalized === "application/javascript" || normalized === "application/x-javascript" || normalized === "application/typescript" || normalized === "application/x-typescript" || normalized === "application/xml" || normalized === "application/yaml" || normalized === "application/x-yaml" || normalized === "application/toml" || normalized === "application/markdown" || normalized === "application/sql" || normalized === "application/graphql" || normalized.endsWith("+json") || normalized.endsWith("+xml");
137
+ };
138
+ const textDocumentMimeTypeFromFilename = (filename) => {
139
+ const normalized = filename.trim().toLowerCase();
140
+ return Object.entries(textDocumentMimeTypeByExtension).find(([extension]) => normalized.endsWith(extension))?.[1];
141
+ };
142
+ const inferTextDocumentMimeType = (input) => {
143
+ const normalized = normalizeMimeType(input.mimeType);
144
+ if (isTextDocumentMimeType(normalized)) return normalized;
145
+ if (!isUnknownDocumentMimeType(normalized)) return void 0;
146
+ return textDocumentMimeTypeFromFilename(input.filename);
147
+ };
148
+ const textToBase64Utf8 = (text) => {
149
+ const bytes = new TextEncoder().encode(text);
150
+ let binary = "";
151
+ for (const byte of bytes) binary += String.fromCharCode(byte);
152
+ return globalThis.btoa(binary);
153
+ };
154
+ const documentPartFromText = (input) => {
155
+ const normalized = normalizeMimeType(input.mimeType);
156
+ const mimeType = inferTextDocumentMimeType({
157
+ filename: input.filename,
158
+ mimeType: input.mimeType
159
+ }) ?? (isUnknownDocumentMimeType(normalized) ? "text/plain" : void 0);
160
+ if (mimeType === void 0) return void 0;
161
+ const base = {
162
+ source: inlineBase64AttachmentSource(textToBase64Utf8(input.text)),
163
+ mimeType,
164
+ filename: input.filename
165
+ };
166
+ return input.title === void 0 ? DocumentPart.make(base) : DocumentPart.make({
167
+ ...base,
168
+ title: input.title
169
+ });
170
+ };
171
+ const decodeBase64Utf8 = (data) => {
172
+ const binary = globalThis.atob(data);
173
+ const bytes = Uint8Array.from(binary, (character) => character.charCodeAt(0));
174
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
175
+ };
176
+ const attachmentSourceText = (source) => {
177
+ switch (source._tag) {
178
+ case "InlineBase64": return Effect.try({
179
+ try: () => Option.some(decodeBase64Utf8(source.data)),
180
+ catch: (error) => error
181
+ });
182
+ case "Url":
183
+ case "Ref": return Effect.succeed(Option.none());
184
+ }
185
+ };
111
186
  const attachmentSourceBase64 = (source) => {
112
187
  switch (source._tag) {
113
188
  case "InlineBase64": return Option.some(source.data);
@@ -116,6 +191,6 @@ const attachmentSourceBase64 = (source) => {
116
191
  }
117
192
  };
118
193
  //#endregion
119
- export { 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 };
194
+ export { 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 };
120
195
 
121
196
  //# sourceMappingURL=content.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"content.mjs","names":["Arr"],"sources":["../../src/protocol/content.ts"],"sourcesContent":["import { Array as Arr, Effect, Option } from 'effect'\nimport * as Schema from 'effect/Schema'\n\nexport class TextPart extends Schema.TaggedClass<TextPart>()('Text', {\n text: Schema.String\n}) {}\n\nexport class InlineBase64AttachmentSource extends Schema.TaggedClass<InlineBase64AttachmentSource>()(\n 'InlineBase64',\n {\n data: Schema.String\n }\n) {}\n\nexport class UrlAttachmentSource extends Schema.TaggedClass<UrlAttachmentSource>()('Url', {\n url: Schema.String\n}) {}\n\nexport class RefAttachmentSource extends Schema.TaggedClass<RefAttachmentSource>()('Ref', {\n id: Schema.String\n}) {}\n\nexport const AttachmentSource = Schema.Union([\n InlineBase64AttachmentSource,\n UrlAttachmentSource,\n RefAttachmentSource\n])\nexport type AttachmentSource = typeof AttachmentSource.Type\n\nexport class ImagePart extends Schema.TaggedClass<ImagePart>()('Image', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n title: Schema.optional(Schema.String),\n width: Schema.optional(Schema.Number),\n height: Schema.optional(Schema.Number)\n}) {}\n\nexport class DocumentPart extends Schema.TaggedClass<DocumentPart>()('Document', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.String,\n title: Schema.optional(Schema.String)\n}) {}\n\nexport class AudioPart extends Schema.TaggedClass<AudioPart>()('Audio', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n durationMs: Schema.optional(Schema.Number)\n}) {}\n\nexport const ContentPart = Schema.Union([TextPart, ImagePart, DocumentPart, AudioPart])\nexport type ContentPart = typeof ContentPart.Type\n\nexport const Content = Schema.Union([Schema.String, Schema.Array(ContentPart)])\nexport type Content = typeof Content.Type\n\nexport type AttachmentContentPart = ImagePart | DocumentPart | AudioPart\n\nexport type AttachmentSourceResolver<E = never, R = never> = (\n part: AttachmentContentPart\n) => Effect.Effect<AttachmentSource, E, R>\n\nconst resolveContentPartAttachmentSource = <E, R>(\n part: ContentPart,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<ContentPart, E, R> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed(part)\n case 'Image':\n return resolver(part).pipe(\n Effect.map(source =>\n ImagePart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title,\n width: part.width,\n height: part.height\n })\n )\n )\n case 'Document':\n return resolver(part).pipe(\n Effect.map(source =>\n DocumentPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title\n })\n )\n )\n case 'Audio':\n return resolver(part).pipe(\n Effect.map(source =>\n AudioPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n durationMs: part.durationMs\n })\n )\n )\n }\n}\n\nexport const resolveContentAttachmentSources = <E, R>(\n content: Content,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<Content, E, R> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, part => resolveContentPartAttachmentSource(part, resolver))\n\nexport const contentPartText = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n case 'Document':\n case 'Audio':\n return ''\n }\n}\n\nexport const contentPartPreview = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n return 'Image'\n case 'Document':\n return `Document: ${part.title ?? part.filename}`\n case 'Audio':\n return 'Audio'\n }\n}\n\nexport const contentText = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartText).join('')\n\nexport const contentPreview = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartPreview).join(', ')\n\nexport const contentParts = (content: Content): ReadonlyArray<ContentPart> =>\n typeof content === 'string' ? [TextPart.make({ text: content })] : content\n\nexport const isContentEmpty = (content: Content) =>\n typeof content === 'string'\n ? content.length === 0\n : content.length === 0 ||\n Arr.every(content, part => part._tag === 'Text' && part.text.length === 0)\n\nexport const appendTextToContent = (content: Content, text: string): Content => {\n if (typeof content === 'string') {\n return `${content}${text}`\n }\n\n return Option.match(Arr.last(content), {\n onNone: () => [TextPart.make({ text })],\n onSome: last =>\n last._tag !== 'Text'\n ? [...content, TextPart.make({ text })]\n : Arr.map(content, (part, index) =>\n index === content.length - 1 && part._tag === 'Text'\n ? TextPart.make({ text: `${part.text}${text}` })\n : part\n )\n })\n}\n\nexport const inlineBase64AttachmentSource = (data: string) => InlineBase64AttachmentSource.make({ data })\n\nexport const urlAttachmentSource = (url: string) => UrlAttachmentSource.make({ url })\n\nexport const refAttachmentSource = (id: string) => RefAttachmentSource.make({ id })\n\nexport const inlineBase64Source = inlineBase64AttachmentSource\n\nexport const attachmentSourcePreview = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return 'inline'\n case 'Url':\n return source.url\n case 'Ref':\n return source.id\n }\n}\n\nexport const attachmentSourceDataUrl = (source: AttachmentSource, mimeType: string) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(`data:${mimeType};base64,${source.data}`)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n\nexport const attachmentSourceBase64 = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.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MAAa,0BAA0B,WAA6B;CAClE,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO,OAAO,KAAK,OAAO,IAAI;EAChC,KAAK;EACL,KAAK,OACH,OAAO,OAAO,KAAa;CAC/B;AACF"}
1
+ {"version":3,"file":"content.mjs","names":["Arr"],"sources":["../../src/protocol/content.ts"],"sourcesContent":["import { Array as Arr, Effect, Option } from 'effect'\nimport * as Schema from 'effect/Schema'\n\nexport class TextPart extends Schema.TaggedClass<TextPart>()('Text', {\n text: Schema.String\n}) {}\n\nexport class InlineBase64AttachmentSource extends Schema.TaggedClass<InlineBase64AttachmentSource>()(\n 'InlineBase64',\n {\n data: Schema.String\n }\n) {}\n\nexport class UrlAttachmentSource extends Schema.TaggedClass<UrlAttachmentSource>()('Url', {\n url: Schema.String\n}) {}\n\nexport class RefAttachmentSource extends Schema.TaggedClass<RefAttachmentSource>()('Ref', {\n id: Schema.String\n}) {}\n\nexport const AttachmentSource = Schema.Union([\n InlineBase64AttachmentSource,\n UrlAttachmentSource,\n RefAttachmentSource\n])\nexport type AttachmentSource = typeof AttachmentSource.Type\n\nexport class ImagePart extends Schema.TaggedClass<ImagePart>()('Image', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n title: Schema.optional(Schema.String),\n width: Schema.optional(Schema.Number),\n height: Schema.optional(Schema.Number)\n}) {}\n\nexport class DocumentPart extends Schema.TaggedClass<DocumentPart>()('Document', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.String,\n title: Schema.optional(Schema.String)\n}) {}\n\nexport class AudioPart extends Schema.TaggedClass<AudioPart>()('Audio', {\n source: AttachmentSource,\n mimeType: Schema.String,\n filename: Schema.optional(Schema.String),\n durationMs: Schema.optional(Schema.Number)\n}) {}\n\nexport const ContentPart = Schema.Union([TextPart, ImagePart, DocumentPart, AudioPart])\nexport type ContentPart = typeof ContentPart.Type\n\nexport const Content = Schema.Union([Schema.String, Schema.Array(ContentPart)])\nexport type Content = typeof Content.Type\n\nexport type AttachmentContentPart = ImagePart | DocumentPart | AudioPart\n\nexport type AttachmentSourceResolver<E = never, R = never> = (\n part: AttachmentContentPart\n) => Effect.Effect<AttachmentSource, E, R>\n\nconst resolveContentPartAttachmentSource = <E, R>(\n part: ContentPart,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<ContentPart, E, R> => {\n switch (part._tag) {\n case 'Text':\n return Effect.succeed(part)\n case 'Image':\n return resolver(part).pipe(\n Effect.map(source =>\n ImagePart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title,\n width: part.width,\n height: part.height\n })\n )\n )\n case 'Document':\n return resolver(part).pipe(\n Effect.map(source =>\n DocumentPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n title: part.title\n })\n )\n )\n case 'Audio':\n return resolver(part).pipe(\n Effect.map(source =>\n AudioPart.make({\n source,\n mimeType: part.mimeType,\n filename: part.filename,\n durationMs: part.durationMs\n })\n )\n )\n }\n}\n\nexport const resolveContentAttachmentSources = <E, R>(\n content: Content,\n resolver: AttachmentSourceResolver<E, R>\n): Effect.Effect<Content, E, R> =>\n typeof content === 'string'\n ? Effect.succeed(content)\n : Effect.forEach(content, part => resolveContentPartAttachmentSource(part, resolver))\n\nexport const contentPartText = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n case 'Document':\n case 'Audio':\n return ''\n }\n}\n\nexport const contentPartPreview = (part: ContentPart) => {\n switch (part._tag) {\n case 'Text':\n return part.text\n case 'Image':\n return 'Image'\n case 'Document':\n return `Document: ${part.title ?? part.filename}`\n case 'Audio':\n return 'Audio'\n }\n}\n\nexport const contentText = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartText).join('')\n\nexport const contentPreview = (content: Content) =>\n typeof content === 'string' ? content : Arr.map(content, contentPartPreview).join(', ')\n\nexport const contentParts = (content: Content): ReadonlyArray<ContentPart> =>\n typeof content === 'string' ? [TextPart.make({ text: content })] : content\n\nexport const isContentEmpty = (content: Content) =>\n typeof content === 'string'\n ? content.length === 0\n : content.length === 0 ||\n Arr.every(content, part => part._tag === 'Text' && part.text.length === 0)\n\nexport const appendTextToContent = (content: Content, text: string): Content => {\n if (typeof content === 'string') {\n return `${content}${text}`\n }\n\n return Option.match(Arr.last(content), {\n onNone: () => [TextPart.make({ text })],\n onSome: last =>\n last._tag !== 'Text'\n ? [...content, TextPart.make({ text })]\n : Arr.map(content, (part, index) =>\n index === content.length - 1 && part._tag === 'Text'\n ? TextPart.make({ text: `${part.text}${text}` })\n : part\n )\n })\n}\n\nexport const inlineBase64AttachmentSource = (data: string) => InlineBase64AttachmentSource.make({ data })\n\nexport const urlAttachmentSource = (url: string) => UrlAttachmentSource.make({ url })\n\nexport const refAttachmentSource = (id: string) => RefAttachmentSource.make({ id })\n\nexport const inlineBase64Source = inlineBase64AttachmentSource\n\nexport const attachmentSourcePreview = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return 'inline'\n case 'Url':\n return source.url\n case 'Ref':\n return source.id\n }\n}\n\nexport const attachmentSourceDataUrl = (source: AttachmentSource, mimeType: string) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(`data:${mimeType};base64,${source.data}`)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n\nconst normalizeMimeType = (mimeType: string) => mimeType.split(';', 1)[0]?.trim().toLowerCase() ?? ''\n\nconst textDocumentMimeTypeByExtension: Readonly<Record<string, string>> = {\n '.csv': 'text/csv',\n '.css': 'text/css',\n '.gql': 'application/graphql',\n '.graphql': 'application/graphql',\n '.html': 'text/html',\n '.js': 'application/javascript',\n '.jsx': 'application/javascript',\n '.json': 'application/json',\n '.jsonl': 'application/x-ndjson',\n '.md': 'text/markdown',\n '.markdown': 'text/markdown',\n '.sql': 'application/sql',\n '.toml': 'application/toml',\n '.ts': 'application/typescript',\n '.tsx': 'application/typescript',\n '.txt': 'text/plain',\n '.xml': 'application/xml',\n '.yaml': 'application/yaml',\n '.yml': 'application/yaml'\n}\n\nconst isUnknownDocumentMimeType = (mimeType: string) =>\n mimeType.length === 0 || mimeType === 'application/octet-stream' || mimeType === 'binary/octet-stream'\n\nexport const isTextDocumentMimeType = (mimeType: string) => {\n const normalized = normalizeMimeType(mimeType)\n\n return (\n normalized.startsWith('text/') ||\n normalized === 'application/json' ||\n normalized === 'application/ld+json' ||\n normalized === 'application/jsonl' ||\n normalized === 'application/x-ndjson' ||\n normalized === 'application/javascript' ||\n normalized === 'application/x-javascript' ||\n normalized === 'application/typescript' ||\n normalized === 'application/x-typescript' ||\n normalized === 'application/xml' ||\n normalized === 'application/yaml' ||\n normalized === 'application/x-yaml' ||\n normalized === 'application/toml' ||\n normalized === 'application/markdown' ||\n normalized === 'application/sql' ||\n normalized === 'application/graphql' ||\n normalized.endsWith('+json') ||\n normalized.endsWith('+xml')\n )\n}\n\nexport const textDocumentMimeTypeFromFilename = (filename: string) => {\n const normalized = filename.trim().toLowerCase()\n const entry = Object.entries(textDocumentMimeTypeByExtension).find(([extension]) =>\n normalized.endsWith(extension)\n )\n\n return entry?.[1]\n}\n\nexport const inferTextDocumentMimeType = (input: {\n readonly filename: string\n readonly mimeType: string\n}) => {\n const normalized = normalizeMimeType(input.mimeType)\n\n if (isTextDocumentMimeType(normalized)) return normalized\n if (!isUnknownDocumentMimeType(normalized)) return undefined\n\n return textDocumentMimeTypeFromFilename(input.filename)\n}\n\nexport const textToBase64Utf8 = (text: string) => {\n const bytes = new TextEncoder().encode(text)\n let binary = ''\n\n for (const byte of bytes) {\n binary += String.fromCharCode(byte)\n }\n\n return globalThis.btoa(binary)\n}\n\nexport const documentPartFromText = (input: {\n readonly text: string\n readonly filename: string\n readonly mimeType: string\n readonly title?: string\n}) => {\n const normalized = normalizeMimeType(input.mimeType)\n const mimeType = inferTextDocumentMimeType({\n filename: input.filename,\n mimeType: input.mimeType\n }) ?? (isUnknownDocumentMimeType(normalized) ? 'text/plain' : undefined)\n\n if (mimeType === undefined) return undefined\n\n const base = {\n source: inlineBase64AttachmentSource(textToBase64Utf8(input.text)),\n mimeType,\n filename: input.filename\n }\n\n return input.title === undefined\n ? DocumentPart.make(base)\n : DocumentPart.make({ ...base, title: input.title })\n}\n\nconst decodeBase64Utf8 = (data: string) => {\n const binary = globalThis.atob(data)\n const bytes = Uint8Array.from(binary, character => character.charCodeAt(0))\n\n return new TextDecoder('utf-8', { fatal: true }).decode(bytes)\n}\n\nexport const attachmentSourceText = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Effect.try({\n try: () => Option.some(decodeBase64Utf8(source.data)),\n catch: error => error\n })\n case 'Url':\n case 'Ref':\n return Effect.succeed(Option.none<string>())\n }\n}\n\nexport const attachmentSourceBase64 = (source: AttachmentSource) => {\n switch (source._tag) {\n case 'InlineBase64':\n return Option.some(source.data)\n case 'Url':\n case 'Ref':\n return Option.none<string>()\n }\n}\n"],"mappings":";;;AAGA,IAAa,WAAb,cAA8B,OAAO,YAAsB,EAAE,QAAQ,EACnE,MAAM,OAAO,OACf,CAAC,EAAE,CAAC;AAEJ,IAAa,+BAAb,cAAkD,OAAO,YAA0C,EACjG,gBACA,EACE,MAAM,OAAO,OACf,CACF,EAAE,CAAC;AAEH,IAAa,sBAAb,cAAyC,OAAO,YAAiC,EAAE,OAAO,EACxF,KAAK,OAAO,OACd,CAAC,EAAE,CAAC;AAEJ,IAAa,sBAAb,cAAyC,OAAO,YAAiC,EAAE,OAAO,EACxF,IAAI,OAAO,OACb,CAAC,EAAE,CAAC;AAEJ,MAAa,mBAAmB,OAAO,MAAM;CAC3C;CACA;CACA;AACF,CAAC;AAGD,IAAa,YAAb,cAA+B,OAAO,YAAuB,EAAE,SAAS;CACtE,QAAQ;CACR,UAAU,OAAO;CACjB,UAAU,OAAO,SAAS,OAAO,MAAM;CACvC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,OAAO,OAAO,SAAS,OAAO,MAAM;CACpC,QAAQ,OAAO,SAAS,OAA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wBAAwB,WAA6B;CAChE,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO,OAAO,IAAI;GAChB,WAAW,OAAO,KAAK,iBAAiB,OAAO,IAAI,CAAC;GACpD,QAAO,UAAS;EAClB,CAAC;EACH,KAAK;EACL,KAAK,OACH,OAAO,OAAO,QAAQ,OAAO,KAAa,CAAC;CAC/C;AACF;AAEA,MAAa,0BAA0B,WAA6B;CAClE,QAAQ,OAAO,MAAf;EACE,KAAK,gBACH,OAAO,OAAO,KAAK,OAAO,IAAI;EAChC,KAAK;EACL,KAAK,OACH,OAAO,OAAO,KAAa;CAC/B;AACF"}
@@ -1,5 +1,5 @@
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";
@@ -10,5 +10,5 @@ import { AgentWebSocketClientMessage, AgentWebSocketServerMessage, QuestionRespo
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, 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":";;;;;;;;;;KAiJY,SAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/protocol/index.ts"],"mappings":";;;;;;;;;;KAuJY,SAAA"}
@@ -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
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";
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, 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":";;;;;;KA0CY,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,gBAAA;EAAA,SACU,IAAA;EAAA,SAAuB,OAAA,WAAkB,aAAA,CAAc,kBAAA;AAAA;EAAA,SACvD,IAAA;EAAA,SAA4B,OAAA,EAAS,aAAA,CAAc,uBAAA;AAAA;AAAA,KAS7D,aAAA;EAAA,SACM,IAAA;EAAA,SACA,WAAA;EAAA,SACA,YAAA;AAAA;AAAA,KAGN,oBAAA;EAAA,SACM,KAAA;EAAA,SACA,MAAA,EAAQ,aAAA,CAAc,oBAAA;EAAA,SACtB,QAAA,EAAU,aAAA,CAAc,gBAAA;EAAA,SACxB,UAAA;EAAA,SACA,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,cA+d1B,6BAAA,GACX,QAAA,EAAU,kBAAA,CAAmB,kBAAA,KAC5B,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,QAAA;AAAA,cA4Ed,gCAAA,GAAoC,MAAA,EAAQ,6BAAA,KAA6B,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA"}
@@ -1,8 +1,8 @@
1
1
  import { anthropicClaudeAuthorizationHeaders, anthropicClaudeCodeEntrypoint, anthropicClaudeCodeVersion, anthropicClaudeOAuthUserAgent } from "./claude.mjs";
2
+ import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, attachmentSourceBase64, attachmentSourceText, isTextDocumentMimeType, messageContextText, prependMessageContextToContent } from "@yolk-sdk/agent/protocol";
2
3
  import { Effect, Layer, Option, Ref, Stream } from "effect";
3
4
  import { HttpClient, HttpClientRequest } from "effect/unstable/http";
4
5
  import * as Schema from "effect/Schema";
5
- import { AgentInputUsage, AgentOutputUsage, AgentUsage, ToolCall, assistantContent, assistantHostToolCalls, attachmentSourceBase64, messageContextText, prependMessageContextToContent } from "@yolk-sdk/agent/protocol";
6
6
  import { LLMDone, LLMError, LLMProvider, LLMReasoningDelta as LLMReasoningDelta$1, LLMTextDelta as LLMTextDelta$1, LLMToolCall, LLMUsage } from "@yolk-sdk/agent/loop";
7
7
  //#region src/providers/anthropic/claude-provider.ts
8
8
  const anthropicClaudeSystemIdentity = "You are Claude Code, Anthropic's official CLI for Claude.";
@@ -190,6 +190,16 @@ const unsupportedContentError = (contentType) => new LLMError({
190
190
  message: `${contentType} content is not supported by the Anthropic Claude provider yet`,
191
191
  retryable: false
192
192
  });
193
+ const textDocumentToAnthropicBlock = (part) => attachmentSourceText(part.source).pipe(Effect.mapError(() => unsupportedContentError("Invalid document text")), Effect.flatMap(Option.match({
194
+ onNone: () => Effect.fail(unsupportedContentError("Unresolved document source")),
195
+ onSome: (text) => {
196
+ const block = {
197
+ type: "text",
198
+ text: `Document: ${part.title ?? part.filename}\n\n${text}`
199
+ };
200
+ return Effect.succeed(block);
201
+ }
202
+ })));
193
203
  const contentPartToUserBlock = (part) => {
194
204
  switch (part._tag) {
195
205
  case "Text": return Effect.succeed({
@@ -207,7 +217,7 @@ const contentPartToUserBlock = (part) => {
207
217
  }
208
218
  })
209
219
  });
210
- case "Document": return part.mimeType === "application/pdf" ? Option.match(attachmentSourceBase64(part.source), {
220
+ case "Document": return isTextDocumentMimeType(part.mimeType) ? textDocumentToAnthropicBlock(part) : part.mimeType === "application/pdf" ? Option.match(attachmentSourceBase64(part.source), {
211
221
  onNone: () => Effect.fail(unsupportedContentError("Unresolved document source")),
212
222
  onSome: (data) => Effect.succeed({
213
223
  type: "document",