@llumiverse/common 1.1.1-dev.20260505.151157Z → 1.3.0

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 (58) hide show
  1. package/lib/cjs/capability/anthropic.js +45 -0
  2. package/lib/cjs/capability/anthropic.js.map +1 -0
  3. package/lib/cjs/capability.js +6 -0
  4. package/lib/cjs/capability.js.map +1 -1
  5. package/lib/cjs/index.js +5 -3
  6. package/lib/cjs/index.js.map +1 -1
  7. package/lib/cjs/options/anthropic.js +34 -0
  8. package/lib/cjs/options/anthropic.js.map +1 -0
  9. package/lib/cjs/options/bedrock.js.map +1 -1
  10. package/lib/cjs/options/openai.js.map +1 -1
  11. package/lib/cjs/options/vertexai.js.map +1 -1
  12. package/lib/cjs/options.js +5 -2
  13. package/lib/cjs/options.js.map +1 -1
  14. package/lib/cjs/types.js +8 -0
  15. package/lib/cjs/types.js.map +1 -1
  16. package/lib/esm/capability/anthropic.js +42 -0
  17. package/lib/esm/capability/anthropic.js.map +1 -0
  18. package/lib/esm/capability.js +6 -0
  19. package/lib/esm/capability.js.map +1 -1
  20. package/lib/esm/index.js +5 -3
  21. package/lib/esm/index.js.map +1 -1
  22. package/lib/esm/options/anthropic.js +31 -0
  23. package/lib/esm/options/anthropic.js.map +1 -0
  24. package/lib/esm/options/bedrock.js.map +1 -1
  25. package/lib/esm/options/openai.js.map +1 -1
  26. package/lib/esm/options/vertexai.js.map +1 -1
  27. package/lib/esm/options.js +5 -2
  28. package/lib/esm/options.js.map +1 -1
  29. package/lib/esm/types.js +8 -0
  30. package/lib/esm/types.js.map +1 -1
  31. package/lib/types/capability/anthropic.d.ts +3 -0
  32. package/lib/types/capability/anthropic.d.ts.map +1 -0
  33. package/lib/types/capability.d.ts +1 -1
  34. package/lib/types/capability.d.ts.map +1 -1
  35. package/lib/types/index.d.ts +5 -3
  36. package/lib/types/index.d.ts.map +1 -1
  37. package/lib/types/options/anthropic.d.ts +16 -0
  38. package/lib/types/options/anthropic.d.ts.map +1 -0
  39. package/lib/types/options/bedrock.d.ts +16 -9
  40. package/lib/types/options/bedrock.d.ts.map +1 -1
  41. package/lib/types/options/openai.d.ts +3 -0
  42. package/lib/types/options/openai.d.ts.map +1 -1
  43. package/lib/types/options/vertexai.d.ts +3 -0
  44. package/lib/types/options/vertexai.d.ts.map +1 -1
  45. package/lib/types/options.d.ts +1 -1
  46. package/lib/types/options.d.ts.map +1 -1
  47. package/lib/types/types.d.ts +18 -7
  48. package/lib/types/types.d.ts.map +1 -1
  49. package/package.json +2 -1
  50. package/src/capability/anthropic.ts +49 -0
  51. package/src/capability.ts +6 -1
  52. package/src/index.ts +5 -4
  53. package/src/options/anthropic.ts +56 -0
  54. package/src/options/bedrock.ts +27 -10
  55. package/src/options/openai.ts +3 -0
  56. package/src/options/vertexai.ts +3 -0
  57. package/src/options.ts +7 -4
  58. package/src/types.ts +26 -7
@@ -0,0 +1,49 @@
1
+ import type { ModelCapabilities } from "../types.js";
2
+
3
+ // Explicit model exceptions
4
+ const RECORD_MODEL_CAPABILITIES: Record<string, ModelCapabilities> = {
5
+ // claude-3-5-haiku: no image input
6
+ "claude-3-5-haiku-20241022": { input: { text: true, image: false, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
7
+ };
8
+
9
+ // Family-level capabilities (longest prefix match)
10
+ const RECORD_FAMILY_CAPABILITIES: Record<string, ModelCapabilities> = {
11
+ "claude-3-5-haiku": { input: { text: true, image: false, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
12
+ "claude-3-haiku": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
13
+ "claude-3-sonnet": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
14
+ "claude-3-opus": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
15
+ "claude-3-5": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
16
+ "claude-3-7": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
17
+ "claude-3": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
18
+ "claude-4": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
19
+ "claude-": { input: { text: true, image: true, video: false, audio: false, embed: false }, output: { text: true, image: false, video: false, audio: false, embed: false }, tool_support: true, tool_support_streaming: true },
20
+ };
21
+
22
+ const DEFAULT_CLAUDE_CAPABILITIES: ModelCapabilities = {
23
+ input: { text: true, image: true, video: false, audio: false, embed: false },
24
+ output: { text: true, image: false, video: false, audio: false, embed: false },
25
+ tool_support: true,
26
+ tool_support_streaming: true,
27
+ };
28
+
29
+ export function getModelCapabilitiesAnthropic(model: string): ModelCapabilities {
30
+ const lower = model.toLowerCase();
31
+
32
+ // Exact match first
33
+ if (lower in RECORD_MODEL_CAPABILITIES) {
34
+ return RECORD_MODEL_CAPABILITIES[lower];
35
+ }
36
+
37
+ // Longest prefix family match
38
+ let bestKey: string | undefined;
39
+ for (const key of Object.keys(RECORD_FAMILY_CAPABILITIES)) {
40
+ if (lower.startsWith(key) && (!bestKey || key.length > bestKey.length)) {
41
+ bestKey = key;
42
+ }
43
+ }
44
+ if (bestKey) {
45
+ return RECORD_FAMILY_CAPABILITIES[bestKey];
46
+ }
47
+
48
+ return DEFAULT_CLAUDE_CAPABILITIES;
49
+ }
package/src/capability.ts CHANGED
@@ -1,8 +1,9 @@
1
+ import { getModelCapabilitiesAnthropic } from "./capability/anthropic.js";
1
2
  import { getModelCapabilitiesAzureFoundry } from "./capability/azure_foundry.js";
2
3
  import { getModelCapabilitiesBedrock } from "./capability/bedrock.js";
3
4
  import { getModelCapabilitiesOpenAI } from "./capability/openai.js";
4
5
  import { getModelCapabilitiesVertexAI } from "./capability/vertexai.js";
5
- import { ModelCapabilities, ModelModalities, Providers } from "./types.js";
6
+ import { type ModelCapabilities, type ModelModalities, Providers } from "./types.js";
6
7
 
7
8
  export function getModelCapabilities(model: string, provider?: string | Providers): ModelCapabilities {
8
9
  //Check for locations/<location>/ prefix and remove it
@@ -25,6 +26,8 @@ export function getModelCapabilities(model: string, provider?: string | Provider
25
26
 
26
27
  function _getModelCapabilities(model: string, provider?: string | Providers): ModelCapabilities {
27
28
  switch (provider?.toLowerCase()) {
29
+ case Providers.anthropic:
30
+ return getModelCapabilitiesAnthropic(model);
28
31
  case Providers.vertexai:
29
32
  return getModelCapabilitiesVertexAI(model);
30
33
  case Providers.openai:
@@ -53,6 +56,8 @@ function _getModelCapabilities(model: string, provider?: string | Providers): Mo
53
56
  // Guess the provider based on the model name
54
57
  if (model.startsWith("gpt")) {
55
58
  return getModelCapabilitiesOpenAI(model);
59
+ } else if (model.startsWith("claude")) {
60
+ return getModelCapabilitiesAnthropic(model);
56
61
  } else if (model.startsWith("grok")) {
57
62
  // xAI Grok models
58
63
  return {
package/src/index.ts CHANGED
@@ -1,11 +1,12 @@
1
- export * from "./types.js";
2
1
  export * from "./capability.js";
3
2
  export * from "./options.js";
4
-
3
+ export * from "./options/anthropic.js";
5
4
  export * from "./options/bedrock.js";
5
+ export * from "./options/context-windows.js";
6
6
  export * from "./options/fallback.js";
7
7
  export * from "./options/groq.js";
8
8
  export * from "./options/openai.js";
9
+ export * from "./options/shared-parsing.js";
10
+ export * from "./options/version-parsing.js";
9
11
  export * from "./options/vertexai.js";
10
- export * from "./options/context-windows.js";
11
- export * from "./options/version-parsing.js";
12
+ export * from "./types.js";
@@ -0,0 +1,56 @@
1
+ import { type ModelOptions, type ModelOptionsInfo, OptionType, SharedOptions } from "../types.js";
2
+ import { textOptionsFallback } from "./fallback.js";
3
+ import {
4
+ buildClaudeCacheOptions,
5
+ buildClaudeCacheTtlOptions,
6
+ buildClaudeEffortOptions,
7
+ buildClaudeIncludeThoughtsOption,
8
+ buildClaudeThinkingBudgetOption,
9
+ getClaudeMaxTokensLimit,
10
+ } from "./shared-parsing.js";
11
+ import { hasSamplingParameterRestriction } from "./version-parsing.js";
12
+
13
+ export interface AnthropicClaudeOptions {
14
+ _option_id: "anthropic-claude";
15
+ max_tokens?: number;
16
+ temperature?: number;
17
+ top_p?: number;
18
+ top_k?: number;
19
+ stop_sequence?: string[];
20
+ effort?: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
21
+ thinking_budget_tokens?: number;
22
+ include_thoughts?: boolean;
23
+ cache_enabled?: boolean;
24
+ cache_ttl?: '5m' | '1h';
25
+ }
26
+
27
+ export function getAnthropicOptions(model: string, option?: ModelOptions): ModelOptionsInfo {
28
+ const max_tokens_limit = getClaudeMaxTokensLimit(model);
29
+ const excludeOptions = ["max_tokens", "presence_penalty", "frequency_penalty"];
30
+ let commonOptions = textOptionsFallback.options.filter((o) => !excludeOptions.includes(o.name));
31
+
32
+ const hasSamplingRestriction = hasSamplingParameterRestriction(model);
33
+ if (hasSamplingRestriction) {
34
+ commonOptions = commonOptions.filter((o) =>
35
+ o.name !== SharedOptions.temperature &&
36
+ o.name !== SharedOptions.top_p &&
37
+ o.name !== "top_k"
38
+ );
39
+ }
40
+
41
+ return {
42
+ _option_id: "anthropic-claude",
43
+ options: [
44
+ {
45
+ name: SharedOptions.max_tokens, type: OptionType.numeric, min: 1, max: max_tokens_limit,
46
+ integer: true, step: 200, description: "The maximum number of tokens to generate",
47
+ },
48
+ ...commonOptions,
49
+ ...buildClaudeEffortOptions(model),
50
+ ...buildClaudeThinkingBudgetOption(model),
51
+ ...buildClaudeIncludeThoughtsOption(model),
52
+ ...buildClaudeCacheOptions(),
53
+ ...buildClaudeCacheTtlOptions((option as unknown as AnthropicClaudeOptions)?.cache_enabled),
54
+ ],
55
+ };
56
+ }
@@ -9,8 +9,22 @@ import {
9
9
  } from "./shared-parsing.js";
10
10
  import { hasSamplingParameterRestriction } from "./version-parsing.js";
11
11
 
12
- // Union type of all Bedrock options
13
- export type BedrockOptions = NovaCanvasOptions | BaseConverseOptions | BedrockClaudeOptions | BedrockPalmyraOptions | BedrockGptOssOptions | TwelvelabsPegasusOptions;
12
+ /**
13
+ * Union type of all Bedrock options
14
+ *
15
+ * @discriminator _option_id
16
+ */
17
+ export type BedrockOptions =
18
+ | NovaCanvasOptions
19
+ | BedrockConverseOptions
20
+ | BedrockNovaOptions
21
+ | BedrockMistralOptions
22
+ | BedrockAI21Options
23
+ | BedrockCohereCommandOptions
24
+ | BedrockClaudeOptions
25
+ | BedrockPalmyraOptions
26
+ | BedrockGptOssOptions
27
+ | TwelvelabsPegasusOptions;
14
28
 
15
29
  export interface NovaCanvasOptions {
16
30
  _option_id: "bedrock-nova-canvas"
@@ -28,16 +42,21 @@ export interface NovaCanvasOptions {
28
42
  outPaintingMode?: "DEFAULT" | "PRECISE";
29
43
  }
30
44
 
31
- export interface BaseConverseOptions {
32
- _option_id: "bedrock-converse" | "bedrock-claude" | "bedrock-nova" | "bedrock-mistral" | "bedrock-ai21" | "bedrock-cohere-command" | "bedrock-palmyra" | "bedrock-gpt-oss";
45
+ export interface BaseConverseOptions<TOptionId extends string = string> {
46
+ _option_id: TOptionId;
33
47
  max_tokens?: number;
34
48
  temperature?: number;
35
49
  top_p?: number;
36
50
  stop_sequence?: string[];
37
51
  }
38
52
 
39
- export interface BedrockClaudeOptions extends BaseConverseOptions {
40
- _option_id: "bedrock-claude";
53
+ export type BedrockConverseOptions = BaseConverseOptions<"bedrock-converse">;
54
+ export type BedrockNovaOptions = BaseConverseOptions<"bedrock-nova">;
55
+ export type BedrockMistralOptions = BaseConverseOptions<"bedrock-mistral">;
56
+ export type BedrockAI21Options = BaseConverseOptions<"bedrock-ai21">;
57
+ export type BedrockCohereCommandOptions = BaseConverseOptions<"bedrock-cohere-command">;
58
+
59
+ export interface BedrockClaudeOptions extends BaseConverseOptions<"bedrock-claude"> {
41
60
  top_k?: number;
42
61
  thinking_budget_tokens?: number;
43
62
  include_thoughts?: boolean;
@@ -46,16 +65,14 @@ export interface BedrockClaudeOptions extends BaseConverseOptions {
46
65
  cache_ttl?: '5m' | '1h';
47
66
  }
48
67
 
49
- export interface BedrockPalmyraOptions extends BaseConverseOptions {
50
- _option_id: "bedrock-palmyra";
68
+ export interface BedrockPalmyraOptions extends BaseConverseOptions<"bedrock-palmyra"> {
51
69
  min_tokens?: number;
52
70
  seed?: number;
53
71
  frequency_penalty?: number;
54
72
  presence_penalty?: number;
55
73
  }
56
74
 
57
- export interface BedrockGptOssOptions extends BaseConverseOptions {
58
- _option_id: "bedrock-gpt-oss";
75
+ export interface BedrockGptOssOptions extends BaseConverseOptions<"bedrock-gpt-oss"> {
59
76
  reasoning_effort?: "low" | "medium" | "high";
60
77
  frequency_penalty?: number;
61
78
  presence_penalty?: number;
@@ -2,6 +2,9 @@ import { ModelOptionInfoItem, ModelOptions, ModelOptionsInfo, OptionType, Reason
2
2
  import { textOptionsFallback } from "./fallback.js";
3
3
 
4
4
  // Union type of all OpenAI options
5
+ /**
6
+ * @discriminator _option_id
7
+ */
5
8
  export type OpenAiOptions = OpenAiThinkingOptions | OpenAiTextOptions | OpenAiDalleOptions | OpenAiGptImageOptions;
6
9
 
7
10
  export interface OpenAiThinkingOptions {
@@ -14,6 +14,9 @@ import {
14
14
  } from "./version-parsing.js";
15
15
 
16
16
  // Union type of all VertexAI options
17
+ /**
18
+ * @discriminator _option_id
19
+ */
17
20
  export type VertexAIOptions = ImagenOptions | VertexAIClaudeOptions | VertexAIGeminiOptions;
18
21
 
19
22
  export enum ImagenTaskType {
package/src/options.ts CHANGED
@@ -1,16 +1,19 @@
1
+ import { getAnthropicOptions } from "./options/anthropic.js";
2
+ import { getAzureFoundryOptions } from "./options/azure_foundry.js";
1
3
  import { getBedrockOptions } from "./options/bedrock.js";
4
+ import { textOptionsFallback } from "./options/fallback.js";
2
5
  import { getGroqOptions } from "./options/groq.js";
3
6
  import { getOpenAiOptions } from "./options/openai.js";
4
7
  import { getVertexAiOptions } from "./options/vertexai.js";
5
- import { textOptionsFallback } from "./options/fallback.js";
6
- import { ModelOptionsInfo, ModelOptions, Providers } from "./types.js";
7
- import { getAzureFoundryOptions } from "./options/azure_foundry.js";
8
+ import { type ModelOptions, type ModelOptionsInfo, Providers } from "./types.js";
8
9
 
9
10
  export function getOptions(model: string, provider?: string | Providers, options?: ModelOptions): ModelOptionsInfo {
10
- if(!provider) {
11
+ if (!provider) {
11
12
  return textOptionsFallback;
12
13
  }
13
14
  switch (provider.toLowerCase()) {
15
+ case Providers.anthropic:
16
+ return getAnthropicOptions(model, options);
14
17
  case Providers.bedrock:
15
18
  return getBedrockOptions(model, options);
16
19
  case Providers.vertexai:
package/src/types.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { BedrockOptions } from './options/bedrock.js';
2
- import { TextFallbackOptions } from './options/fallback.js';
3
- import { GroqOptions } from './options/groq.js';
4
- import { OpenAiOptions } from './options/openai.js';
5
- import { VertexAIOptions } from './options/vertexai.js';
1
+ import type { BedrockOptions } from './options/bedrock.js';
2
+ import type { TextFallbackOptions } from './options/fallback.js';
3
+ import type { GroqOptions } from './options/groq.js';
4
+ import type { OpenAiOptions } from './options/openai.js';
5
+ import type { VertexAIOptions } from './options/vertexai.js';
6
6
 
7
7
  // ============== Provider details ===============
8
8
 
@@ -19,7 +19,8 @@ export enum Providers {
19
19
  mistralai = 'mistralai',
20
20
  groq = 'groq',
21
21
  watsonx = 'watsonx',
22
- xai = 'xai'
22
+ xai = 'xai',
23
+ anthropic = 'anthropic'
23
24
  }
24
25
 
25
26
  export interface ProviderParams {
@@ -130,6 +131,13 @@ export const ProviderList: Record<Providers, ProviderParams> = {
130
131
  endpointPlaceholder: "https://api.example.com/v1",
131
132
  supportSearch: false
132
133
  },
134
+ anthropic: {
135
+ id: Providers.anthropic,
136
+ name: "Anthropic",
137
+ requiresApiKey: true,
138
+ requiresEndpointUrl: false,
139
+ supportSearch: false,
140
+ },
133
141
  }
134
142
 
135
143
  // ============== Embeddings ===============
@@ -324,6 +332,9 @@ export interface ImageResult extends BaseResult {
324
332
  value: string; // base64 data url or real url
325
333
  }
326
334
 
335
+ /**
336
+ * @discriminator type
337
+ */
327
338
  export type CompletionResult = TextResult | JsonResult | ImageResult;
328
339
 
329
340
 
@@ -466,10 +477,15 @@ export interface JSONSchemaObject {
466
477
 
467
478
  export interface JSONSchemaArray extends Array<JSONSchemaType> { }
468
479
 
480
+ export interface JSONSchemaProperties {
481
+ [key: string]: JSONSchema;
482
+ }
483
+
469
484
  export interface JSONSchema {
470
485
  type?: JSONSchemaTypeName | JSONSchemaTypeName[];
471
486
  description?: string;
472
- properties?: Record<string, JSONSchema>;
487
+ properties?: JSONSchemaProperties;
488
+ additionalProperties?: boolean | JSONSchema;
473
489
  required?: string[];
474
490
  [k: string]: any;
475
491
  }
@@ -577,6 +593,9 @@ export type ReasoningEffort = "low" | "medium" | "high";
577
593
 
578
594
  // ============== Model Options ===============
579
595
 
596
+ /**
597
+ * @discriminator _option_id
598
+ */
580
599
  export type ModelOptions = TextFallbackOptions | VertexAIOptions | BedrockOptions | OpenAiOptions | GroqOptions;
581
600
 
582
601
  // ============== Option Info ===============