@modelprofile.com/flexharness-providers 9.0.0 → 9.2.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 (109) hide show
  1. package/dist_ts_anthropic_messages/errors.d.ts +22 -0
  2. package/dist_ts_anthropic_messages/errors.js +100 -0
  3. package/dist_ts_anthropic_messages/index.d.ts +4 -0
  4. package/dist_ts_anthropic_messages/index.js +4 -0
  5. package/dist_ts_anthropic_messages/interfaces.d.ts +185 -0
  6. package/dist_ts_anthropic_messages/interfaces.js +2 -0
  7. package/dist_ts_anthropic_messages/openai.d.ts +19 -0
  8. package/dist_ts_anthropic_messages/openai.js +48 -0
  9. package/dist_ts_anthropic_messages/plugins.d.ts +4 -0
  10. package/dist_ts_anthropic_messages/plugins.js +4 -0
  11. package/dist_ts_anthropic_messages/request.d.ts +109 -0
  12. package/dist_ts_anthropic_messages/request.js +554 -0
  13. package/dist_ts_anthropic_messages/service.d.ts +8 -0
  14. package/dist_ts_anthropic_messages/service.js +274 -0
  15. package/dist_ts_anthropic_messages/signature.d.ts +16 -0
  16. package/dist_ts_anthropic_messages/signature.js +91 -0
  17. package/dist_ts_anthropic_messages/stream.d.ts +48 -0
  18. package/dist_ts_anthropic_messages/stream.js +220 -0
  19. package/dist_ts_anthropic_messages_node/index.d.ts +8 -0
  20. package/dist_ts_anthropic_messages_node/index.js +93 -0
  21. package/dist_ts_anthropic_messages_node/plugins.d.ts +6 -0
  22. package/dist_ts_anthropic_messages_node/plugins.js +4 -0
  23. package/dist_ts_openai_account/plugins.d.ts +2 -0
  24. package/dist_ts_openai_account/plugins.js +4 -1
  25. package/dist_ts_openai_account/smartai.providers.interfaces.d.ts +6 -22
  26. package/dist_ts_openai_account/smartai.providers.openai.js +15 -134
  27. package/dist_ts_openai_auth/index.d.ts +1 -2
  28. package/dist_ts_openai_auth/index.js +2 -3
  29. package/dist_ts_openai_auth/interfaces.d.ts +1 -1
  30. package/dist_ts_openai_auth/smartai.auth.openai.d.ts +3 -15
  31. package/dist_ts_openai_auth/smartai.auth.openai.js +3 -17
  32. package/dist_ts_openai_auth/smartai.connection.openai.d.ts +1 -1
  33. package/dist_ts_openai_auth/smartai.connection.openai.js +2 -3
  34. package/dist_ts_providers/anthropic/index.d.ts +1 -1
  35. package/dist_ts_providers/anthropic/index.js +1 -1
  36. package/dist_ts_providers/anthropic/plugins.d.ts +1 -1
  37. package/dist_ts_providers/google/index.d.ts +1 -1
  38. package/dist_ts_providers/google/index.js +1 -1
  39. package/dist_ts_providers/google/plugins.d.ts +1 -1
  40. package/dist_ts_providers/groq/index.d.ts +1 -1
  41. package/dist_ts_providers/groq/index.js +1 -1
  42. package/dist_ts_providers/groq/plugins.d.ts +1 -1
  43. package/dist_ts_providers/mistral/index.d.ts +1 -1
  44. package/dist_ts_providers/mistral/index.js +1 -1
  45. package/dist_ts_providers/mistral/plugins.d.ts +1 -1
  46. package/dist_ts_providers/openai/index.d.ts +5 -1
  47. package/dist_ts_providers/openai/index.js +5 -1
  48. package/dist_ts_providers/openai/plugins.d.ts +4 -4
  49. package/dist_ts_providers/openai/plugins.js +3 -3
  50. package/dist_ts_providers/openai/smartai.chatgpt.catalog.d.ts +61 -0
  51. package/dist_ts_providers/openai/smartai.chatgpt.catalog.js +252 -0
  52. package/{dist_ts_openai_auth/smartai.limits.openai.d.ts → dist_ts_providers/openai/smartai.chatgpt.limits.d.ts} +2 -2
  53. package/dist_ts_providers/openai/smartai.chatgpt.limits.js +49 -0
  54. package/dist_ts_providers/openai/smartai.chatgpt.middleware.d.ts +10 -0
  55. package/dist_ts_providers/openai/smartai.chatgpt.middleware.js +60 -0
  56. package/dist_ts_providers/openai/smartai.chatgpt.openai.d.ts +92 -0
  57. package/dist_ts_providers/openai/smartai.chatgpt.openai.js +160 -0
  58. package/dist_ts_providers/perplexity/index.d.ts +1 -1
  59. package/dist_ts_providers/perplexity/index.js +1 -1
  60. package/dist_ts_providers/perplexity/plugins.d.ts +1 -1
  61. package/dist_ts_providers/xai/index.d.ts +1 -1
  62. package/dist_ts_providers/xai/index.js +1 -1
  63. package/dist_ts_providers/xai/plugins.d.ts +1 -1
  64. package/package.json +14 -2
  65. package/readme.md +9 -0
  66. package/ts_anthropic_messages/errors.ts +124 -0
  67. package/ts_anthropic_messages/index.ts +24 -0
  68. package/ts_anthropic_messages/interfaces.ts +173 -0
  69. package/ts_anthropic_messages/openai.ts +58 -0
  70. package/ts_anthropic_messages/plugins.ts +26 -0
  71. package/ts_anthropic_messages/readme.md +129 -0
  72. package/ts_anthropic_messages/request.ts +652 -0
  73. package/ts_anthropic_messages/service.ts +312 -0
  74. package/ts_anthropic_messages/signature.ts +107 -0
  75. package/ts_anthropic_messages/stream.ts +260 -0
  76. package/ts_anthropic_messages_node/index.ts +99 -0
  77. package/ts_anthropic_messages_node/plugins.ts +7 -0
  78. package/ts_anthropic_messages_node/readme.md +50 -0
  79. package/ts_openai_account/plugins.ts +5 -0
  80. package/ts_openai_account/smartai.providers.interfaces.ts +11 -25
  81. package/ts_openai_account/smartai.providers.openai.ts +16 -135
  82. package/ts_openai_auth/index.ts +4 -2
  83. package/ts_openai_auth/interfaces.ts +1 -1
  84. package/ts_openai_auth/smartai.auth.openai.ts +12 -24
  85. package/ts_openai_auth/smartai.connection.openai.ts +5 -3
  86. package/ts_providers/anthropic/index.ts +1 -1
  87. package/ts_providers/anthropic/plugins.ts +1 -0
  88. package/ts_providers/google/index.ts +1 -1
  89. package/ts_providers/google/plugins.ts +1 -1
  90. package/ts_providers/groq/index.ts +1 -1
  91. package/ts_providers/groq/plugins.ts +1 -1
  92. package/ts_providers/mistral/index.ts +1 -1
  93. package/ts_providers/mistral/plugins.ts +1 -1
  94. package/ts_providers/openai/index.ts +30 -1
  95. package/ts_providers/openai/plugins.ts +5 -3
  96. package/ts_providers/openai/readme.md +60 -7
  97. package/ts_providers/openai/smartai.chatgpt.catalog.ts +319 -0
  98. package/{ts_openai_auth/smartai.limits.openai.ts → ts_providers/openai/smartai.chatgpt.limits.ts} +6 -7
  99. package/ts_providers/openai/smartai.chatgpt.middleware.ts +71 -0
  100. package/ts_providers/openai/smartai.chatgpt.openai.ts +271 -0
  101. package/ts_providers/perplexity/index.ts +1 -1
  102. package/ts_providers/perplexity/plugins.ts +1 -1
  103. package/ts_providers/readme.md +9 -0
  104. package/ts_providers/xai/index.ts +1 -1
  105. package/ts_providers/xai/plugins.ts +1 -1
  106. package/dist_ts_openai_auth/smartai.limits.openai.js +0 -49
  107. package/dist_ts_openai_auth/smartai.middleware.openai.d.ts +0 -6
  108. package/dist_ts_openai_auth/smartai.middleware.openai.js +0 -47
  109. package/ts_openai_auth/smartai.middleware.openai.ts +0 -55
@@ -0,0 +1,99 @@
1
+ import * as plugins from './plugins.js';
2
+
3
+ const bodylessMethods: ReadonlySet<string> = new Set(['GET', 'HEAD']);
4
+
5
+ const toRequest = (incomingArg: plugins.http.IncomingMessage, signalArg: AbortSignal): Request => {
6
+ const headers = new Headers();
7
+ for (let index = 0; index + 1 < incomingArg.rawHeaders.length; index += 2) {
8
+ headers.append(incomingArg.rawHeaders[index], incomingArg.rawHeaders[index + 1]);
9
+ }
10
+ const method = incomingArg.method ?? 'GET';
11
+ // Only the path and query are taken from the request line; the Host header stays a header, for the
12
+ // service's `authenticate` to judge.
13
+ const url = new URL(incomingArg.url ?? '/', 'http://localhost');
14
+ return new Request(url, {
15
+ method,
16
+ headers,
17
+ signal: signalArg,
18
+ ...(bodylessMethods.has(method)
19
+ ? {}
20
+ // `Readable.toWeb` is typed with Node's own stream/web types, which the global `BodyInit` does not name.
21
+ : { body: plugins.Readable.toWeb(incomingArg) as ReadableStream<Uint8Array>, duplex: 'half' as const }),
22
+ });
23
+ };
24
+
25
+ const writeResponse = async (
26
+ responseArg: Response,
27
+ outgoingArg: plugins.http.ServerResponse,
28
+ signalArg: AbortSignal,
29
+ ): Promise<void> => {
30
+ if (signalArg.aborted) {
31
+ // The client left while the answer was prepared; cancelling the body releases what it holds, such as the
32
+ // model call and the ping timer of a stream.
33
+ await responseArg.body?.cancel(signalArg.reason);
34
+ return;
35
+ }
36
+ outgoingArg.writeHead(responseArg.status, Object.fromEntries(responseArg.headers));
37
+ outgoingArg.flushHeaders();
38
+ if (!responseArg.body) {
39
+ outgoingArg.end();
40
+ return;
41
+ }
42
+ const reader = responseArg.body.getReader();
43
+ const onAbort = (): void => {
44
+ void reader.cancel(signalArg.reason).catch(() => undefined);
45
+ };
46
+ signalArg.addEventListener('abort', onAbort, { once: true });
47
+ let finished = false;
48
+ try {
49
+ while (!signalArg.aborted) {
50
+ const { done, value } = await reader.read();
51
+ if (done) {
52
+ finished = true;
53
+ break;
54
+ }
55
+ // A socket that closes while full aborts the signal, which ends this wait.
56
+ if (!outgoingArg.write(value)) await plugins.once(outgoingArg, 'drain', { signal: signalArg });
57
+ }
58
+ } finally {
59
+ signalArg.removeEventListener('abort', onAbort);
60
+ // A write that failed leaves the body unread; cancelling it releases the model call and the ping timer.
61
+ if (!finished) await reader.cancel(signalArg.reason).catch(() => undefined);
62
+ reader.releaseLock();
63
+ }
64
+ if (!signalArg.aborted) outgoingArg.end();
65
+ };
66
+
67
+ /**
68
+ * Hosts an Anthropic Messages service on a Node HTTP server: `http.createServer(listener)`.
69
+ *
70
+ * A streamed answer is written as it is produced and waits for the socket when it is full. A client that
71
+ * disconnects aborts its request, which stops the model call behind it.
72
+ */
73
+ export const createAnthropicMessagesNodeListener = (
74
+ serviceArg: plugins.IAnthropicMessagesService,
75
+ ): ((incomingArg: plugins.http.IncomingMessage, outgoingArg: plugins.http.ServerResponse) => void) => (
76
+ incomingArg,
77
+ outgoingArg,
78
+ ) => {
79
+ const abort = new AbortController();
80
+ outgoingArg.once('close', () => {
81
+ if (!outgoingArg.writableFinished) abort.abort(new Error('The client closed the connection.'));
82
+ });
83
+ void (async () => {
84
+ const response = await serviceArg.handle(toRequest(incomingArg, abort.signal));
85
+ await writeResponse(response, outgoingArg, abort.signal);
86
+ })().catch((errorArg: unknown) => {
87
+ // A client that left has no one to tell; its abort already ended the answer.
88
+ if (abort.signal.aborted) return;
89
+ if (!outgoingArg.headersSent) {
90
+ outgoingArg.writeHead(500, { 'content-type': 'application/json' });
91
+ outgoingArg.end(JSON.stringify({
92
+ type: 'error',
93
+ error: { type: 'api_error', message: `The request could not be served: ${errorArg instanceof Error ? errorArg.message : String(errorArg)}` },
94
+ }));
95
+ return;
96
+ }
97
+ outgoingArg.destroy(errorArg instanceof Error ? errorArg : new Error(String(errorArg)));
98
+ });
99
+ };
@@ -0,0 +1,7 @@
1
+ import type * as http from 'node:http';
2
+ import { once } from 'node:events';
3
+ import { Readable } from 'node:stream';
4
+
5
+ export { once, Readable };
6
+ export type { http };
7
+ export type { IAnthropicMessagesService } from '@modelprofile.com/flexharness-providers/anthropic-messages';
@@ -0,0 +1,50 @@
1
+ Hosts an Anthropic Messages service on a Node HTTP server.
2
+
3
+ Part of the [FlexHarness toolbox](https://code.foss.global/modelprofile.com/flexharness).
4
+ Install the components your project uses. Provider adapters are registered explicitly;
5
+ the agent and harness do not install or register vendor SDKs.
6
+
7
+ ```sh
8
+ pnpm add @modelprofile.com/flexharness-providers
9
+ ```
10
+
11
+ See the [toolbox usage and migration guide](https://code.foss.global/modelprofile.com/flexharness#readme)
12
+ for composition examples and the SmartAI/SmartAgent migration map.
13
+
14
+ ```typescript
15
+ import * as http from 'node:http';
16
+ import { createAnthropicMessagesNodeListener } from '@modelprofile.com/flexharness-providers/anthropic-messages/node';
17
+
18
+ const server = http.createServer(createAnthropicMessagesNodeListener(service));
19
+ server.listen(0, '127.0.0.1');
20
+ ```
21
+
22
+ A streamed answer is written as the model produces it and waits for the socket when it is full. A client that
23
+ disconnects aborts its request, which stops the model call behind it; one that leaves before the answer
24
+ begins gets no model call, or has the answer that was already prepared cancelled with its model call. The request line gives the path and
25
+ query only; the `Host` header stays a header for the service's `authenticate` to judge.
26
+
27
+ ## Issue Reporting and Security
28
+
29
+ Report issues and security concerns through [community.foss.global](https://community.foss.global).
30
+
31
+ ## License and Legal Information
32
+
33
+ This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the repository license file.
34
+
35
+ **Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
36
+
37
+ ### Trademarks
38
+
39
+ This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
40
+
41
+ Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
42
+
43
+ ### Company Information
44
+
45
+ Task Venture Capital GmbH<br>
46
+ Registered at District Court Bremen HRB 35230 HB, Germany
47
+
48
+ For any legal inquiries or further information, please contact us via email at hello@task.vc.
49
+
50
+ By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
@@ -7,3 +7,8 @@ import type { Socket } from 'node:net';
7
7
 
8
8
  export { Buffer, crypto, http };
9
9
  export type { Server, Socket };
10
+
11
+ // @modelprofile.com scope
12
+ import * as openAi from '@modelprofile.com/flexharness-providers/openai';
13
+
14
+ export { openAi };
@@ -1,8 +1,14 @@
1
1
  import type { TOpenAiChatGptRequestOutcome } from '@modelprofile.com/flexharness-providers/auth';
2
+ import type {
3
+ IOpenAiChatGptModel,
4
+ IOpenAiChatGptModelReasoningEffort,
5
+ IOpenAiChatGptModelServiceTier,
6
+ TOpenAiChatGptInputModality,
7
+ } from '@modelprofile.com/flexharness-providers/openai';
2
8
 
3
9
  export type TSmartAiProviderId = string;
4
10
  export type TSmartAiProviderLoginFlow = 'browser' | 'device';
5
- export type TSmartAiProviderInputModality = 'text' | 'image' | 'audio';
11
+ export type TSmartAiProviderInputModality = TOpenAiChatGptInputModality;
6
12
 
7
13
  export interface ISmartAiProviderDescriptor {
8
14
  providerId: TSmartAiProviderId;
@@ -87,32 +93,12 @@ export interface ISmartAiProviderOperationOptions {
87
93
  timeoutMs?: number;
88
94
  }
89
95
 
90
- export interface ISmartAiProviderModelReasoningEffort {
91
- effort: string;
92
- description: string;
93
- }
96
+ /** The catalog shapes are defined once, by the access-only catalog read in `/openai`. */
97
+ export interface ISmartAiProviderModelReasoningEffort extends IOpenAiChatGptModelReasoningEffort {}
94
98
 
95
- export interface ISmartAiProviderModelServiceTier {
96
- id: string;
97
- name: string;
98
- description: string;
99
- }
99
+ export interface ISmartAiProviderModelServiceTier extends IOpenAiChatGptModelServiceTier {}
100
100
 
101
- export interface ISmartAiProviderModel {
102
- providerId: 'openai';
103
- modelId: string;
104
- wireModel: string;
105
- displayName: string;
106
- description: string;
107
- hidden: boolean;
108
- reasoningEfforts: ISmartAiProviderModelReasoningEffort[];
109
- defaultReasoningEffort: string;
110
- inputModalities: TSmartAiProviderInputModality[];
111
- supportsPersonality: boolean;
112
- serviceTiers: ISmartAiProviderModelServiceTier[];
113
- defaultServiceTier?: string;
114
- isDefault: boolean;
115
- }
101
+ export interface ISmartAiProviderModel extends IOpenAiChatGptModel {}
116
102
 
117
103
  export interface ISmartAiProviderModelListOptions extends ISmartAiProviderOperationOptions {
118
104
  cursor?: string;
@@ -1,7 +1,6 @@
1
1
  // OpenAI protocol portions are adapted in TypeScript; see third-party-notices.md.
2
2
  import * as plugins from './plugins.js';
3
3
  import {
4
- OPENAI_CHATGPT_CODEX_BASE_URL,
5
4
  OPENAI_CHATGPT_DEFAULT_ORIGINATOR,
6
5
  OpenAiChatGptAuthError,
7
6
  completeOpenAiChatGptDeviceCodeLogin,
@@ -43,13 +42,10 @@ const defaultBrowserLoginTimeoutMs = 11 * 60 * 1000;
43
42
  const defaultDeviceLoginTimeoutMs = 15 * 60 * 1000;
44
43
  const defaultOperationTimeoutMs = 30_000;
45
44
  const maximumOperationTimeoutMs = 20 * 60 * 1000;
46
- const maximumCatalogBytes = 2 * 1024 * 1024;
47
45
  const maximumAccountRateLimitsBytes = 256 * 1024;
48
- const maximumCatalogModels = 256;
49
46
  const maximumAdditionalRateLimits = 128;
50
47
  const maximumCursorBytes = 4096;
51
48
  const maximumModelPageSize = 50;
52
- const defaultClientVersion = '0.146.1';
53
49
  const maximumHeaderBytes = 16 * 1024;
54
50
  const maximumCallbackUrlBytes = 4096;
55
51
  const accountRateLimitsUrl = 'https://chatgpt.com/backend-api/wham/usage';
@@ -185,15 +181,9 @@ const toTokenData = (credentialArg: IOpenAiChatGptOAuthCredential): IOpenAiChatG
185
181
  };
186
182
  };
187
183
 
188
- interface IOpenAiChatGptReadAccess {
189
- accessToken: string;
190
- accountId?: string;
191
- isFedrampAccount: boolean;
192
- }
193
-
194
184
  const toReadAccess = (
195
185
  credentialArg: TOpenAiChatGptReadCredential,
196
- ): IOpenAiChatGptReadAccess => {
186
+ ): plugins.openAi.IOpenAiChatGptReadAccess => {
197
187
  if (!isRecord(credentialArg)) throw createSmartAiProviderError('CREDENTIAL_INVALID');
198
188
  if (credentialArg.kind === 'chatgptOAuth') {
199
189
  const tokenData = toTokenData(credentialArg);
@@ -634,95 +624,6 @@ const projectAccountRateLimits = (
634
624
  };
635
625
  };
636
626
 
637
- const projectCatalog = (valueArg: unknown): ISmartAiProviderModel[] => {
638
- if (!isRecord(valueArg) || !Array.isArray(valueArg.models) || valueArg.models.length > maximumCatalogModels) {
639
- throw createSmartAiProviderError('PROTOCOL_ERROR');
640
- }
641
- const modelIds = new Set<string>();
642
- const entries = valueArg.models.map((rawModel, sourceIndex) => {
643
- if (!isRecord(rawModel)) throw createSmartAiProviderError('PROTOCOL_ERROR');
644
- const modelId = boundedString(rawModel.slug, 256);
645
- if (modelIds.has(modelId)) throw createSmartAiProviderError('PROTOCOL_ERROR');
646
- modelIds.add(modelId);
647
- const visibility = rawModel.visibility;
648
- if (visibility !== 'list' && visibility !== 'hide' && visibility !== 'none') {
649
- throw createSmartAiProviderError('PROTOCOL_ERROR');
650
- }
651
- if (!Number.isSafeInteger(rawModel.priority)) throw createSmartAiProviderError('PROTOCOL_ERROR');
652
- if (!Array.isArray(rawModel.supported_reasoning_levels) || rawModel.supported_reasoning_levels.length > 16) {
653
- throw createSmartAiProviderError('PROTOCOL_ERROR');
654
- }
655
- const reasoningEfforts = rawModel.supported_reasoning_levels.map((rawEffort) => {
656
- if (!isRecord(rawEffort)) throw createSmartAiProviderError('PROTOCOL_ERROR');
657
- return {
658
- effort: boundedString(rawEffort.effort, 128),
659
- description: boundedString(rawEffort.description, 1024, true),
660
- };
661
- });
662
- const modalities = rawModel.input_modalities ?? ['text', 'image'];
663
- if (
664
- !Array.isArray(modalities)
665
- || modalities.length > 3
666
- || modalities.some((entry) => entry !== 'text' && entry !== 'image' && entry !== 'audio')
667
- || new Set(modalities).size !== modalities.length
668
- ) {
669
- throw createSmartAiProviderError('PROTOCOL_ERROR');
670
- }
671
- const rawServiceTiers = rawModel.service_tiers ?? [];
672
- if (!Array.isArray(rawServiceTiers) || rawServiceTiers.length > 16) {
673
- throw createSmartAiProviderError('PROTOCOL_ERROR');
674
- }
675
- const serviceTiers = rawServiceTiers.map((rawTier) => {
676
- if (!isRecord(rawTier)) throw createSmartAiProviderError('PROTOCOL_ERROR');
677
- return {
678
- id: boundedString(rawTier.id, 128),
679
- name: boundedString(rawTier.name, 256),
680
- description: boundedString(rawTier.description, 1024, true),
681
- };
682
- });
683
- const modelMessages = isRecord(rawModel.model_messages) ? rawModel.model_messages : undefined;
684
- const variables = isRecord(modelMessages?.instructions_variables)
685
- ? modelMessages.instructions_variables
686
- : undefined;
687
- const supportsPersonality = typeof modelMessages?.instructions_template === 'string'
688
- && modelMessages.instructions_template.includes('{{ personality }}')
689
- && typeof variables?.personality_default === 'string'
690
- && typeof variables.personality_friendly === 'string'
691
- && typeof variables.personality_pragmatic === 'string';
692
- return {
693
- priority: rawModel.priority as number,
694
- sourceIndex,
695
- model: {
696
- providerId: 'openai' as const,
697
- modelId,
698
- wireModel: modelId,
699
- displayName: boundedString(rawModel.display_name, 512),
700
- description: rawModel.description === null || rawModel.description === undefined
701
- ? ''
702
- : boundedString(rawModel.description, 4096, true),
703
- hidden: visibility !== 'list',
704
- reasoningEfforts,
705
- defaultReasoningEffort: rawModel.default_reasoning_level === null
706
- || rawModel.default_reasoning_level === undefined
707
- ? 'none'
708
- : boundedString(rawModel.default_reasoning_level, 128),
709
- inputModalities: modalities as ISmartAiProviderModel['inputModalities'],
710
- supportsPersonality,
711
- serviceTiers,
712
- ...(rawModel.default_service_tier === null || rawModel.default_service_tier === undefined
713
- ? {}
714
- : { defaultServiceTier: boundedString(rawModel.default_service_tier, 128) }),
715
- isDefault: false,
716
- },
717
- };
718
- });
719
- entries.sort((left, right) => left.priority - right.priority || left.sourceIndex - right.sourceIndex);
720
- const models = entries.map((entry) => entry.model);
721
- const defaultModel = models.find((model) => !model.hidden) ?? models[0];
722
- if (defaultModel) defaultModel.isDefault = true;
723
- return models;
724
- };
725
-
726
627
  export class OpenAiProviderAdapter implements ISmartAiProviderAdapter {
727
628
  public readonly descriptor: ISmartAiProviderDescriptor = {
728
629
  providerId: 'openai',
@@ -995,47 +896,27 @@ export class OpenAiProviderAdapter implements ISmartAiProviderAdapter {
995
896
  }
996
897
 
997
898
  private async fetchCatalog(
998
- accessArg: IOpenAiChatGptReadAccess,
899
+ accessArg: plugins.openAi.IOpenAiChatGptReadAccess,
999
900
  signalArg: AbortSignal,
1000
901
  ): Promise<ISmartAiProviderModel[]> {
1001
- const accountId = accessArg.accountId;
1002
- const url = `${OPENAI_CHATGPT_CODEX_BASE_URL}/models?client_version=${encodeURIComponent(defaultClientVersion)}`;
1003
- let response: Response;
1004
- let onAbort!: () => void;
1005
902
  try {
1006
- const fetchPromise = this.fetchImplementation(url, {
1007
- method: 'GET',
1008
- redirect: 'error',
903
+ return await plugins.openAi.listOpenAiChatGptModels(accessArg, {
1009
904
  signal: signalArg,
1010
- headers: {
1011
- Accept: 'application/json',
1012
- Authorization: `Bearer ${accessArg.accessToken}`,
1013
- ...(accountId ? { 'ChatGPT-Account-ID': accountId } : {}),
1014
- ...(accessArg.isFedrampAccount ? { 'X-OpenAI-Fedramp': 'true' } : {}),
1015
- originator: this.originator,
1016
- version: defaultClientVersion,
1017
- },
905
+ originator: this.originator,
906
+ fetch: this.fetchImplementation,
1018
907
  });
1019
- void fetchPromise.then((lateResponse) => {
1020
- if (signalArg.aborted) void lateResponse.body?.cancel().catch(() => undefined);
1021
- }).catch(() => undefined);
1022
- const aborted = new Promise<never>((_resolve, reject) => {
1023
- onAbort = () => reject(createSmartAiProviderError('ABORTED'));
1024
- signalArg.addEventListener('abort', onAbort, { once: true });
1025
- if (signalArg.aborted) onAbort();
1026
- });
1027
- response = await Promise.race([fetchPromise, aborted]);
1028
- } catch {
908
+ } catch (errorArg) {
1029
909
  if (signalArg.aborted) throw createSmartAiProviderError('ABORTED');
1030
- throw createSmartAiProviderError('NETWORK_FAILED');
1031
- } finally {
1032
- if (onAbort) signalArg.removeEventListener('abort', onAbort);
1033
- }
1034
- if (!response.ok) {
1035
- await response.body?.cancel().catch(() => undefined);
1036
- throw new ModelHttpError(response.status);
910
+ if (errorArg instanceof OpenAiChatGptAuthError && errorArg.status === 401) {
911
+ throw new ModelHttpError(401);
912
+ }
913
+ if (errorArg instanceof plugins.openAi.OpenAiChatGptModelListError) {
914
+ throw errorArg.code === 'HTTP_ERROR'
915
+ ? new ModelHttpError(errorArg.status ?? 0)
916
+ : createSmartAiProviderError(errorArg.code);
917
+ }
918
+ throw errorArg;
1037
919
  }
1038
- return projectCatalog(await readBoundedJson(response, signalArg, maximumCatalogBytes));
1039
920
  }
1040
921
 
1041
922
  private encodeCursor(payloadArg: ICursorPayload): string {
@@ -1141,7 +1022,7 @@ export class OpenAiProviderAdapter implements ISmartAiProviderAdapter {
1141
1022
  }
1142
1023
 
1143
1024
  private async fetchAccountRateLimits(
1144
- accessArg: IOpenAiChatGptReadAccess,
1025
+ accessArg: plugins.openAi.IOpenAiChatGptReadAccess,
1145
1026
  signalArg: AbortSignal,
1146
1027
  ): Promise<ISmartAiProviderAccountRateLimits> {
1147
1028
  const accountId = accessArg.accountId;
@@ -1,5 +1,7 @@
1
1
  export * from './interfaces.js';
2
2
  export * from './smartai.auth.openai.js';
3
3
  export * from './smartai.connection.openai.js';
4
- export * from './smartai.limits.openai.js';
5
- export * from './smartai.middleware.openai.js';
4
+ export {
5
+ classifyOpenAiChatGptLimit,
6
+ createOpenAiChatGptInstructionsMiddleware,
7
+ } from '@modelprofile.com/flexharness-providers/openai';
@@ -70,7 +70,7 @@ export interface IOpenAiChatGptAuthOptions {
70
70
  }
71
71
 
72
72
  /** A failed refresh is replayable only when no request was handed to fetch. */
73
- export type TOpenAiChatGptRequestOutcome = 'notSent' | 'outcomeUnknown';
73
+ export type { TOpenAiChatGptRequestOutcome } from '@modelprofile.com/flexharness-providers/openai';
74
74
 
75
75
  export interface IOpenAiChatGptBrowserAuthorizationOptions extends IOpenAiChatGptAuthOptions {
76
76
  redirectUri: string;
@@ -13,13 +13,22 @@ import type {
13
13
  IOpenAiChatGptTokenData,
14
14
  IOpenAiChatGptTokenInfo,
15
15
  TOpenAiChatGptBrowserCallback,
16
- TOpenAiChatGptRequestOutcome,
17
16
  } from './interfaces.js';
17
+ import {
18
+ OPENAI_CHATGPT_CODEX_BASE_URL,
19
+ OPENAI_CHATGPT_DEFAULT_ORIGINATOR,
20
+ OpenAiChatGptAuthError,
21
+ type TOpenAiChatGptRequestOutcome,
22
+ } from '@modelprofile.com/flexharness-providers/openai';
23
+
24
+ export {
25
+ OPENAI_CHATGPT_CODEX_BASE_URL,
26
+ OPENAI_CHATGPT_DEFAULT_ORIGINATOR,
27
+ OpenAiChatGptAuthError,
28
+ };
18
29
 
19
30
  export const OPENAI_CHATGPT_AUTH_ISSUER = 'https://auth.openai.com';
20
31
  export const OPENAI_CHATGPT_CLIENT_ID = 'app_EMoamEEZ73f0CkXaXp7hrann';
21
- export const OPENAI_CHATGPT_CODEX_BASE_URL = 'https://chatgpt.com/backend-api/codex';
22
- export const OPENAI_CHATGPT_DEFAULT_ORIGINATOR = 'smartai';
23
32
 
24
33
  const DEVICE_CODE_TIMEOUT_MS = 15 * 60 * 1000;
25
34
  const SAFE_MAX_RESPONSE_BYTES = 64 * 1024;
@@ -41,27 +50,6 @@ const usesSafeErrors = (optionsArg: IOpenAiChatGptAuthOptions): boolean =>
41
50
  optionsArg.safeErrors !== false;
42
51
  const utf8ByteLength = (valueArg: string): number => textEncoder.encode(valueArg).byteLength;
43
52
 
44
- export class OpenAiChatGptAuthError extends Error {
45
- public status?: number;
46
- public body?: string;
47
- public requestOutcome?: TOpenAiChatGptRequestOutcome;
48
- public retryAfterMs?: number;
49
-
50
- constructor(message: string, options: {
51
- status?: number;
52
- body?: string;
53
- requestOutcome?: TOpenAiChatGptRequestOutcome;
54
- retryAfterMs?: number;
55
- } = {}) {
56
- super(message);
57
- this.name = 'OpenAiChatGptAuthError';
58
- this.status = options.status;
59
- this.body = options.body;
60
- this.requestOutcome = options.requestOutcome;
61
- this.retryAfterMs = options.retryAfterMs;
62
- }
63
- }
64
-
65
53
  export interface IOpenAiChatGptAuthorizationCode {
66
54
  authorizationCode: string;
67
55
  codeChallenge: string;
@@ -1,4 +1,8 @@
1
- import type { IOpenAiModelConnection } from '@modelprofile.com/flexharness-providers/openai';
1
+ import {
2
+ classifyOpenAiChatGptLimit,
3
+ createOpenAiChatGptInstructionsMiddleware,
4
+ type IOpenAiModelConnection,
5
+ } from '@modelprofile.com/flexharness-providers/openai';
2
6
  import type {
3
7
  IOpenAiChatGptAuthCredentials,
4
8
  IOpenAiChatGptDynamicModelConnectionOptions,
@@ -8,8 +12,6 @@ import {
8
12
  OPENAI_CHATGPT_CODEX_BASE_URL,
9
13
  OpenAiChatGptAuthError,
10
14
  } from './smartai.auth.openai.js';
11
- import { classifyOpenAiChatGptLimit } from './smartai.limits.openai.js';
12
- import { createOpenAiChatGptInstructionsMiddleware } from './smartai.middleware.openai.js';
13
15
 
14
16
  const codexBaseUrl = new URL(OPENAI_CHATGPT_CODEX_BASE_URL);
15
17
 
@@ -7,7 +7,7 @@ export interface IAnthropicModelOptions extends plugins.ISmartAiOptions {
7
7
  promptCaching?: boolean | plugins.ISmartAiCacheOptions;
8
8
  }
9
9
 
10
- export const createAnthropicModelProvider = (): plugins.IModelProvider<IAnthropicModelOptions> => ({
10
+ export const createAnthropicModelProvider = (): plugins.IModelProvider<IAnthropicModelOptions, plugins.LanguageModelV4> => ({
11
11
  id: 'anthropic',
12
12
  getModel: (options) => {
13
13
  const model = plugins.createAnthropic({ apiKey: options.apiKey })(options.model);
@@ -11,5 +11,6 @@ export type {
11
11
  IModelProvider,
12
12
  ISmartAiCacheOptions,
13
13
  ISmartAiOptions,
14
+ LanguageModelV4,
14
15
  TModelLimitClassifier,
15
16
  } from '@modelprofile.com/flexharness-models';
@@ -2,7 +2,7 @@ import * as plugins from './plugins.js';
2
2
 
3
3
  export interface IGoogleModelOptions extends plugins.ISmartAiOptions { provider: 'google'; }
4
4
 
5
- export const createGoogleModelProvider = (): plugins.IModelProvider<IGoogleModelOptions> => ({
5
+ export const createGoogleModelProvider = (): plugins.IModelProvider<IGoogleModelOptions, plugins.LanguageModelV4> => ({
6
6
  id: 'google',
7
7
  getModel: (options) => plugins.createGoogle({ apiKey: options.apiKey })(options.model),
8
8
  });
@@ -1,3 +1,3 @@
1
1
  import { createGoogle } from '@ai-sdk/google';
2
2
  export { createGoogle };
3
- export type { IModelProvider, ISmartAiOptions } from '@modelprofile.com/flexharness-models';
3
+ export type { IModelProvider, ISmartAiOptions, LanguageModelV4 } from '@modelprofile.com/flexharness-models';
@@ -2,7 +2,7 @@ import * as plugins from './plugins.js';
2
2
 
3
3
  export interface IGroqModelOptions extends plugins.ISmartAiOptions { provider: 'groq'; }
4
4
 
5
- export const createGroqModelProvider = (): plugins.IModelProvider<IGroqModelOptions> => ({
5
+ export const createGroqModelProvider = (): plugins.IModelProvider<IGroqModelOptions, plugins.LanguageModelV4> => ({
6
6
  id: 'groq',
7
7
  getModel: (options) => plugins.createGroq({ apiKey: options.apiKey })(options.model),
8
8
  });
@@ -1,3 +1,3 @@
1
1
  import { createGroq } from '@ai-sdk/groq';
2
2
  export { createGroq };
3
- export type { IModelProvider, ISmartAiOptions } from '@modelprofile.com/flexharness-models';
3
+ export type { IModelProvider, ISmartAiOptions, LanguageModelV4 } from '@modelprofile.com/flexharness-models';
@@ -2,7 +2,7 @@ import * as plugins from './plugins.js';
2
2
 
3
3
  export interface IMistralModelOptions extends plugins.ISmartAiOptions { provider: 'mistral'; }
4
4
 
5
- export const createMistralModelProvider = (): plugins.IModelProvider<IMistralModelOptions> => ({
5
+ export const createMistralModelProvider = (): plugins.IModelProvider<IMistralModelOptions, plugins.LanguageModelV4> => ({
6
6
  id: 'mistral',
7
7
  getModel: (options) => plugins.createMistral({ apiKey: options.apiKey })(options.model),
8
8
  });
@@ -1,3 +1,3 @@
1
1
  import { createMistral } from '@ai-sdk/mistral';
2
2
  export { createMistral };
3
- export type { IModelProvider, ISmartAiOptions } from '@modelprofile.com/flexharness-models';
3
+ export type { IModelProvider, ISmartAiOptions, LanguageModelV4 } from '@modelprofile.com/flexharness-models';
@@ -2,6 +2,35 @@ import * as plugins from './plugins.js';
2
2
  import { classifyOpenAiLimit } from './smartai.limits.openai.js';
3
3
 
4
4
  export { classifyOpenAiLimit, readOpenAiError, type IOpenAiErrorDetails } from './smartai.limits.openai.js';
5
+ export { classifyOpenAiChatGptLimit } from './smartai.chatgpt.limits.js';
6
+ export { createOpenAiChatGptInstructionsMiddleware } from './smartai.chatgpt.middleware.js';
7
+ export {
8
+ createOpenAiChatGptAccessHeaders,
9
+ createOpenAiChatGptAccessModelConnection,
10
+ createOpenAiChatGptResolvingModelConnection,
11
+ OPENAI_CHATGPT_CODEX_BASE_URL,
12
+ OPENAI_CHATGPT_DEFAULT_ORIGINATOR,
13
+ OpenAiChatGptAuthError,
14
+ type IOpenAiChatGptAccess,
15
+ type IOpenAiChatGptAccessConnectionOptions,
16
+ type IOpenAiChatGptAccessGrant,
17
+ type IOpenAiChatGptAccessResolveRequest,
18
+ type IOpenAiChatGptReadAccess,
19
+ type IOpenAiChatGptResolvingConnectionOptions,
20
+ type IOpenAiChatGptWorkspaceIdentity,
21
+ type TOpenAiChatGptRequestOutcome,
22
+ } from './smartai.chatgpt.openai.js';
23
+ export {
24
+ listOpenAiChatGptModels,
25
+ OPENAI_CHATGPT_CATALOG_CLIENT_VERSION,
26
+ OpenAiChatGptModelListError,
27
+ type IOpenAiChatGptModel,
28
+ type IOpenAiChatGptModelListOptions,
29
+ type IOpenAiChatGptModelReasoningEffort,
30
+ type IOpenAiChatGptModelServiceTier,
31
+ type TOpenAiChatGptInputModality,
32
+ type TOpenAiChatGptModelListErrorCode,
33
+ } from './smartai.chatgpt.catalog.js';
5
34
 
6
35
  export type TOpenAiReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
7
36
  export type TOpenAiTextVerbosity = 'low' | 'medium' | 'high';
@@ -33,7 +62,7 @@ export interface IOpenAiModelOptions extends plugins.ISmartAiOptions {
33
62
  api?: TOpenAiApi;
34
63
  }
35
64
 
36
- export const createOpenAiModelProvider = (): plugins.IModelProvider<IOpenAiModelOptions> => ({
65
+ export const createOpenAiModelProvider = (): plugins.IModelProvider<IOpenAiModelOptions, plugins.LanguageModelV4> => ({
37
66
  id: 'openai',
38
67
  getModel: (options) => {
39
68
  const api = options.api ?? 'responses';
@@ -6,12 +6,14 @@ export type {
6
6
  OpenAIProviderSettings,
7
7
  OpenAIResponsesProviderOptions,
8
8
  } from '@ai-sdk/openai';
9
- export type { LanguageModelV4Middleware } from '@ai-sdk/provider';
10
- import { createModelLimitMiddleware, readJsonRecord } from '@modelprofile.com/flexharness-models';
11
- export { createModelLimitMiddleware, readJsonRecord };
9
+ export type { LanguageModelV4CallOptions, LanguageModelV4Middleware } from '@ai-sdk/provider';
10
+ import { createModelLimitMiddleware, readEpochSeconds, readJsonRecord } from '@modelprofile.com/flexharness-models';
11
+ export { createModelLimitMiddleware, readEpochSeconds, readJsonRecord };
12
12
  export type {
13
+ IModelCallFailure,
13
14
  IModelProvider,
14
15
  ISmartAiOptions,
15
16
  JSONObject,
17
+ LanguageModelV4,
16
18
  TModelLimitClassifier,
17
19
  } from '@modelprofile.com/flexharness-models';