@effect-uai/anthropic 0.12.0 → 0.12.1

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.
@@ -1 +1 @@
1
- export { };
1
+ export {}
@@ -1,6 +1,6 @@
1
1
  import { emptyAccumulator, mergeUsage } from "./codec.mjs";
2
2
  import { applyEvent } from "./streamEvents.mjs";
3
- import { n as describe, r as it, t as globalExpect } from "./test.DNmyFkvJ-CPKukVWS.mjs";
3
+ import { n as describe, r as it, t as globalExpect } from "./test.DNmyFkvJ-N3QqMRwZ.mjs";
4
4
  //#region src/usage.test.ts
5
5
  const wire = {
6
6
  input_tokens: 94,
@@ -1 +1 @@
1
- {"version":3,"file":"usage.test.mjs","names":[],"sources":["../src/usage.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\"\nimport { type WireUsage, emptyAccumulator, mergeUsage } from \"./codec.js\"\nimport { type ProviderEvent, applyEvent } from \"./streamEvents.js\"\n\n// A completed cached turn: input split across post-breakpoint tokens, cache\n// reads, and cache writes, all billed separately.\nconst wire: WireUsage = {\n input_tokens: 94,\n output_tokens: 210,\n cache_read_input_tokens: 31851,\n cache_creation_input_tokens: 604,\n}\n\ndescribe(\"mergeUsage\", () => {\n it(\"keeps all three input buckets, not just cache reads\", () => {\n const usage = mergeUsage(emptyAccumulator, wire).usage\n expect(usage.input_tokens).toBe(94)\n expect(usage.input_tokens_details?.cached_tokens).toBe(31851)\n expect(usage.input_tokens_details?.cache_write_tokens).toBe(604)\n })\n\n it(\"totals every input bucket plus output\", () => {\n const usage = mergeUsage(emptyAccumulator, wire).usage\n expect(usage.total_tokens).toBe(94 + 31851 + 604 + 210)\n })\n})\n\ndescribe(\"streamed usage\", () => {\n // Anthropic sends input + cache on message_start and the final output_tokens\n // on message_delta. total_tokens must reflect the accumulated buckets, not\n // the (input + initial output) figure frozen at message_start.\n it(\"computes a non-stale total across message_start and message_delta\", () => {\n const start: ProviderEvent = {\n type: \"message_start\",\n message: {\n usage: {\n input_tokens: 94,\n output_tokens: 1,\n cache_read_input_tokens: 31851,\n cache_creation_input_tokens: 604,\n },\n },\n }\n const delta: ProviderEvent = {\n type: \"message_delta\",\n delta: { stop_reason: \"end_turn\" },\n usage: { output_tokens: 210 },\n }\n const usage = applyEvent(applyEvent(emptyAccumulator, start), delta).usage\n expect(usage.output_tokens).toBe(210)\n expect(usage.input_tokens_details?.cache_write_tokens).toBe(604)\n expect(usage.total_tokens).toBe(94 + 31851 + 604 + 210)\n })\n})\n"],"mappings":";;;;AAMA,MAAM,OAAkB;CACtB,cAAc;CACd,eAAe;CACf,yBAAyB;CACzB,6BAA6B;CAC9B;AAED,SAAS,oBAAoB;AAC3B,IAAG,6DAA6D;EAC9D,MAAM,QAAQ,WAAW,kBAAkB,KAAK,CAAC;AACjD,eAAO,MAAM,aAAa,CAAC,KAAK,GAAG;AACnC,eAAO,MAAM,sBAAsB,cAAc,CAAC,KAAK,MAAM;AAC7D,eAAO,MAAM,sBAAsB,mBAAmB,CAAC,KAAK,IAAI;GAChE;AAEF,IAAG,+CAA+C;EAChD,MAAM,QAAQ,WAAW,kBAAkB,KAAK,CAAC;AACjD,eAAO,MAAM,aAAa,CAAC,KAAK,MAAuB;GACvD;EACF;AAEF,SAAS,wBAAwB;AAI/B,IAAG,2EAA2E;EAiB5E,MAAM,QAAQ,WAAW,WAAW,kBAAkB;GAfpD,MAAM;GACN,SAAS,EACP,OAAO;IACL,cAAc;IACd,eAAe;IACf,yBAAyB;IACzB,6BAA6B;IAC9B,EACF;GAOwD,CAAC,EAAE;GAJ5D,MAAM;GACN,OAAO,EAAE,aAAa,YAAY;GAClC,OAAO,EAAE,eAAe,KAAK;GAEoC,CAAC,CAAC;AACrE,eAAO,MAAM,cAAc,CAAC,KAAK,IAAI;AACrC,eAAO,MAAM,sBAAsB,mBAAmB,CAAC,KAAK,IAAI;AAChE,eAAO,MAAM,aAAa,CAAC,KAAK,MAAuB;GACvD;EACF"}
1
+ {"version":3,"file":"usage.test.mjs","names":[],"sources":["../src/usage.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\"\nimport { type WireUsage, emptyAccumulator, mergeUsage } from \"./codec.js\"\nimport { type ProviderEvent, applyEvent } from \"./streamEvents.js\"\n\n// A completed cached turn: input split across post-breakpoint tokens, cache\n// reads, and cache writes, all billed separately.\nconst wire: WireUsage = {\n input_tokens: 94,\n output_tokens: 210,\n cache_read_input_tokens: 31851,\n cache_creation_input_tokens: 604,\n}\n\ndescribe(\"mergeUsage\", () => {\n it(\"keeps all three input buckets, not just cache reads\", () => {\n const usage = mergeUsage(emptyAccumulator, wire).usage\n expect(usage.input_tokens).toBe(94)\n expect(usage.input_tokens_details?.cached_tokens).toBe(31851)\n expect(usage.input_tokens_details?.cache_write_tokens).toBe(604)\n })\n\n it(\"totals every input bucket plus output\", () => {\n const usage = mergeUsage(emptyAccumulator, wire).usage\n expect(usage.total_tokens).toBe(94 + 31851 + 604 + 210)\n })\n})\n\ndescribe(\"streamed usage\", () => {\n // Anthropic sends input + cache on message_start and the final output_tokens\n // on message_delta. total_tokens must reflect the accumulated buckets, not\n // the (input + initial output) figure frozen at message_start.\n it(\"computes a non-stale total across message_start and message_delta\", () => {\n const start: ProviderEvent = {\n type: \"message_start\",\n message: {\n usage: {\n input_tokens: 94,\n output_tokens: 1,\n cache_read_input_tokens: 31851,\n cache_creation_input_tokens: 604,\n },\n },\n }\n const delta: ProviderEvent = {\n type: \"message_delta\",\n delta: { stop_reason: \"end_turn\" },\n usage: { output_tokens: 210 },\n }\n const usage = applyEvent(applyEvent(emptyAccumulator, start), delta).usage\n expect(usage.output_tokens).toBe(210)\n expect(usage.input_tokens_details?.cache_write_tokens).toBe(604)\n expect(usage.total_tokens).toBe(94 + 31851 + 604 + 210)\n })\n})\n"],"mappings":";;;;AAMA,MAAM,OAAkB;CACtB,cAAc;CACd,eAAe;CACf,yBAAyB;CACzB,6BAA6B;AAC/B;AAEA,SAAS,oBAAoB;CAC3B,GAAG,6DAA6D;EAC9D,MAAM,QAAQ,WAAW,kBAAkB,IAAI,CAAC,CAAC;EACjD,aAAO,MAAM,YAAY,CAAC,CAAC,KAAK,EAAE;EAClC,aAAO,MAAM,sBAAsB,aAAa,CAAC,CAAC,KAAK,KAAK;EAC5D,aAAO,MAAM,sBAAsB,kBAAkB,CAAC,CAAC,KAAK,GAAG;CACjE,CAAC;CAED,GAAG,+CAA+C;EAChD,MAAM,QAAQ,WAAW,kBAAkB,IAAI,CAAC,CAAC;EACjD,aAAO,MAAM,YAAY,CAAC,CAAC,KAAK,KAAsB;CACxD,CAAC;AACH,CAAC;AAED,SAAS,wBAAwB;CAI/B,GAAG,2EAA2E;EAiB5E,MAAM,QAAQ,WAAW,WAAW,kBAAkB;GAfpD,MAAM;GACN,SAAS,EACP,OAAO;IACL,cAAc;IACd,eAAe;IACf,yBAAyB;IACzB,6BAA6B;GAC/B,EACF;EAOwD,CAAC,GAAG;GAJ5D,MAAM;GACN,OAAO,EAAE,aAAa,WAAW;GACjC,OAAO,EAAE,eAAe,IAAI;EAEoC,CAAC,CAAC,CAAC;EACrE,aAAO,MAAM,aAAa,CAAC,CAAC,KAAK,GAAG;EACpC,aAAO,MAAM,sBAAsB,kBAAkB,CAAC,CAAC,KAAK,GAAG;EAC/D,aAAO,MAAM,YAAY,CAAC,CAAC,KAAK,KAAsB;CACxD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@effect-uai/anthropic",
3
- "version": "0.12.0",
3
+ "version": "0.12.1",
4
4
  "description": "Anthropic Messages API provider for @effect-uai/core.",
5
5
  "keywords": [
6
6
  "ai",
@@ -43,13 +43,13 @@
43
43
  "access": "public"
44
44
  },
45
45
  "devDependencies": {
46
- "effect": "4.0.0-beta.94",
47
- "typescript": "^6.0.3",
48
- "@effect-uai/core": "0.12.0"
46
+ "effect": "4.0.0-rc.111",
47
+ "typescript": "^7.0.2",
48
+ "@effect-uai/core": "0.12.1"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@effect-uai/core": ">=0.2.0 <1",
52
- "effect": ">=4.0.0-beta.94 <5.0.0"
52
+ "effect": ">=4.0.0-rc.111 <5.0.0"
53
53
  },
54
54
  "scripts": {
55
55
  "build": "tsdown",
package/src/Anthropic.ts CHANGED
@@ -445,13 +445,10 @@ export const layer = (
445
445
  const typed = Layer.effect(Anthropic, make(cfg))
446
446
  const generic = Layer.effect(
447
447
  LanguageModel,
448
- Effect.map(
449
- make(cfg),
450
- (s): LanguageModelService => ({
451
- streamTurn: (request) => s.streamTurn(request as AnthropicRequest),
452
- turn: (request) => s.turn(request as AnthropicRequest),
453
- }),
454
- ),
448
+ Effect.map(make(cfg), (s): LanguageModelService => ({
449
+ streamTurn: (request) => s.streamTurn(request as AnthropicRequest),
450
+ turn: (request) => s.turn(request as AnthropicRequest),
451
+ })),
455
452
  )
456
453
  return Layer.merge(typed, generic)
457
454
  }
@@ -109,12 +109,10 @@ const renderOne = (
109
109
  })
110
110
  : decodeConfig(tool.config).pipe(
111
111
  Result.map(configToWire),
112
- Result.mapError(
113
- (): ToolRenderError => ({
114
- capability: "providerTool",
115
- reason: `unrecognized Anthropic provider tool config on "${tool.name}"`,
116
- }),
117
- ),
112
+ Result.mapError((): ToolRenderError => ({
113
+ capability: "providerTool",
114
+ reason: `unrecognized Anthropic provider tool config on "${tool.name}"`,
115
+ })),
118
116
  )
119
117
 
120
118
  /**
package/src/codec.ts CHANGED
@@ -195,11 +195,9 @@ const itemToAssistantBlocks = (
195
195
  function_call: (f) =>
196
196
  pipe(
197
197
  parseJson(f.arguments),
198
- Result.map(
199
- (input): ReadonlyArray<RequestAssistantContentBlock> => [
200
- { type: "tool_use", id: f.call_id, name: f.name, input },
201
- ],
202
- ),
198
+ Result.map((input): ReadonlyArray<RequestAssistantContentBlock> => [
199
+ { type: "tool_use", id: f.call_id, name: f.name, input },
200
+ ]),
203
201
  ),
204
202
  function_call_output: (): Result.Result<
205
203
  ReadonlyArray<RequestAssistantContentBlock>,
@@ -373,58 +371,56 @@ export const buildRequestBody = (params: {
373
371
  }): Result.Result<RequestBody, JsonParseError> =>
374
372
  pipe(
375
373
  groupedMessages(params.history),
376
- Result.map(
377
- (messages): RequestBody => ({
378
- model: params.model,
379
- messages,
380
- max_tokens: params.maxTokens,
381
- ...Option.match(systemFromHistory(params.history), {
382
- onNone: () => ({}),
383
- onSome: (system) => ({ system }),
384
- }),
385
- ...Option.match(params.temperature, {
386
- onNone: () => ({}),
387
- onSome: (temperature) => ({ temperature }),
388
- }),
389
- ...Option.match(params.topP, {
390
- onNone: () => ({}),
391
- onSome: (top_p) => ({ top_p }),
392
- }),
393
- ...Option.match(params.topK, {
394
- onNone: () => ({}),
395
- onSome: (top_k) => ({ top_k }),
396
- }),
397
- ...Option.match(params.stopSequences, {
398
- onNone: () => ({}),
399
- onSome: (stop_sequences) => ({ stop_sequences }),
400
- }),
401
- ...Option.match(params.thinking, {
402
- onNone: () => ({}),
403
- onSome: (thinking) => ({ thinking }),
404
- }),
405
- ...Option.match(params.tools, {
406
- onNone: () => ({}),
407
- onSome: (tools) => ({ tools }),
408
- }),
409
- ...Option.match(params.toolChoice, {
410
- onNone: () => ({}),
411
- onSome: (tool_choice) => ({ tool_choice }),
412
- }),
413
- ...Option.match(params.userId, {
414
- onNone: () => ({}),
415
- onSome: (user_id) => ({ metadata: { user_id } }),
416
- }),
417
- ...Option.match(params.outputConfig, {
418
- onNone: () => ({}),
419
- onSome: (output_config) => ({ output_config }),
420
- }),
421
- ...Option.match(params.cacheControl, {
422
- onNone: () => ({}),
423
- onSome: (cache_control) => ({ cache_control }),
424
- }),
425
- stream: true,
374
+ Result.map((messages): RequestBody => ({
375
+ model: params.model,
376
+ messages,
377
+ max_tokens: params.maxTokens,
378
+ ...Option.match(systemFromHistory(params.history), {
379
+ onNone: () => ({}),
380
+ onSome: (system) => ({ system }),
426
381
  }),
427
- ),
382
+ ...Option.match(params.temperature, {
383
+ onNone: () => ({}),
384
+ onSome: (temperature) => ({ temperature }),
385
+ }),
386
+ ...Option.match(params.topP, {
387
+ onNone: () => ({}),
388
+ onSome: (top_p) => ({ top_p }),
389
+ }),
390
+ ...Option.match(params.topK, {
391
+ onNone: () => ({}),
392
+ onSome: (top_k) => ({ top_k }),
393
+ }),
394
+ ...Option.match(params.stopSequences, {
395
+ onNone: () => ({}),
396
+ onSome: (stop_sequences) => ({ stop_sequences }),
397
+ }),
398
+ ...Option.match(params.thinking, {
399
+ onNone: () => ({}),
400
+ onSome: (thinking) => ({ thinking }),
401
+ }),
402
+ ...Option.match(params.tools, {
403
+ onNone: () => ({}),
404
+ onSome: (tools) => ({ tools }),
405
+ }),
406
+ ...Option.match(params.toolChoice, {
407
+ onNone: () => ({}),
408
+ onSome: (tool_choice) => ({ tool_choice }),
409
+ }),
410
+ ...Option.match(params.userId, {
411
+ onNone: () => ({}),
412
+ onSome: (user_id) => ({ metadata: { user_id } }),
413
+ }),
414
+ ...Option.match(params.outputConfig, {
415
+ onNone: () => ({}),
416
+ onSome: (output_config) => ({ output_config }),
417
+ }),
418
+ ...Option.match(params.cacheControl, {
419
+ onNone: () => ({}),
420
+ onSome: (cache_control) => ({ cache_control }),
421
+ }),
422
+ stream: true,
423
+ })),
428
424
  )
429
425
 
430
426
  // ---------------------------------------------------------------------------
@@ -576,52 +572,41 @@ const blocksByIndex = (acc: Accumulator): ReadonlyArray<BlockBuffer> =>
576
572
 
577
573
  const blockToItems = (block: BlockBuffer): ReadonlyArray<Items.HistoryItem> =>
578
574
  Match.value(block.type).pipe(
579
- Match.when(
580
- "text",
581
- (): ReadonlyArray<Items.HistoryItem> =>
582
- block.text.length === 0
583
- ? []
584
- : [
585
- {
586
- type: "message",
587
- role: "assistant",
588
- content: [{ type: "output_text", text: block.text }],
589
- },
590
- ],
591
- ),
592
- Match.when(
593
- "tool_use",
594
- (): ReadonlyArray<Items.HistoryItem> => [
595
- {
596
- type: "function_call",
597
- call_id: Option.getOrElse(block.id, () => ""),
598
- name: Option.getOrElse(block.name, () => ""),
599
- arguments: block.inputJson,
600
- },
601
- ],
602
- ),
603
- Match.when(
604
- "thinking",
605
- (): ReadonlyArray<Items.HistoryItem> => [
606
- {
607
- type: "reasoning",
608
- ...(block.thinking.length > 0 && { summary: block.thinking }),
609
- ...(block.signature.length > 0 && { signature: block.signature }),
610
- },
611
- ],
612
- ),
613
- Match.when(
614
- "redacted_thinking",
615
- (): ReadonlyArray<Items.HistoryItem> => [
616
- {
617
- type: "reasoning",
618
- ...Option.match(block.redactedData, {
619
- onNone: () => ({}),
620
- onSome: (signature) => ({ signature }),
621
- }),
622
- },
623
- ],
575
+ Match.when("text", (): ReadonlyArray<Items.HistoryItem> =>
576
+ block.text.length === 0
577
+ ? []
578
+ : [
579
+ {
580
+ type: "message",
581
+ role: "assistant",
582
+ content: [{ type: "output_text", text: block.text }],
583
+ },
584
+ ],
624
585
  ),
586
+ Match.when("tool_use", (): ReadonlyArray<Items.HistoryItem> => [
587
+ {
588
+ type: "function_call",
589
+ call_id: Option.getOrElse(block.id, () => ""),
590
+ name: Option.getOrElse(block.name, () => ""),
591
+ arguments: block.inputJson,
592
+ },
593
+ ]),
594
+ Match.when("thinking", (): ReadonlyArray<Items.HistoryItem> => [
595
+ {
596
+ type: "reasoning",
597
+ ...(block.thinking.length > 0 && { summary: block.thinking }),
598
+ ...(block.signature.length > 0 && { signature: block.signature }),
599
+ },
600
+ ]),
601
+ Match.when("redacted_thinking", (): ReadonlyArray<Items.HistoryItem> => [
602
+ {
603
+ type: "reasoning",
604
+ ...Option.match(block.redactedData, {
605
+ onNone: () => ({}),
606
+ onSome: (signature) => ({ signature }),
607
+ }),
608
+ },
609
+ ]),
625
610
  Match.exhaustive,
626
611
  )
627
612