@molecule/api-resource-ai-models 1.0.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.
- package/LICENSE +115 -0
- package/dist/browser-guard.d.ts +2 -0
- package/dist/browser-guard.d.ts.map +1 -0
- package/dist/browser-guard.js +18 -0
- package/dist/handlers/index.d.ts +2 -0
- package/dist/handlers/index.d.ts.map +1 -0
- package/dist/handlers/index.js +1 -0
- package/dist/handlers/list.d.ts +34 -0
- package/dist/handlers/list.d.ts.map +1 -0
- package/dist/handlers/list.js +48 -0
- package/dist/index.d.ts +48 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +47 -0
- package/dist/lookup.d.ts +93 -0
- package/dist/lookup.d.ts.map +1 -0
- package/dist/lookup.js +121 -0
- package/dist/models.d.ts +78 -0
- package/dist/models.d.ts.map +1 -0
- package/dist/models.js +1233 -0
- package/dist/requestHandlerMap.d.ts +13 -0
- package/dist/requestHandlerMap.d.ts.map +1 -0
- package/dist/requestHandlerMap.js +12 -0
- package/dist/routes.d.ts +13 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +14 -0
- package/dist/types.d.ts +315 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +12 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-guard.d.ts","sourceRoot":"","sources":["../src/browser-guard.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser guard — `@molecule/api-resource-ai-models` is SERVER-ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Generated by scripts/gen-browser-guards.mjs (workspace root) — edit THAT, not this.
|
|
5
|
+
* Evaluating a server package in a browser bundle is always an import-graph mistake
|
|
6
|
+
* (node APIs, secrets); without this guard it surfaces as a cryptic downstream crash
|
|
7
|
+
* ("Buffer is not defined") far from the culprit. Throwing here names the package and
|
|
8
|
+
* the fix at the exact moment the client bundle evaluates it. jsdom tests and SSR are
|
|
9
|
+
* unaffected: the throw requires browser globals AND the absence of a node runtime.
|
|
10
|
+
*/
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g.window !== undefined && g.document !== undefined && !g.process?.versions?.node) {
|
|
13
|
+
throw new Error('@molecule/api-resource-ai-models is SERVER-ONLY: it was bundled into browser/client code. Import it only ' +
|
|
14
|
+
'from server code (a server route/function or your API), or dynamic-import it inside ' +
|
|
15
|
+
'the server handler — never from components or shared client modules, and never ' +
|
|
16
|
+
'polyfill Buffer/process to silence this.');
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/handlers/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './list.js';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /ai/models` — returns the catalog of available AI models.
|
|
3
|
+
*
|
|
4
|
+
* Filters the central `MODELS` list to only those whose provider is currently
|
|
5
|
+
* bonded under the `'ai'` category AND are not `disabled` (a retired model is
|
|
6
|
+
* never listed for selection, though `getModel` still prices it). No further
|
|
7
|
+
* projection is applied — every `ModelDefinition` field is fine to expose to
|
|
8
|
+
* authenticated clients today.
|
|
9
|
+
*
|
|
10
|
+
* Secure-by-default: this handler enforces authentication IN the handler
|
|
11
|
+
* (`res.locals.session.userId`) and fails closed with `401` for an
|
|
12
|
+
* unauthenticated request. It does NOT rely on the `'authenticate'` route
|
|
13
|
+
* middleware alone, because the codegen that emits generated apps can strip
|
|
14
|
+
* declared middleware — leaving the configured-model catalog (provider mix,
|
|
15
|
+
* pricing, capabilities) disclosed to anonymous callers. The in-handler check
|
|
16
|
+
* holds regardless of what happens to the route middleware.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import type { MoleculeRequest, MoleculeResponse } from '@molecule/api-resource';
|
|
21
|
+
/**
|
|
22
|
+
* Returns models whose `provider` has a bond registered under the `'ai'`
|
|
23
|
+
* category. When no AI providers are bonded the response is `{ models: [] }`,
|
|
24
|
+
* which signals a misconfigured server rather than masking the issue.
|
|
25
|
+
*
|
|
26
|
+
* Fails closed with `401` when there is no authenticated session, so the model
|
|
27
|
+
* catalog is never disclosed to an unauthenticated caller even if the route's
|
|
28
|
+
* `'authenticate'` middleware is dropped by codegen.
|
|
29
|
+
*
|
|
30
|
+
* @param _req - The request object (unused).
|
|
31
|
+
* @param res - The response object.
|
|
32
|
+
*/
|
|
33
|
+
export declare function list(_req: MoleculeRequest, res: MoleculeResponse): Promise<void>;
|
|
34
|
+
//# sourceMappingURL=list.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/handlers/list.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAK/E;;;;;;;;;;;GAWG;AACH,wBAAsB,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CActF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `GET /ai/models` — returns the catalog of available AI models.
|
|
3
|
+
*
|
|
4
|
+
* Filters the central `MODELS` list to only those whose provider is currently
|
|
5
|
+
* bonded under the `'ai'` category AND are not `disabled` (a retired model is
|
|
6
|
+
* never listed for selection, though `getModel` still prices it). No further
|
|
7
|
+
* projection is applied — every `ModelDefinition` field is fine to expose to
|
|
8
|
+
* authenticated clients today.
|
|
9
|
+
*
|
|
10
|
+
* Secure-by-default: this handler enforces authentication IN the handler
|
|
11
|
+
* (`res.locals.session.userId`) and fails closed with `401` for an
|
|
12
|
+
* unauthenticated request. It does NOT rely on the `'authenticate'` route
|
|
13
|
+
* middleware alone, because the codegen that emits generated apps can strip
|
|
14
|
+
* declared middleware — leaving the configured-model catalog (provider mix,
|
|
15
|
+
* pricing, capabilities) disclosed to anonymous callers. The in-handler check
|
|
16
|
+
* holds regardless of what happens to the route middleware.
|
|
17
|
+
*
|
|
18
|
+
* @module
|
|
19
|
+
*/
|
|
20
|
+
import { getAll } from '@molecule/api-bond';
|
|
21
|
+
import { t } from '@molecule/api-i18n';
|
|
22
|
+
import { MODELS } from '../models.js';
|
|
23
|
+
/**
|
|
24
|
+
* Returns models whose `provider` has a bond registered under the `'ai'`
|
|
25
|
+
* category. When no AI providers are bonded the response is `{ models: [] }`,
|
|
26
|
+
* which signals a misconfigured server rather than masking the issue.
|
|
27
|
+
*
|
|
28
|
+
* Fails closed with `401` when there is no authenticated session, so the model
|
|
29
|
+
* catalog is never disclosed to an unauthenticated caller even if the route's
|
|
30
|
+
* `'authenticate'` middleware is dropped by codegen.
|
|
31
|
+
*
|
|
32
|
+
* @param _req - The request object (unused).
|
|
33
|
+
* @param res - The response object.
|
|
34
|
+
*/
|
|
35
|
+
export async function list(_req, res) {
|
|
36
|
+
const userId = res.locals.session?.userId;
|
|
37
|
+
if (!userId) {
|
|
38
|
+
res.status(401).json({
|
|
39
|
+
error: t('resource.error.unauthorized', undefined, { defaultValue: 'Unauthorized' }),
|
|
40
|
+
errorKey: 'resource.error.unauthorized',
|
|
41
|
+
});
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const bondedProviders = new Set(getAll('ai').keys());
|
|
45
|
+
const models = MODELS.filter((m) => bondedProviders.has(m.provider) && !m.disabled);
|
|
46
|
+
const response = { models: [...models] };
|
|
47
|
+
res.json(response);
|
|
48
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI model catalog resource.
|
|
3
|
+
*
|
|
4
|
+
* Server-side source of truth for available AI models plus an
|
|
5
|
+
* authentication-gated discovery endpoint (`GET /ai/models`). Server consumers
|
|
6
|
+
* (chat handler, compaction) import `MODELS` / `getModel` / `MODEL_IDS`
|
|
7
|
+
* directly; authenticated clients fetch the filtered projection over HTTP. The
|
|
8
|
+
* `list` handler enforces the session check itself and fails closed with `401`,
|
|
9
|
+
* so the configured-model catalog is never disclosed to an unauthenticated
|
|
10
|
+
* caller even if the route's `'authenticate'` middleware is stripped by codegen.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { getModel, MODEL_IDS } from '@molecule/api-resource-ai-models'
|
|
15
|
+
*
|
|
16
|
+
* // Server-side validation of a client-selected model id:
|
|
17
|
+
* if (!MODEL_IDS.has(requestedId)) {
|
|
18
|
+
* throw new Error('Unknown or retired model')
|
|
19
|
+
* }
|
|
20
|
+
* const model = getModel(requestedId)! // full definition (pricing, effort levels)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* - **No database, no migration — the catalog is code.** Add/retire models by
|
|
25
|
+
* editing `models.ts`; validation (`MODEL_IDS`) and the discovery endpoint
|
|
26
|
+
* update automatically.
|
|
27
|
+
* - **`GET /ai/models` only lists models whose provider is BONDED.** The handler
|
|
28
|
+
* intersects `MODELS` with the names registered under the `'ai'` bond category,
|
|
29
|
+
* so `bond('ai', '<name>', provider)` names must equal
|
|
30
|
+
* `ModelDefinition.provider` ids. An empty `{ models: [] }` response means no
|
|
31
|
+
* AI bond is wired — fix the wiring; never hardcode a model list client-side.
|
|
32
|
+
* - **Disabled models stay resolvable on purpose.** `getModel(id)` returns
|
|
33
|
+
* retired models so historical usage still prices correctly; gate what a user
|
|
34
|
+
* may SELECT with `MODEL_IDS` / `getAvailableModels()`, never with `getModel()`.
|
|
35
|
+
* - The list handler enforces authentication in-handler (fails closed 401) — if
|
|
36
|
+
* you fork it, keep that check; route middleware alone can be stripped by
|
|
37
|
+
* codegen.
|
|
38
|
+
*
|
|
39
|
+
* @module
|
|
40
|
+
*/
|
|
41
|
+
export * from './browser-guard.js';
|
|
42
|
+
export * from './handlers/index.js';
|
|
43
|
+
export * from './lookup.js';
|
|
44
|
+
export * from './models.js';
|
|
45
|
+
export * from './requestHandlerMap.js';
|
|
46
|
+
export * from './routes.js';
|
|
47
|
+
export * from './types.js';
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,cAAc,oBAAoB,CAAA;AAClC,cAAc,qBAAqB,CAAA;AACnC,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI model catalog resource.
|
|
3
|
+
*
|
|
4
|
+
* Server-side source of truth for available AI models plus an
|
|
5
|
+
* authentication-gated discovery endpoint (`GET /ai/models`). Server consumers
|
|
6
|
+
* (chat handler, compaction) import `MODELS` / `getModel` / `MODEL_IDS`
|
|
7
|
+
* directly; authenticated clients fetch the filtered projection over HTTP. The
|
|
8
|
+
* `list` handler enforces the session check itself and fails closed with `401`,
|
|
9
|
+
* so the configured-model catalog is never disclosed to an unauthenticated
|
|
10
|
+
* caller even if the route's `'authenticate'` middleware is stripped by codegen.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { getModel, MODEL_IDS } from '@molecule/api-resource-ai-models'
|
|
15
|
+
*
|
|
16
|
+
* // Server-side validation of a client-selected model id:
|
|
17
|
+
* if (!MODEL_IDS.has(requestedId)) {
|
|
18
|
+
* throw new Error('Unknown or retired model')
|
|
19
|
+
* }
|
|
20
|
+
* const model = getModel(requestedId)! // full definition (pricing, effort levels)
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* - **No database, no migration — the catalog is code.** Add/retire models by
|
|
25
|
+
* editing `models.ts`; validation (`MODEL_IDS`) and the discovery endpoint
|
|
26
|
+
* update automatically.
|
|
27
|
+
* - **`GET /ai/models` only lists models whose provider is BONDED.** The handler
|
|
28
|
+
* intersects `MODELS` with the names registered under the `'ai'` bond category,
|
|
29
|
+
* so `bond('ai', '<name>', provider)` names must equal
|
|
30
|
+
* `ModelDefinition.provider` ids. An empty `{ models: [] }` response means no
|
|
31
|
+
* AI bond is wired — fix the wiring; never hardcode a model list client-side.
|
|
32
|
+
* - **Disabled models stay resolvable on purpose.** `getModel(id)` returns
|
|
33
|
+
* retired models so historical usage still prices correctly; gate what a user
|
|
34
|
+
* may SELECT with `MODEL_IDS` / `getAvailableModels()`, never with `getModel()`.
|
|
35
|
+
* - The list handler enforces authentication in-handler (fails closed 401) — if
|
|
36
|
+
* you fork it, keep that check; route middleware alone can be stripped by
|
|
37
|
+
* codegen.
|
|
38
|
+
*
|
|
39
|
+
* @module
|
|
40
|
+
*/
|
|
41
|
+
export * from './browser-guard.js';
|
|
42
|
+
export * from './handlers/index.js';
|
|
43
|
+
export * from './lookup.js';
|
|
44
|
+
export * from './models.js';
|
|
45
|
+
export * from './requestHandlerMap.js';
|
|
46
|
+
export * from './routes.js';
|
|
47
|
+
export * from './types.js';
|
package/dist/lookup.d.ts
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lookups over the AI model catalog.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { AIProviderID, ModelDefinition } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Set of *selectable* model IDs for fast validation.
|
|
9
|
+
*
|
|
10
|
+
* Excludes `disabled` models so a retired model (e.g. `grok-code-fast-1`) can
|
|
11
|
+
* never be chosen for a new chat, while {@link getModel} still resolves it for
|
|
12
|
+
* historical pricing.
|
|
13
|
+
*/
|
|
14
|
+
export declare const MODEL_IDS: ReadonlySet<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Look up a model definition by ID.
|
|
17
|
+
*
|
|
18
|
+
* Returns `disabled` models too: a saved selection or a historical usage row
|
|
19
|
+
* may reference a since-retired model, and it must stay priceable. Use
|
|
20
|
+
* {@link MODEL_IDS} / {@link getAvailableModels} (which exclude disabled
|
|
21
|
+
* models) to decide what is *selectable*.
|
|
22
|
+
*
|
|
23
|
+
* @param id - The API model ID.
|
|
24
|
+
* @returns The model definition, or `undefined` if not found.
|
|
25
|
+
*/
|
|
26
|
+
export declare function getModel(id: string): ModelDefinition | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Get all models for a specific provider.
|
|
29
|
+
*
|
|
30
|
+
* @param provider - The provider ID.
|
|
31
|
+
* @returns Array of model definitions for that provider.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getModelsByProvider(provider: AIProviderID): readonly ModelDefinition[];
|
|
34
|
+
/**
|
|
35
|
+
* Get models that are currently usable — filtered to only providers that are available.
|
|
36
|
+
*
|
|
37
|
+
* The caller passes in which provider IDs are active (i.e. have a bond wired).
|
|
38
|
+
* `disabled` models are excluded — they are never offered for selection.
|
|
39
|
+
*
|
|
40
|
+
* @param availableProviders - Set or array of provider IDs that have active bonds.
|
|
41
|
+
* @returns Non-disabled models whose provider is in the available set.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getAvailableModels(availableProviders: ReadonlySet<AIProviderID> | readonly AIProviderID[]): readonly ModelDefinition[];
|
|
44
|
+
/**
|
|
45
|
+
* The price multiplier in effect for a model at a given instant.
|
|
46
|
+
*
|
|
47
|
+
* Consults the model's {@link ModelDefinition.peakPricing} windows (UTC,
|
|
48
|
+
* half-open, may wrap midnight). Metering MUST call this with each request's
|
|
49
|
+
* own timestamp so peak-hour usage bills at the provider's real rate — pricing
|
|
50
|
+
* everything at the flat rate silently under-meters peak traffic.
|
|
51
|
+
*
|
|
52
|
+
* @param modelDef - The model definition (or undefined).
|
|
53
|
+
* @param at - The instant the request was made.
|
|
54
|
+
* @returns The multiplier (`1` outside peak windows or when none are declared).
|
|
55
|
+
*/
|
|
56
|
+
export declare function priceMultiplierAt(modelDef: ModelDefinition | undefined, at: Date): number;
|
|
57
|
+
/**
|
|
58
|
+
* Resolve a model's effective processing region: the requested region when the
|
|
59
|
+
* model's {@link ModelDefinition.regions} list offers it, else the model's
|
|
60
|
+
* DEFAULT region (the first listed; `'us'` when the catalog omits regions,
|
|
61
|
+
* which also covers unknown model ids). A single-entry `regions` list pins the
|
|
62
|
+
* model regardless of the request (e.g. a model with no US re-host).
|
|
63
|
+
*
|
|
64
|
+
* @param modelDef - The model definition (or undefined for unknown ids).
|
|
65
|
+
* @param requested - The user's per-model region choice, if any.
|
|
66
|
+
* @returns The effective region code.
|
|
67
|
+
*/
|
|
68
|
+
export declare function effectiveModelRegion(modelDef: ModelDefinition | undefined, requested?: string): string;
|
|
69
|
+
/** The four per-MTok token rates a turn bills at (USD). */
|
|
70
|
+
export interface ModelTokenRates {
|
|
71
|
+
/** Input price per million uncached tokens in USD. */
|
|
72
|
+
inputPricePerMTok: number;
|
|
73
|
+
/** Output price per million tokens in USD. */
|
|
74
|
+
outputPricePerMTok: number;
|
|
75
|
+
/** Prompt-cache read price per million tokens in USD. */
|
|
76
|
+
cacheReadPricePerMTok: number;
|
|
77
|
+
/** Prompt-cache write price per million tokens in USD. */
|
|
78
|
+
cacheWritePricePerMTok: number;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The token rates for a model in a given processing region: the model's
|
|
82
|
+
* {@link ModelDefinition.regionPricing} override for the region when one
|
|
83
|
+
* exists, else the base rates (the native provider's list prices). Omitted
|
|
84
|
+
* cache fields in an override fall back to the override's input price (hosts
|
|
85
|
+
* with no cache discount / no write premium). The region is resolved via
|
|
86
|
+
* {@link effectiveModelRegion}, so callers may pass the raw user choice.
|
|
87
|
+
*
|
|
88
|
+
* @param modelDef - The model definition.
|
|
89
|
+
* @param requested - The user's per-model region choice, if any.
|
|
90
|
+
* @returns The region-effective rates.
|
|
91
|
+
*/
|
|
92
|
+
export declare function modelRegionRates(modelDef: ModelDefinition, requested?: string): ModelTokenRates;
|
|
93
|
+
//# sourceMappingURL=lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lookup.d.ts","sourceRoot":"","sources":["../src/lookup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,EAAE,WAAW,CAAC,MAAM,CAEzC,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAEhE;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,SAAS,eAAe,EAAE,CAEtF;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAChC,kBAAkB,EAAE,WAAW,CAAC,YAAY,CAAC,GAAG,SAAS,YAAY,EAAE,GACtE,SAAS,eAAe,EAAE,CAI5B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,SAAS,EAAE,EAAE,EAAE,IAAI,GAAG,MAAM,CAYzF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,eAAe,GAAG,SAAS,EACrC,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CAGR;AAED,2DAA2D;AAC3D,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,iBAAiB,EAAE,MAAM,CAAA;IACzB,8CAA8C;IAC9C,kBAAkB,EAAE,MAAM,CAAA;IAC1B,yDAAyD;IACzD,qBAAqB,EAAE,MAAM,CAAA;IAC7B,0DAA0D;IAC1D,sBAAsB,EAAE,MAAM,CAAA;CAC/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,eAAe,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,eAAe,CAiB/F"}
|
package/dist/lookup.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lookups over the AI model catalog.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { MODELS } from './models.js';
|
|
7
|
+
/**
|
|
8
|
+
* Set of *selectable* model IDs for fast validation.
|
|
9
|
+
*
|
|
10
|
+
* Excludes `disabled` models so a retired model (e.g. `grok-code-fast-1`) can
|
|
11
|
+
* never be chosen for a new chat, while {@link getModel} still resolves it for
|
|
12
|
+
* historical pricing.
|
|
13
|
+
*/
|
|
14
|
+
export const MODEL_IDS = new Set(MODELS.filter((m) => !m.disabled).map((m) => m.id));
|
|
15
|
+
/**
|
|
16
|
+
* Look up a model definition by ID.
|
|
17
|
+
*
|
|
18
|
+
* Returns `disabled` models too: a saved selection or a historical usage row
|
|
19
|
+
* may reference a since-retired model, and it must stay priceable. Use
|
|
20
|
+
* {@link MODEL_IDS} / {@link getAvailableModels} (which exclude disabled
|
|
21
|
+
* models) to decide what is *selectable*.
|
|
22
|
+
*
|
|
23
|
+
* @param id - The API model ID.
|
|
24
|
+
* @returns The model definition, or `undefined` if not found.
|
|
25
|
+
*/
|
|
26
|
+
export function getModel(id) {
|
|
27
|
+
return MODELS.find((m) => m.id === id);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get all models for a specific provider.
|
|
31
|
+
*
|
|
32
|
+
* @param provider - The provider ID.
|
|
33
|
+
* @returns Array of model definitions for that provider.
|
|
34
|
+
*/
|
|
35
|
+
export function getModelsByProvider(provider) {
|
|
36
|
+
return MODELS.filter((m) => m.provider === provider);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get models that are currently usable — filtered to only providers that are available.
|
|
40
|
+
*
|
|
41
|
+
* The caller passes in which provider IDs are active (i.e. have a bond wired).
|
|
42
|
+
* `disabled` models are excluded — they are never offered for selection.
|
|
43
|
+
*
|
|
44
|
+
* @param availableProviders - Set or array of provider IDs that have active bonds.
|
|
45
|
+
* @returns Non-disabled models whose provider is in the available set.
|
|
46
|
+
*/
|
|
47
|
+
export function getAvailableModels(availableProviders) {
|
|
48
|
+
const providerSet = availableProviders instanceof Set ? availableProviders : new Set(availableProviders);
|
|
49
|
+
return MODELS.filter((m) => providerSet.has(m.provider) && !m.disabled);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The price multiplier in effect for a model at a given instant.
|
|
53
|
+
*
|
|
54
|
+
* Consults the model's {@link ModelDefinition.peakPricing} windows (UTC,
|
|
55
|
+
* half-open, may wrap midnight). Metering MUST call this with each request's
|
|
56
|
+
* own timestamp so peak-hour usage bills at the provider's real rate — pricing
|
|
57
|
+
* everything at the flat rate silently under-meters peak traffic.
|
|
58
|
+
*
|
|
59
|
+
* @param modelDef - The model definition (or undefined).
|
|
60
|
+
* @param at - The instant the request was made.
|
|
61
|
+
* @returns The multiplier (`1` outside peak windows or when none are declared).
|
|
62
|
+
*/
|
|
63
|
+
export function priceMultiplierAt(modelDef, at) {
|
|
64
|
+
const peak = modelDef?.peakPricing;
|
|
65
|
+
if (!peak || peak.windows.length === 0)
|
|
66
|
+
return 1;
|
|
67
|
+
const minute = at.getUTCHours() * 60 + at.getUTCMinutes();
|
|
68
|
+
for (const w of peak.windows) {
|
|
69
|
+
const inWindow = w.startMinuteUtc <= w.endMinuteUtc
|
|
70
|
+
? minute >= w.startMinuteUtc && minute < w.endMinuteUtc
|
|
71
|
+
: minute >= w.startMinuteUtc || minute < w.endMinuteUtc;
|
|
72
|
+
if (inWindow)
|
|
73
|
+
return peak.multiplier;
|
|
74
|
+
}
|
|
75
|
+
return 1;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Resolve a model's effective processing region: the requested region when the
|
|
79
|
+
* model's {@link ModelDefinition.regions} list offers it, else the model's
|
|
80
|
+
* DEFAULT region (the first listed; `'us'` when the catalog omits regions,
|
|
81
|
+
* which also covers unknown model ids). A single-entry `regions` list pins the
|
|
82
|
+
* model regardless of the request (e.g. a model with no US re-host).
|
|
83
|
+
*
|
|
84
|
+
* @param modelDef - The model definition (or undefined for unknown ids).
|
|
85
|
+
* @param requested - The user's per-model region choice, if any.
|
|
86
|
+
* @returns The effective region code.
|
|
87
|
+
*/
|
|
88
|
+
export function effectiveModelRegion(modelDef, requested) {
|
|
89
|
+
const regions = modelDef?.regions ?? ['us'];
|
|
90
|
+
return requested && regions.includes(requested) ? requested : regions[0];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The token rates for a model in a given processing region: the model's
|
|
94
|
+
* {@link ModelDefinition.regionPricing} override for the region when one
|
|
95
|
+
* exists, else the base rates (the native provider's list prices). Omitted
|
|
96
|
+
* cache fields in an override fall back to the override's input price (hosts
|
|
97
|
+
* with no cache discount / no write premium). The region is resolved via
|
|
98
|
+
* {@link effectiveModelRegion}, so callers may pass the raw user choice.
|
|
99
|
+
*
|
|
100
|
+
* @param modelDef - The model definition.
|
|
101
|
+
* @param requested - The user's per-model region choice, if any.
|
|
102
|
+
* @returns The region-effective rates.
|
|
103
|
+
*/
|
|
104
|
+
export function modelRegionRates(modelDef, requested) {
|
|
105
|
+
const region = effectiveModelRegion(modelDef, requested);
|
|
106
|
+
const override = modelDef.regionPricing?.[region];
|
|
107
|
+
if (!override) {
|
|
108
|
+
return {
|
|
109
|
+
inputPricePerMTok: modelDef.inputPricePerMTok,
|
|
110
|
+
outputPricePerMTok: modelDef.outputPricePerMTok,
|
|
111
|
+
cacheReadPricePerMTok: modelDef.cacheReadPricePerMTok,
|
|
112
|
+
cacheWritePricePerMTok: modelDef.cacheWritePricePerMTok,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
inputPricePerMTok: override.inputPricePerMTok,
|
|
117
|
+
outputPricePerMTok: override.outputPricePerMTok,
|
|
118
|
+
cacheReadPricePerMTok: override.cacheReadPricePerMTok ?? override.inputPricePerMTok,
|
|
119
|
+
cacheWritePricePerMTok: override.cacheWritePricePerMTok ?? override.inputPricePerMTok,
|
|
120
|
+
};
|
|
121
|
+
}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Available AI models.
|
|
3
|
+
*
|
|
4
|
+
* This is the single source of truth for which models Synthase can use.
|
|
5
|
+
* Server-side code (chat handler, compaction) consumes the full definitions
|
|
6
|
+
* directly; clients receive the `PublicModel` projection from `GET /ai/models`.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { ModelDefinition } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* All available AI models, grouped by provider, ordered from most to least capable.
|
|
13
|
+
*
|
|
14
|
+
* To add or remove a model, edit this array. Both the server-side validation
|
|
15
|
+
* and the public discovery endpoint will update automatically.
|
|
16
|
+
*
|
|
17
|
+
* Effort is each model's OWN native value — there is no abstract scale (see
|
|
18
|
+
* {@link ModelDefinition.supportedEffortLevels}):
|
|
19
|
+
* - A model driven by a provider-native effort/level param lists its provider
|
|
20
|
+
* values verbatim in `supportedEffortLevels` (ascending), with
|
|
21
|
+
* `defaultEffortLevel` = the provider's default/recommended level for agentic
|
|
22
|
+
* coding. NO `effortBudgetTokens`.
|
|
23
|
+
* - A model with a controllable token budget but no native level names (e.g.
|
|
24
|
+
* Claude Haiku 4.5's `budget_tokens`, Qwen's `thinking_budget`) lists
|
|
25
|
+
* scaled-budget labels (`['4K', '8K', '16K', '32K']`) with `effortBudgetTokens`
|
|
26
|
+
* mapping each label to the token budget it sends.
|
|
27
|
+
* - A model whose reasoning is fixed (always-on or on/off only, no depth
|
|
28
|
+
* control) carries `thinkingConfigurable: false` and OMITS both fields —
|
|
29
|
+
* there is nothing to tune.
|
|
30
|
+
*
|
|
31
|
+
* Sources (verified 2026-07-28; OpenAI re-verified 2026-07-31 after the
|
|
32
|
+
* 2026-07-30 GPT-5.6 repricing — cross-check prices against models.dev with
|
|
33
|
+
* `npm run check:model-freshness` from the workspace root):
|
|
34
|
+
* - Anthropic: https://platform.claude.com/docs/en/about-claude/models/overview
|
|
35
|
+
* + /docs/en/build-with-claude/effort (fable-5 / opus-5 / sonnet-5 current;
|
|
36
|
+
* opus-4-8 superseded by opus-5 at identical pricing but still served — it is
|
|
37
|
+
* the recommended refusal-fallback model; effort ladder on all three current
|
|
38
|
+
* models is low|medium|high|xhigh|max; budget_tokens 400s on 4.7+)
|
|
39
|
+
* - OpenAI: https://developers.openai.com/api/docs/pricing (GPT-5.6 family GA
|
|
40
|
+
* 2026-07-09; REPRICED 2026-07-30: -luna cut 80% to $0.20/$1.20, -terra cut
|
|
41
|
+
* 20% to $2/$12, -sol unchanged $5/$30; cache read 0.1× input; gpt-5.5/
|
|
42
|
+
* gpt-5.4 still listed as current; long-context 2× variants exist upstream —
|
|
43
|
+
* not modeled, same as the Gemini/Grok tiers; Sol "Fast mode" 2.5× speed at
|
|
44
|
+
* 2× price announced 2026-07-30 — not yet modeled)
|
|
45
|
+
* - Google: https://ai.google.dev/gemini-api/docs/pricing (gemini-3.6-flash GA
|
|
46
|
+
* 2026-07-21 $1.50/$7.50 supersedes 3.5-flash as the agentic flagship;
|
|
47
|
+
* gemini-3.1-pro-preview still the pro tier — "3.5 Pro" has NOT shipped as
|
|
48
|
+
* of 2026-07-28 despite the coming-soon badge; do not add until it has an id)
|
|
49
|
+
* - xAI: https://docs.x.ai/developers/models + /developers/grok-4-5
|
|
50
|
+
* (grok-4.5 flagship 2026-07-08: $2/$6, 500K ctx, ≥200K prompts bill 2× —
|
|
51
|
+
* not modeled; reasoning_effort low|medium|high default high, image input;
|
|
52
|
+
* grok-4.3 still served at $1.25/$2.50 with the bigger 1M window;
|
|
53
|
+
* grok-code-fast-1 no longer listed — retires 2026-08-15)
|
|
54
|
+
* - DeepSeek: https://api-docs.deepseek.com/quick_start/pricing (unchanged V4
|
|
55
|
+
* Pro/Flash pricing; legacy deepseek-chat/-reasoner ids fully retired
|
|
56
|
+
* 2026-07-24 — never in this catalog; the announced peak-hour 2× surcharge is
|
|
57
|
+
* still NOT active as of 2026-07-28, see the entries)
|
|
58
|
+
* - Moonshot: https://platform.kimi.ai/docs/models (kimi-k3 flagship 2026-07-16
|
|
59
|
+
* — 2.8T MoE, 1M ctx, $3/$15 — NOT added: thinking is forced-on with
|
|
60
|
+
* reasoning_content that must be replayed through tool loops, the same
|
|
61
|
+
* constraint that keeps kimi-k2.7-code out; add BOTH once the moonshot bond
|
|
62
|
+
* supports preserved thinking + reasoning_effort low|high|max. kimi-k2.6
|
|
63
|
+
* remains the newest model the bond can run correctly.)
|
|
64
|
+
* - MiniMax: https://platform.minimax.io/docs/guides/pricing-paygo (unchanged;
|
|
65
|
+
* minimax-m3 $0.30/$1.20 is a "permanent 50% off" list rate)
|
|
66
|
+
* - Alibaba: https://www.alibabacloud.com/help/en/model-studio/deep-thinking
|
|
67
|
+
* (unchanged; qwen3.8-max-preview, 2026-07-19, is Token-Plan-subscriber-only
|
|
68
|
+
* — not on the pay-as-you-go API, so it cannot be added yet; qwen3.7-max
|
|
69
|
+
* currently runs a 50%-off promo — still billed here at list, $2.50/$7.50)
|
|
70
|
+
* - Zhipu: https://docs.z.ai/guides/overview/pricing (unchanged; glm-5.2 is
|
|
71
|
+
* the newest — "GLM-5.3/5.5" rumors have no released ids as of 2026-07-28)
|
|
72
|
+
*
|
|
73
|
+
* Knowledge-cutoff dates on non-Anthropic entries are best-effort estimates
|
|
74
|
+
* where the provider doesn't publish one; the provider sources above verify
|
|
75
|
+
* id / pricing / context window.
|
|
76
|
+
*/
|
|
77
|
+
export declare const MODELS: readonly ModelDefinition[];
|
|
78
|
+
//# sourceMappingURL=models.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"models.d.ts","sourceRoot":"","sources":["../src/models.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,eAAO,MAAM,MAAM,EAAE,SAAS,eAAe,EA6oCnC,CAAA"}
|