openllmprovider 0.1.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 (91) hide show
  1. package/README.md +192 -0
  2. package/dist/auth/index.cjs +6 -0
  3. package/dist/auth/index.d.cts +3 -0
  4. package/dist/auth/index.d.mts +3 -0
  5. package/dist/auth/index.mjs +3 -0
  6. package/dist/auto-C2hXJY13.d.cts +33 -0
  7. package/dist/auto-C2hXJY13.d.cts.map +1 -0
  8. package/dist/auto-CBqNYBXs.mjs +48 -0
  9. package/dist/auto-CBqNYBXs.mjs.map +1 -0
  10. package/dist/auto-CInerwvs.d.mts +33 -0
  11. package/dist/auto-CInerwvs.d.mts.map +1 -0
  12. package/dist/auto-D77wgMqO.cjs +59 -0
  13. package/dist/auto-D77wgMqO.cjs.map +1 -0
  14. package/dist/file-DB-rxfzi.mjs +77 -0
  15. package/dist/file-DB-rxfzi.mjs.map +1 -0
  16. package/dist/file-DZ7FGcSW.cjs +73 -0
  17. package/dist/file-DZ7FGcSW.cjs.map +1 -0
  18. package/dist/index.cjs +1909 -0
  19. package/dist/index.cjs.map +1 -0
  20. package/dist/index.d.cts +1239 -0
  21. package/dist/index.d.cts.map +1 -0
  22. package/dist/index.d.mts +1241 -0
  23. package/dist/index.d.mts.map +1 -0
  24. package/dist/index.mjs +1891 -0
  25. package/dist/index.mjs.map +1 -0
  26. package/dist/logger-BsHpI_fH.mjs +11 -0
  27. package/dist/logger-BsHpI_fH.mjs.map +1 -0
  28. package/dist/logger-jRimlMFR.cjs +69 -0
  29. package/dist/logger-jRimlMFR.cjs.map +1 -0
  30. package/dist/plugin/index.cjs +29 -0
  31. package/dist/plugin/index.cjs.map +1 -0
  32. package/dist/plugin/index.d.cts +10 -0
  33. package/dist/plugin/index.d.cts.map +1 -0
  34. package/dist/plugin/index.d.mts +10 -0
  35. package/dist/plugin/index.d.mts.map +1 -0
  36. package/dist/plugin/index.mjs +25 -0
  37. package/dist/plugin/index.mjs.map +1 -0
  38. package/dist/plugin-BkeUu5LW.d.mts +46 -0
  39. package/dist/plugin-BkeUu5LW.d.mts.map +1 -0
  40. package/dist/plugin-wK7RmJhZ.d.cts +46 -0
  41. package/dist/plugin-wK7RmJhZ.d.cts.map +1 -0
  42. package/dist/resolver-BA7LWSJO.mjs +645 -0
  43. package/dist/resolver-BA7LWSJO.mjs.map +1 -0
  44. package/dist/resolver-BMTvzTt9.cjs +662 -0
  45. package/dist/resolver-BMTvzTt9.cjs.map +1 -0
  46. package/dist/resolver-MgJryMWG.d.cts +75 -0
  47. package/dist/resolver-MgJryMWG.d.cts.map +1 -0
  48. package/dist/resolver-_gfXzr_S.d.mts +76 -0
  49. package/dist/resolver-_gfXzr_S.d.mts.map +1 -0
  50. package/dist/storage/index.cjs +7 -0
  51. package/dist/storage/index.d.cts +12 -0
  52. package/dist/storage/index.d.cts.map +1 -0
  53. package/dist/storage/index.d.mts +12 -0
  54. package/dist/storage/index.d.mts.map +1 -0
  55. package/dist/storage/index.mjs +4 -0
  56. package/package.json +137 -0
  57. package/src/auth/.gitkeep +0 -0
  58. package/src/auth/index.ts +10 -0
  59. package/src/auth/resolver.ts +46 -0
  60. package/src/auth/scanners.ts +462 -0
  61. package/src/auth/store.ts +357 -0
  62. package/src/catalog/.gitkeep +0 -0
  63. package/src/catalog/catalog.ts +302 -0
  64. package/src/catalog/index.ts +17 -0
  65. package/src/catalog/mapper.ts +129 -0
  66. package/src/catalog/merger.ts +99 -0
  67. package/src/index.ts +37 -0
  68. package/src/logger.ts +7 -0
  69. package/src/plugin/.gitkeep +0 -0
  70. package/src/plugin/anthropic.test.ts +505 -0
  71. package/src/plugin/anthropic.ts +324 -0
  72. package/src/plugin/codex.ts +656 -0
  73. package/src/plugin/copilot.ts +161 -0
  74. package/src/plugin/google.ts +454 -0
  75. package/src/plugin/index.ts +30 -0
  76. package/src/provider/.gitkeep +0 -0
  77. package/src/provider/bundled.ts +59 -0
  78. package/src/provider/index.ts +249 -0
  79. package/src/provider/state.ts +163 -0
  80. package/src/storage/.gitkeep +0 -0
  81. package/src/storage/auto.ts +32 -0
  82. package/src/storage/file.ts +84 -0
  83. package/src/storage/index.ts +10 -0
  84. package/src/storage/memory.ts +23 -0
  85. package/src/types/.gitkeep +0 -0
  86. package/src/types/auth.ts +18 -0
  87. package/src/types/errors.ts +87 -0
  88. package/src/types/index.ts +26 -0
  89. package/src/types/model.ts +88 -0
  90. package/src/types/plugin.ts +49 -0
  91. package/src/types/provider.ts +48 -0
@@ -0,0 +1,87 @@
1
+ export type ErrorCode =
2
+ | 'AUTH_ERROR'
3
+ | 'VALIDATION_ERROR'
4
+ | 'MODEL_NOT_FOUND'
5
+ | 'CREDENTIAL_NOT_FOUND'
6
+ | 'PROVIDER_NOT_REGISTERED'
7
+ | 'CATALOG_SYNC_FAILED'
8
+
9
+ interface ErrorOptions {
10
+ providerID?: string
11
+ modelId?: string
12
+ }
13
+
14
+ interface ErrorJSON {
15
+ code: ErrorCode
16
+ message: string
17
+ providerID?: string
18
+ modelId?: string
19
+ }
20
+
21
+ export class OpenLLMProviderError extends Error {
22
+ readonly code: ErrorCode
23
+ readonly providerID?: string
24
+ readonly modelId?: string
25
+
26
+ constructor(message: string, code: ErrorCode, options?: ErrorOptions) {
27
+ super(message)
28
+ this.name = this.constructor.name
29
+ this.code = code
30
+ this.providerID = options?.providerID
31
+ this.modelId = options?.modelId
32
+ const captureStackTrace = (
33
+ Error as unknown as {
34
+ captureStackTrace?: (target: Error, ctor: typeof Error) => void
35
+ }
36
+ ).captureStackTrace
37
+ if (typeof captureStackTrace === 'function') {
38
+ captureStackTrace(this, this.constructor as typeof Error)
39
+ }
40
+ }
41
+
42
+ toJSON(): ErrorJSON {
43
+ const result: ErrorJSON = {
44
+ code: this.code,
45
+ message: this.message,
46
+ }
47
+ if (this.providerID !== undefined) result.providerID = this.providerID
48
+ if (this.modelId !== undefined) result.modelId = this.modelId
49
+ return result
50
+ }
51
+ }
52
+
53
+ export class AuthError extends OpenLLMProviderError {
54
+ constructor(message: string, options?: ErrorOptions) {
55
+ super(message, 'AUTH_ERROR', options)
56
+ }
57
+ }
58
+
59
+ export class ValidationError extends OpenLLMProviderError {
60
+ constructor(message: string, options?: ErrorOptions) {
61
+ super(message, 'VALIDATION_ERROR', options)
62
+ }
63
+ }
64
+
65
+ export class ModelNotFoundError extends OpenLLMProviderError {
66
+ constructor(message: string, options?: ErrorOptions) {
67
+ super(message, 'MODEL_NOT_FOUND', options)
68
+ }
69
+ }
70
+
71
+ export class CredentialNotFoundError extends OpenLLMProviderError {
72
+ constructor(message: string, options?: ErrorOptions) {
73
+ super(message, 'CREDENTIAL_NOT_FOUND', options)
74
+ }
75
+ }
76
+
77
+ export class ProviderNotRegisteredError extends OpenLLMProviderError {
78
+ constructor(message: string, options?: ErrorOptions) {
79
+ super(message, 'PROVIDER_NOT_REGISTERED', options)
80
+ }
81
+ }
82
+
83
+ export class CatalogSyncFailedError extends OpenLLMProviderError {
84
+ constructor(message: string, options?: ErrorOptions) {
85
+ super(message, 'CATALOG_SYNC_FAILED', options)
86
+ }
87
+ }
@@ -0,0 +1,26 @@
1
+ import type { LanguageModelV3 } from '@ai-sdk/provider'
2
+
3
+ export type LanguageModel = LanguageModelV3
4
+ export type { LanguageModelV3 }
5
+
6
+ export type { ProviderDefinition, ProviderUserConfig } from './provider.js'
7
+ export { ProviderDefinitionSchema, ProviderUserConfigSchema } from './provider.js'
8
+
9
+ export type { ModelDefinition, ModelAlias } from './model.js'
10
+ export { ModelDefinitionSchema, ModelAliasSchema } from './model.js'
11
+
12
+ export type { SecretRef, SecretResolver } from './auth.js'
13
+ export { SecretRefSchema } from './auth.js'
14
+
15
+ export type { AuthHook, AuthMethod, AuthCredential, ProviderInfo } from './plugin.js'
16
+
17
+ export {
18
+ OpenLLMProviderError,
19
+ AuthError,
20
+ ValidationError,
21
+ ModelNotFoundError,
22
+ CredentialNotFoundError,
23
+ ProviderNotRegisteredError,
24
+ CatalogSyncFailedError,
25
+ } from './errors.js'
26
+ export type { ErrorCode } from './errors.js'
@@ -0,0 +1,88 @@
1
+ import { z } from 'zod'
2
+
3
+ export interface ModelDefinition {
4
+ modelId: string
5
+ name?: string
6
+ family?: string
7
+ type?: 'chat' | 'embedding' | 'image'
8
+ reasoning?: boolean
9
+ tool_call?: boolean
10
+ structured_output?: boolean
11
+ temperature?: boolean
12
+ attachment?: boolean
13
+ streaming?: boolean
14
+ system_message?: boolean
15
+ modalities: {
16
+ input: Array<'text' | 'image' | 'audio' | 'video' | 'pdf'>
17
+ output: Array<'text' | 'image' | 'audio'>
18
+ }
19
+ limit: {
20
+ context: number
21
+ output: number
22
+ input_images?: number
23
+ }
24
+ cost?: {
25
+ input: number
26
+ output: number
27
+ cache_read?: number
28
+ cache_write?: number
29
+ }
30
+ status?: 'stable' | 'beta' | 'deprecated'
31
+ knowledgeCutoff?: string
32
+ provenance?: 'snapshot' | 'remote' | 'user-override'
33
+ }
34
+
35
+ export const ModelDefinitionSchema = z
36
+ .object({
37
+ modelId: z.string(),
38
+ name: z.string().optional(),
39
+ family: z.string().optional(),
40
+ type: z.enum(['chat', 'embedding', 'image']).optional(),
41
+ reasoning: z.boolean().optional(),
42
+ tool_call: z.boolean().optional(),
43
+ structured_output: z.boolean().optional(),
44
+ temperature: z.boolean().optional(),
45
+ attachment: z.boolean().optional(),
46
+ streaming: z.boolean().optional(),
47
+ system_message: z.boolean().optional(),
48
+ modalities: z
49
+ .object({
50
+ input: z.array(z.enum(['text', 'image', 'audio', 'video', 'pdf'])),
51
+ output: z.array(z.enum(['text', 'image', 'audio'])),
52
+ })
53
+ .passthrough(),
54
+ limit: z
55
+ .object({
56
+ context: z.number(),
57
+ output: z.number(),
58
+ input_images: z.number().optional(),
59
+ })
60
+ .passthrough(),
61
+ cost: z
62
+ .object({
63
+ input: z.number(),
64
+ output: z.number(),
65
+ cache_read: z.number().optional(),
66
+ cache_write: z.number().optional(),
67
+ })
68
+ .passthrough()
69
+ .optional(),
70
+ status: z.enum(['stable', 'beta', 'deprecated']).optional(),
71
+ knowledgeCutoff: z.string().optional(),
72
+ provenance: z.enum(['snapshot', 'remote', 'user-override']).optional(),
73
+ })
74
+ .passthrough()
75
+
76
+ export interface ModelAlias {
77
+ alias: string
78
+ provider: string
79
+ model: string
80
+ }
81
+
82
+ export const ModelAliasSchema = z
83
+ .object({
84
+ alias: z.string(),
85
+ provider: z.string(),
86
+ model: z.string(),
87
+ })
88
+ .passthrough()
@@ -0,0 +1,49 @@
1
+ export interface ProviderInfo {
2
+ id: string
3
+ name?: string
4
+ }
5
+
6
+ /**
7
+ * Unified credential for all auth types.
8
+ *
9
+ * API key auth (type: 'api'):
10
+ * - key: the API key string (e.g. sk-ant-xxx for Anthropic, sk-xxx for OpenAI)
11
+ *
12
+ * OAuth auth (type: 'oauth'):
13
+ * - key: short-lived access_token for API calls
14
+ * - refresh: long-lived refresh_token used to obtain a new access_token when expired
15
+ * - expires: absolute timestamp (ms) when the access_token expires
16
+ *
17
+ * Well-known auth (type: 'wellknown'):
18
+ * - key: credential discovered from well-known config file locations
19
+ */
20
+ export interface AuthCredential {
21
+ type: 'api' | 'oauth' | 'wellknown'
22
+ /** API key (type 'api') or OAuth access_token (type 'oauth') */
23
+ key?: string
24
+ /** OAuth refresh_token — only present when type is 'oauth' */
25
+ refresh?: string
26
+ /** Absolute timestamp (ms) when the access_token expires — only present when type is 'oauth' */
27
+ expires?: number
28
+ baseURL?: string
29
+ apiHost?: string
30
+ host?: string
31
+ location?: string
32
+ [key: string]: unknown
33
+ }
34
+
35
+ export interface AuthMethod {
36
+ type: string
37
+ label: string
38
+ handler(): Promise<AuthCredential>
39
+ }
40
+
41
+ export interface AuthHook {
42
+ provider: string
43
+ loader(
44
+ getAuth: () => Promise<AuthCredential>,
45
+ provider: ProviderInfo,
46
+ setAuth: (credential: AuthCredential) => Promise<void>,
47
+ ): Promise<Record<string, unknown>>
48
+ methods: AuthMethod[]
49
+ }
@@ -0,0 +1,48 @@
1
+ import { z } from 'zod'
2
+ import type { SecretRef } from './auth.js'
3
+ import { SecretRefSchema } from './auth.js'
4
+ import type { ModelDefinition } from './model.js'
5
+ import { ModelDefinitionSchema } from './model.js'
6
+
7
+ export interface ProviderDefinition {
8
+ id: string
9
+ name: string
10
+ bundledProvider?: string
11
+ defaultSettings?: {
12
+ baseURL?: string
13
+ headers?: Record<string, string>
14
+ options?: Record<string, unknown>
15
+ }
16
+ models?: ModelDefinition[]
17
+ }
18
+
19
+ export const ProviderDefinitionSchema = z
20
+ .object({
21
+ id: z.string(),
22
+ name: z.string(),
23
+ bundledProvider: z.string().optional(),
24
+ defaultSettings: z
25
+ .object({
26
+ baseURL: z.string().optional(),
27
+ headers: z.record(z.string()).optional(),
28
+ options: z.record(z.unknown()).optional(),
29
+ })
30
+ .passthrough()
31
+ .optional(),
32
+ models: z.array(ModelDefinitionSchema).optional(),
33
+ })
34
+ .passthrough()
35
+
36
+ export interface ProviderUserConfig {
37
+ apiKey?: SecretRef
38
+ baseURL?: string
39
+ headers?: Record<string, string>
40
+ options?: Record<string, unknown>
41
+ }
42
+
43
+ export const ProviderUserConfigSchema = z.object({
44
+ apiKey: SecretRefSchema.optional(),
45
+ baseURL: z.string().optional(),
46
+ headers: z.record(z.string()).optional(),
47
+ options: z.record(z.unknown()).optional(),
48
+ })