@modelprofile.com/flexharness-providers 8.0.0 → 8.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.
- package/dist_ts_openai_auth/index.d.ts +1 -3
- package/dist_ts_openai_auth/index.js +2 -7
- package/dist_ts_openai_auth/interfaces.d.ts +24 -0
- package/dist_ts_openai_auth/smartai.connection.openai.d.ts +4 -0
- package/dist_ts_openai_auth/smartai.connection.openai.js +102 -0
- package/dist_ts_providers/openai/index.d.ts +14 -0
- package/dist_ts_providers/openai/index.js +13 -3
- package/dist_ts_providers/openai/plugins.d.ts +1 -1
- package/package.json +2 -2
- package/readme.md +5 -1
- package/ts_openai_auth/index.ts +1 -9
- package/ts_openai_auth/interfaces.ts +30 -0
- package/ts_openai_auth/readme.md +8 -0
- package/ts_openai_auth/smartai.connection.openai.ts +147 -0
- package/ts_providers/openai/index.ts +25 -2
- package/ts_providers/openai/plugins.ts +5 -1
- package/ts_providers/openai/readme.md +35 -0
- package/ts_providers/readme.md +5 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { IOpenAiModelConnection } from '@modelprofile.com/flexharness-providers/openai';
|
|
2
|
-
import type { IOpenAiChatGptAuthCredentials } from './interfaces.js';
|
|
3
1
|
export * from './interfaces.js';
|
|
4
2
|
export * from './smartai.auth.openai.js';
|
|
3
|
+
export * from './smartai.connection.openai.js';
|
|
5
4
|
export * from './smartai.middleware.openai.js';
|
|
6
|
-
export declare const createOpenAiChatGptModelConnection: (credentials: IOpenAiChatGptAuthCredentials) => IOpenAiModelConnection;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { createOpenAiChatGptProviderSettings } from './smartai.auth.openai.js';
|
|
2
|
-
import { createOpenAiChatGptInstructionsMiddleware } from './smartai.middleware.openai.js';
|
|
3
1
|
export * from './interfaces.js';
|
|
4
2
|
export * from './smartai.auth.openai.js';
|
|
3
|
+
export * from './smartai.connection.openai.js';
|
|
5
4
|
export * from './smartai.middleware.openai.js';
|
|
6
|
-
|
|
7
|
-
settings: createOpenAiChatGptProviderSettings(credentials),
|
|
8
|
-
middleware: createOpenAiChatGptInstructionsMiddleware(),
|
|
9
|
-
});
|
|
10
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c19vcGVuYWlfYXV0aC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFFQSxPQUFPLEVBQUUsbUNBQW1DLEVBQUUsTUFBTSwwQkFBMEIsQ0FBQztBQUMvRSxPQUFPLEVBQUUseUNBQXlDLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUMzRixjQUFjLGlCQUFpQixDQUFDO0FBQ2hDLGNBQWMsMEJBQTBCLENBQUM7QUFDekMsY0FBYyxnQ0FBZ0MsQ0FBQztBQUUvQyxNQUFNLENBQUMsTUFBTSxrQ0FBa0MsR0FBRyxDQUFDLFdBQTBDLEVBQTBCLEVBQUUsQ0FBQyxDQUFDO0lBQ3pILFFBQVEsRUFBRSxtQ0FBbUMsQ0FBQyxXQUFXLENBQUM7SUFDMUQsVUFBVSxFQUFFLHlDQUF5QyxFQUFFO0NBQ3hELENBQUMsQ0FBQyJ9
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90c19vcGVuYWlfYXV0aC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGlCQUFpQixDQUFDO0FBQ2hDLGNBQWMsMEJBQTBCLENBQUM7QUFDekMsY0FBYyxnQ0FBZ0MsQ0FBQztBQUMvQyxjQUFjLGdDQUFnQyxDQUFDIn0=
|
|
@@ -17,6 +17,30 @@ export interface IOpenAiChatGptAuthCredentials {
|
|
|
17
17
|
tokenInfo?: IOpenAiChatGptTokenInfo;
|
|
18
18
|
originator?: string;
|
|
19
19
|
}
|
|
20
|
+
export interface IOpenAiChatGptAccessIdentity {
|
|
21
|
+
/** Exact workspace claim expected on every resolved access token. */
|
|
22
|
+
readonly accountId: string | undefined;
|
|
23
|
+
/** Exact residency claim expected on every resolved access token. */
|
|
24
|
+
readonly isFedrampAccount: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface IOpenAiChatGptAccessRequest {
|
|
27
|
+
/** The provider request signal. A resolver should pass it through to its authority. */
|
|
28
|
+
readonly signal: AbortSignal;
|
|
29
|
+
}
|
|
30
|
+
/** Access-only result. Refresh and ID tokens are not part of the request-time contract. */
|
|
31
|
+
export interface IOpenAiChatGptResolvedAccess {
|
|
32
|
+
readonly accessToken: string;
|
|
33
|
+
}
|
|
34
|
+
export interface IOpenAiChatGptDynamicModelConnectionOptions {
|
|
35
|
+
/** Pins the account and residency boundary for the lifetime of the connection. */
|
|
36
|
+
readonly expectedIdentity: IOpenAiChatGptAccessIdentity;
|
|
37
|
+
/** Stable provider originator header. Defaults to `smartai`. */
|
|
38
|
+
readonly originator?: string;
|
|
39
|
+
/** Resolves current access immediately before every provider network request. */
|
|
40
|
+
readonly resolveAccess: (request: IOpenAiChatGptAccessRequest) => Promise<IOpenAiChatGptResolvedAccess>;
|
|
41
|
+
/** Optional underlying transport. Defaults to the current global fetch. */
|
|
42
|
+
readonly fetch?: typeof fetch;
|
|
43
|
+
}
|
|
20
44
|
export interface IOpenAiChatGptTokenData extends IOpenAiChatGptAuthCredentials {
|
|
21
45
|
refreshToken: string;
|
|
22
46
|
tokenInfo: IOpenAiChatGptTokenInfo;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IOpenAiModelConnection } from '@modelprofile.com/flexharness-providers/openai';
|
|
2
|
+
import type { IOpenAiChatGptAuthCredentials, IOpenAiChatGptDynamicModelConnectionOptions } from './interfaces.js';
|
|
3
|
+
export declare const createOpenAiChatGptModelConnection: (credentialsArg: IOpenAiChatGptAuthCredentials) => IOpenAiModelConnection;
|
|
4
|
+
export declare const createOpenAiChatGptDynamicModelConnection: (optionsArg: IOpenAiChatGptDynamicModelConnectionOptions) => IOpenAiModelConnection;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { createOpenAiChatGptProviderSettings, OPENAI_CHATGPT_CODEX_BASE_URL, OpenAiChatGptAuthError, } from './smartai.auth.openai.js';
|
|
2
|
+
import { createOpenAiChatGptInstructionsMiddleware } from './smartai.middleware.openai.js';
|
|
3
|
+
const codexBaseUrl = new URL(OPENAI_CHATGPT_CODEX_BASE_URL);
|
|
4
|
+
function assertCodexRequestUrl(normalizedUrlArg) {
|
|
5
|
+
const url = new URL(normalizedUrlArg);
|
|
6
|
+
const isCodexPath = url.pathname === codexBaseUrl.pathname
|
|
7
|
+
|| url.pathname.startsWith(`${codexBaseUrl.pathname}/`);
|
|
8
|
+
if (url.origin !== codexBaseUrl.origin
|
|
9
|
+
|| url.username !== ''
|
|
10
|
+
|| url.password !== ''
|
|
11
|
+
|| !isCodexPath) {
|
|
12
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT inference URL is outside the Codex endpoint.');
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function requireExpectedIdentity(optionsArg) {
|
|
16
|
+
const expectedIdentity = optionsArg.expectedIdentity;
|
|
17
|
+
if (!expectedIdentity
|
|
18
|
+
|| (expectedIdentity.accountId !== undefined
|
|
19
|
+
&& (typeof expectedIdentity.accountId !== 'string' || expectedIdentity.accountId.length === 0))
|
|
20
|
+
|| typeof expectedIdentity.isFedrampAccount !== 'boolean') {
|
|
21
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT expected access identity is invalid.');
|
|
22
|
+
}
|
|
23
|
+
return Object.freeze({
|
|
24
|
+
accountId: expectedIdentity.accountId,
|
|
25
|
+
isFedrampAccount: expectedIdentity.isFedrampAccount,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
function assertExpectedIdentity(settingsArg, expectedIdentityArg) {
|
|
29
|
+
const accountId = settingsArg.headers['ChatGPT-Account-ID'];
|
|
30
|
+
const isFedrampAccount = settingsArg.headers['X-OpenAI-Fedramp'] === 'true';
|
|
31
|
+
if (accountId !== expectedIdentityArg.accountId
|
|
32
|
+
|| isFedrampAccount !== expectedIdentityArg.isFedrampAccount) {
|
|
33
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT resolved access identity does not match the connection.');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function applyAccessHeaders(headersArg, settingsArg) {
|
|
37
|
+
headersArg.set('Authorization', `Bearer ${settingsArg.apiKey}`);
|
|
38
|
+
headersArg.set('originator', settingsArg.headers.originator);
|
|
39
|
+
for (const name of ['ChatGPT-Account-ID', 'X-OpenAI-Fedramp']) {
|
|
40
|
+
const value = settingsArg.headers[name];
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
headersArg.delete(name);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
headersArg.set(name, value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
export const createOpenAiChatGptModelConnection = (credentialsArg) => ({
|
|
50
|
+
settings: createOpenAiChatGptProviderSettings(credentialsArg),
|
|
51
|
+
middleware: createOpenAiChatGptInstructionsMiddleware(),
|
|
52
|
+
// the ChatGPT Codex backend serves the Responses API only
|
|
53
|
+
apis: ['responses'],
|
|
54
|
+
});
|
|
55
|
+
export const createOpenAiChatGptDynamicModelConnection = (optionsArg) => {
|
|
56
|
+
if (!optionsArg || typeof optionsArg.resolveAccess !== 'function') {
|
|
57
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT access resolver is required.');
|
|
58
|
+
}
|
|
59
|
+
const expectedIdentity = requireExpectedIdentity(optionsArg);
|
|
60
|
+
const resolveAccess = optionsArg.resolveAccess;
|
|
61
|
+
const originator = optionsArg.originator;
|
|
62
|
+
const transport = optionsArg.fetch ?? globalThis.fetch;
|
|
63
|
+
if (typeof transport !== 'function') {
|
|
64
|
+
throw new OpenAiChatGptAuthError('fetch is not available for OpenAI ChatGPT inference.');
|
|
65
|
+
}
|
|
66
|
+
const fetchWithCurrentAccess = async (inputArg, initArg) => {
|
|
67
|
+
const request = new Request(inputArg, {
|
|
68
|
+
...initArg,
|
|
69
|
+
redirect: 'error',
|
|
70
|
+
});
|
|
71
|
+
assertCodexRequestUrl(request.url);
|
|
72
|
+
request.signal.throwIfAborted();
|
|
73
|
+
const access = await resolveAccess({ signal: request.signal });
|
|
74
|
+
request.signal.throwIfAborted();
|
|
75
|
+
const settings = createOpenAiChatGptProviderSettings({
|
|
76
|
+
accessToken: access.accessToken,
|
|
77
|
+
originator,
|
|
78
|
+
});
|
|
79
|
+
if (settings.baseURL !== OPENAI_CHATGPT_CODEX_BASE_URL) {
|
|
80
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT inference endpoint is invalid.');
|
|
81
|
+
}
|
|
82
|
+
assertExpectedIdentity(settings, expectedIdentity);
|
|
83
|
+
const headers = new Headers(request.headers);
|
|
84
|
+
applyAccessHeaders(headers, settings);
|
|
85
|
+
const authenticatedRequest = new Request(request, {
|
|
86
|
+
headers,
|
|
87
|
+
});
|
|
88
|
+
authenticatedRequest.signal.throwIfAborted();
|
|
89
|
+
return transport(authenticatedRequest);
|
|
90
|
+
};
|
|
91
|
+
return {
|
|
92
|
+
settings: {
|
|
93
|
+
apiKey: '',
|
|
94
|
+
baseURL: OPENAI_CHATGPT_CODEX_BASE_URL,
|
|
95
|
+
fetch: fetchWithCurrentAccess,
|
|
96
|
+
},
|
|
97
|
+
middleware: createOpenAiChatGptInstructionsMiddleware(),
|
|
98
|
+
// the ChatGPT Codex backend serves the Responses API only
|
|
99
|
+
apis: ['responses'],
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRhaS5j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QUFJLHNCQUFzQixDQUFDLCtDQUErQyxDQUFDLENBQUM7UUFDcEYsQ0FBQztRQUNELHNCQUFzQixDQUFDLFFBQVEsRUFBRSxnQkFBZ0IsQ0FBQyxDQUFDO1FBRW5ELE1BQU0sT0FBTyxHQUFHLElBQUksT0FBTyxDQUFDLE9BQU8sQ0FBQyxPQUFPLENBQUMsQ0FBQztRQUM3QyxrQkFBa0IsQ0FBQyxPQUFPLEVBQUUsUUFBUSxDQUFDLENBQUM7UUFDdEMsTUFBTSxvQkFBb0IsR0FBRyxJQUFJLE9BQU8sQ0FBQyxPQUFPLEVBQUU7WUFDaEQsT0FBTztTQUNSLENBQUMsQ0FBQztRQUNILG9CQUFvQixDQUFDLE1BQU0sQ0FBQyxjQUFjLEVBQUUsQ0FBQztRQUM3QyxPQUFPLFNBQVMsQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDO0lBQ3pDLENBQUMsQ0FBQztJQUVGLE9BQU87UUFDTCxRQUFRLEVBQUU7WUFDUixNQUFNLEVBQUUsRUFBRTtZQUNWLE9BQU8sRUFBRSw2QkFBNkI7WUFDdEMsS0FBSyxFQUFFLHNCQUFzQjtTQUM5QjtRQUNELFVBQVUsRUFBRSx5Q0FBeUMsRUFBRTtRQUN2RCwwREFBMEQ7UUFDMUQsSUFBSSxFQUFFLENBQUMsV0FBVyxDQUFDO0tBQ3BCLENBQUM7QUFDSixDQUFDLENBQUMifQ==
|
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import * as plugins from './plugins.js';
|
|
2
2
|
export type TOpenAiReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
3
3
|
export type TOpenAiTextVerbosity = 'low' | 'medium' | 'high';
|
|
4
|
+
/** `responses` calls `/responses`; `chat` calls `/chat/completions`, the API most OpenAI-compatible servers implement. */
|
|
5
|
+
export type TOpenAiApi = 'responses' | 'chat';
|
|
6
|
+
/** Provider options of the Responses API (`api: 'responses'`, the default). */
|
|
4
7
|
export interface IOpenAiProviderOptions extends plugins.JSONObject, plugins.OpenAIResponsesProviderOptions {
|
|
5
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Provider options of the Chat Completions API (`api: 'chat'`). Responses-only options such as
|
|
11
|
+
* `reasoningSummary`, `previousResponseId`, `include`, `instructions` or `truncation` do not apply
|
|
12
|
+
* to it; the chat model ignores them.
|
|
13
|
+
*/
|
|
14
|
+
export interface IOpenAiChatProviderOptions extends plugins.JSONObject, plugins.OpenAIChatProviderOptions {
|
|
15
|
+
}
|
|
6
16
|
/** The provider owns inference; optional authentication components supply this connection. */
|
|
7
17
|
export interface IOpenAiModelConnection {
|
|
8
18
|
settings: plugins.OpenAIProviderSettings;
|
|
9
19
|
middleware?: plugins.LanguageModelV4Middleware;
|
|
20
|
+
/** The OpenAI APIs this connection serves. Unset means every API; a model asking for another one is refused. */
|
|
21
|
+
apis?: readonly TOpenAiApi[];
|
|
10
22
|
}
|
|
11
23
|
export interface IOpenAiModelOptions extends plugins.ISmartAiOptions {
|
|
12
24
|
provider: 'openai';
|
|
13
25
|
connection?: IOpenAiModelConnection;
|
|
26
|
+
/** The API the model calls. Defaults to `responses`. */
|
|
27
|
+
api?: TOpenAiApi;
|
|
14
28
|
}
|
|
15
29
|
export declare const createOpenAiModelProvider: () => plugins.IModelProvider<IOpenAiModelOptions>;
|
|
@@ -2,13 +2,23 @@ import * as plugins from './plugins.js';
|
|
|
2
2
|
export const createOpenAiModelProvider = () => ({
|
|
3
3
|
id: 'openai',
|
|
4
4
|
getModel: (options) => {
|
|
5
|
-
const
|
|
5
|
+
const api = options.api ?? 'responses';
|
|
6
|
+
if (api !== 'responses' && api !== 'chat') {
|
|
7
|
+
throw new Error(`Unknown OpenAI API "${String(api)}"; use "responses" or "chat".`);
|
|
8
|
+
}
|
|
9
|
+
const servedApis = options.connection?.apis;
|
|
10
|
+
if (servedApis && !servedApis.includes(api)) {
|
|
11
|
+
const served = servedApis.map((entry) => `"${entry}"`).join(', ');
|
|
12
|
+
throw new Error(`This connection serves only the ${served} API; api "${api}" cannot be used with it.`);
|
|
13
|
+
}
|
|
14
|
+
const openai = plugins.createOpenAI(options.connection?.settings ?? {
|
|
6
15
|
apiKey: options.apiKey,
|
|
7
16
|
...(options.baseUrl ? { baseURL: options.baseUrl } : {}),
|
|
8
|
-
})
|
|
17
|
+
});
|
|
18
|
+
const model = api === 'chat' ? openai.chat(options.model) : openai(options.model);
|
|
9
19
|
return options.connection?.middleware
|
|
10
20
|
? plugins.wrapLanguageModel({ model, middleware: options.connection.middleware })
|
|
11
21
|
: model;
|
|
12
22
|
},
|
|
13
23
|
});
|
|
14
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
24
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi90c19wcm92aWRlcnMvb3BlbmFpL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxPQUFPLE1BQU0sY0FBYyxDQUFDO0FBOEJ4QyxNQUFNLENBQUMsTUFBTSx5QkFBeUIsR0FBRyxHQUFnRCxFQUFFLENBQUMsQ0FBQztJQUMzRixFQUFFLEVBQUUsUUFBUTtJQUNaLFFBQVEsRUFBRSxDQUFDLE9BQU8sRUFBRSxFQUFFO1FBQ3BCLE1BQU0sR0FBRyxHQUFHLE9BQU8sQ0FBQyxHQUFHLElBQUksV0FBVyxDQUFDO1FBQ3ZDLElBQUksR0FBRyxLQUFLLFdBQVcsSUFBSSxHQUFHLEtBQUssTUFBTSxFQUFFLENBQUM7WUFDMUMsTUFBTSxJQUFJLEtBQUssQ0FBQyx1QkFBdUIsTUFBTSxDQUFDLEdBQUcsQ0FBQywrQkFBK0IsQ0FBQyxDQUFDO1FBQ3JGLENBQUM7UUFDRCxNQUFNLFVBQVUsR0FBRyxPQUFPLENBQUMsVUFBVSxFQUFFL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yxLQUFLLENBQUM7SUFDWixDQUFDO0NBQ0YsQ0FBQyxDQUFDIn0=
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
2
|
import { wrapLanguageModel } from 'ai';
|
|
3
3
|
export { createOpenAI, wrapLanguageModel };
|
|
4
|
-
export type { OpenAIProviderSettings, OpenAIResponsesProviderOptions } from '@ai-sdk/openai';
|
|
4
|
+
export type { OpenAIChatLanguageModelOptions as OpenAIChatProviderOptions, OpenAIProviderSettings, OpenAIResponsesProviderOptions, } from '@ai-sdk/openai';
|
|
5
5
|
export type { LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
6
6
|
export type { IModelProvider, ISmartAiOptions, JSONObject } from '@modelprofile.com/flexharness-models';
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Task Venture Capital GmbH",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "@modelprofile.com/flexharness-providers",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.2.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"description": "Model providers, authentication, account management, media and research integrations in one package.",
|
|
8
8
|
"main": "./dist_ts_providers/index.js",
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@ai-sdk/provider": "^4.0.8",
|
|
76
76
|
"@ai-sdk/xai": "^4.0.44",
|
|
77
77
|
"@anthropic-ai/sdk": "0.95.2",
|
|
78
|
-
"@modelprofile.com/flexharness-models": "8.
|
|
78
|
+
"@modelprofile.com/flexharness-models": "8.2.0",
|
|
79
79
|
"ai": "^7.0.79",
|
|
80
80
|
"openai": "^6.37.0",
|
|
81
81
|
"proper-lockfile": "^4.1.2"
|
package/readme.md
CHANGED
|
@@ -36,7 +36,11 @@ Provider SDKs are installed together. Authentication, file access and vendor med
|
|
|
36
36
|
are separate entrypoints and are not imported by the provider factory root. For
|
|
37
37
|
ChatGPT authentication, pass
|
|
38
38
|
`connection: createOpenAiChatGptModelConnection(credentials)` from `/auth` to the
|
|
39
|
-
OpenAI model options.
|
|
39
|
+
OpenAI model options. Delegated runtimes use
|
|
40
|
+
`createOpenAiChatGptDynamicModelConnection({ expectedIdentity, resolveAccess })`
|
|
41
|
+
instead; it resolves current access at every provider HTTP request while keeping
|
|
42
|
+
account and residency identity fixed for the connection. API-key inference
|
|
43
|
+
needs no authentication setup.
|
|
40
44
|
|
|
41
45
|
The package includes the applicable OpenAI Codex license and third-party notices.
|
|
42
46
|
|
package/ts_openai_auth/index.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
import type { IOpenAiModelConnection } from '@modelprofile.com/flexharness-providers/openai';
|
|
2
|
-
import type { IOpenAiChatGptAuthCredentials } from './interfaces.js';
|
|
3
|
-
import { createOpenAiChatGptProviderSettings } from './smartai.auth.openai.js';
|
|
4
|
-
import { createOpenAiChatGptInstructionsMiddleware } from './smartai.middleware.openai.js';
|
|
5
1
|
export * from './interfaces.js';
|
|
6
2
|
export * from './smartai.auth.openai.js';
|
|
3
|
+
export * from './smartai.connection.openai.js';
|
|
7
4
|
export * from './smartai.middleware.openai.js';
|
|
8
|
-
|
|
9
|
-
export const createOpenAiChatGptModelConnection = (credentials: IOpenAiChatGptAuthCredentials): IOpenAiModelConnection => ({
|
|
10
|
-
settings: createOpenAiChatGptProviderSettings(credentials),
|
|
11
|
-
middleware: createOpenAiChatGptInstructionsMiddleware(),
|
|
12
|
-
});
|
|
@@ -19,6 +19,36 @@ export interface IOpenAiChatGptAuthCredentials {
|
|
|
19
19
|
originator?: string;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export interface IOpenAiChatGptAccessIdentity {
|
|
23
|
+
/** Exact workspace claim expected on every resolved access token. */
|
|
24
|
+
readonly accountId: string | undefined;
|
|
25
|
+
/** Exact residency claim expected on every resolved access token. */
|
|
26
|
+
readonly isFedrampAccount: boolean;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface IOpenAiChatGptAccessRequest {
|
|
30
|
+
/** The provider request signal. A resolver should pass it through to its authority. */
|
|
31
|
+
readonly signal: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Access-only result. Refresh and ID tokens are not part of the request-time contract. */
|
|
35
|
+
export interface IOpenAiChatGptResolvedAccess {
|
|
36
|
+
readonly accessToken: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface IOpenAiChatGptDynamicModelConnectionOptions {
|
|
40
|
+
/** Pins the account and residency boundary for the lifetime of the connection. */
|
|
41
|
+
readonly expectedIdentity: IOpenAiChatGptAccessIdentity;
|
|
42
|
+
/** Stable provider originator header. Defaults to `smartai`. */
|
|
43
|
+
readonly originator?: string;
|
|
44
|
+
/** Resolves current access immediately before every provider network request. */
|
|
45
|
+
readonly resolveAccess: (
|
|
46
|
+
request: IOpenAiChatGptAccessRequest,
|
|
47
|
+
) => Promise<IOpenAiChatGptResolvedAccess>;
|
|
48
|
+
/** Optional underlying transport. Defaults to the current global fetch. */
|
|
49
|
+
readonly fetch?: typeof fetch;
|
|
50
|
+
}
|
|
51
|
+
|
|
22
52
|
export interface IOpenAiChatGptTokenData extends IOpenAiChatGptAuthCredentials {
|
|
23
53
|
refreshToken: string;
|
|
24
54
|
tokenInfo: IOpenAiChatGptTokenInfo;
|
package/ts_openai_auth/readme.md
CHANGED
|
@@ -23,6 +23,14 @@ the current access token. The token must contain an unexpired `exp` claim;
|
|
|
23
23
|
supplied `accountId`, `isFedrampAccount`, and `tokenInfo` must agree with its
|
|
24
24
|
claims. A saved ID-token snapshot cannot override current access-token facts.
|
|
25
25
|
|
|
26
|
+
Use `createOpenAiChatGptDynamicModelConnection()` for delegated access owned by
|
|
27
|
+
an external authority. Pin its exact account and FedRAMP identity, then provide
|
|
28
|
+
an async `resolveAccess({ signal })` callback. The connection resolves and
|
|
29
|
+
validates current access immediately before every provider HTTP request, so
|
|
30
|
+
multi-step tool runs do not retain the token that admitted the run. Resolution,
|
|
31
|
+
identity, expiry, endpoint, redirect, and abort failures stop before the
|
|
32
|
+
underlying transport is called.
|
|
33
|
+
|
|
26
34
|
## Issue Reporting and Security
|
|
27
35
|
|
|
28
36
|
Report issues and security concerns through [community.foss.global](https://community.foss.global).
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import type { IOpenAiModelConnection } from '@modelprofile.com/flexharness-providers/openai';
|
|
2
|
+
import type {
|
|
3
|
+
IOpenAiChatGptAuthCredentials,
|
|
4
|
+
IOpenAiChatGptDynamicModelConnectionOptions,
|
|
5
|
+
} from './interfaces.js';
|
|
6
|
+
import {
|
|
7
|
+
createOpenAiChatGptProviderSettings,
|
|
8
|
+
OPENAI_CHATGPT_CODEX_BASE_URL,
|
|
9
|
+
OpenAiChatGptAuthError,
|
|
10
|
+
} from './smartai.auth.openai.js';
|
|
11
|
+
import { createOpenAiChatGptInstructionsMiddleware } from './smartai.middleware.openai.js';
|
|
12
|
+
|
|
13
|
+
const codexBaseUrl = new URL(OPENAI_CHATGPT_CODEX_BASE_URL);
|
|
14
|
+
|
|
15
|
+
function assertCodexRequestUrl(normalizedUrlArg: string): void {
|
|
16
|
+
const url = new URL(normalizedUrlArg);
|
|
17
|
+
const isCodexPath = url.pathname === codexBaseUrl.pathname
|
|
18
|
+
|| url.pathname.startsWith(`${codexBaseUrl.pathname}/`);
|
|
19
|
+
if (
|
|
20
|
+
url.origin !== codexBaseUrl.origin
|
|
21
|
+
|| url.username !== ''
|
|
22
|
+
|| url.password !== ''
|
|
23
|
+
|| !isCodexPath
|
|
24
|
+
) {
|
|
25
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT inference URL is outside the Codex endpoint.');
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function requireExpectedIdentity(optionsArg: IOpenAiChatGptDynamicModelConnectionOptions): {
|
|
30
|
+
accountId: string | undefined;
|
|
31
|
+
isFedrampAccount: boolean;
|
|
32
|
+
} {
|
|
33
|
+
const expectedIdentity = optionsArg.expectedIdentity;
|
|
34
|
+
if (
|
|
35
|
+
!expectedIdentity
|
|
36
|
+
|| (
|
|
37
|
+
expectedIdentity.accountId !== undefined
|
|
38
|
+
&& (typeof expectedIdentity.accountId !== 'string' || expectedIdentity.accountId.length === 0)
|
|
39
|
+
)
|
|
40
|
+
|| typeof expectedIdentity.isFedrampAccount !== 'boolean'
|
|
41
|
+
) {
|
|
42
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT expected access identity is invalid.');
|
|
43
|
+
}
|
|
44
|
+
return Object.freeze({
|
|
45
|
+
accountId: expectedIdentity.accountId,
|
|
46
|
+
isFedrampAccount: expectedIdentity.isFedrampAccount,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function assertExpectedIdentity(
|
|
51
|
+
settingsArg: ReturnType<typeof createOpenAiChatGptProviderSettings>,
|
|
52
|
+
expectedIdentityArg: Readonly<{
|
|
53
|
+
accountId: string | undefined;
|
|
54
|
+
isFedrampAccount: boolean;
|
|
55
|
+
}>,
|
|
56
|
+
): void {
|
|
57
|
+
const accountId = settingsArg.headers['ChatGPT-Account-ID'];
|
|
58
|
+
const isFedrampAccount = settingsArg.headers['X-OpenAI-Fedramp'] === 'true';
|
|
59
|
+
if (
|
|
60
|
+
accountId !== expectedIdentityArg.accountId
|
|
61
|
+
|| isFedrampAccount !== expectedIdentityArg.isFedrampAccount
|
|
62
|
+
) {
|
|
63
|
+
throw new OpenAiChatGptAuthError(
|
|
64
|
+
'OpenAI ChatGPT resolved access identity does not match the connection.',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function applyAccessHeaders(
|
|
70
|
+
headersArg: Headers,
|
|
71
|
+
settingsArg: ReturnType<typeof createOpenAiChatGptProviderSettings>,
|
|
72
|
+
): void {
|
|
73
|
+
headersArg.set('Authorization', `Bearer ${settingsArg.apiKey}`);
|
|
74
|
+
headersArg.set('originator', settingsArg.headers.originator);
|
|
75
|
+
|
|
76
|
+
for (const name of ['ChatGPT-Account-ID', 'X-OpenAI-Fedramp']) {
|
|
77
|
+
const value = settingsArg.headers[name];
|
|
78
|
+
if (value === undefined) {
|
|
79
|
+
headersArg.delete(name);
|
|
80
|
+
} else {
|
|
81
|
+
headersArg.set(name, value);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export const createOpenAiChatGptModelConnection = (
|
|
87
|
+
credentialsArg: IOpenAiChatGptAuthCredentials,
|
|
88
|
+
): IOpenAiModelConnection => ({
|
|
89
|
+
settings: createOpenAiChatGptProviderSettings(credentialsArg),
|
|
90
|
+
middleware: createOpenAiChatGptInstructionsMiddleware(),
|
|
91
|
+
// the ChatGPT Codex backend serves the Responses API only
|
|
92
|
+
apis: ['responses'],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const createOpenAiChatGptDynamicModelConnection = (
|
|
96
|
+
optionsArg: IOpenAiChatGptDynamicModelConnectionOptions,
|
|
97
|
+
): IOpenAiModelConnection => {
|
|
98
|
+
if (!optionsArg || typeof optionsArg.resolveAccess !== 'function') {
|
|
99
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT access resolver is required.');
|
|
100
|
+
}
|
|
101
|
+
const expectedIdentity = requireExpectedIdentity(optionsArg);
|
|
102
|
+
const resolveAccess = optionsArg.resolveAccess;
|
|
103
|
+
const originator = optionsArg.originator;
|
|
104
|
+
const transport = optionsArg.fetch ?? globalThis.fetch;
|
|
105
|
+
if (typeof transport !== 'function') {
|
|
106
|
+
throw new OpenAiChatGptAuthError('fetch is not available for OpenAI ChatGPT inference.');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const fetchWithCurrentAccess: typeof fetch = async (inputArg, initArg) => {
|
|
110
|
+
const request = new Request(inputArg, {
|
|
111
|
+
...initArg,
|
|
112
|
+
redirect: 'error',
|
|
113
|
+
});
|
|
114
|
+
assertCodexRequestUrl(request.url);
|
|
115
|
+
request.signal.throwIfAborted();
|
|
116
|
+
|
|
117
|
+
const access = await resolveAccess({ signal: request.signal });
|
|
118
|
+
request.signal.throwIfAborted();
|
|
119
|
+
const settings = createOpenAiChatGptProviderSettings({
|
|
120
|
+
accessToken: access.accessToken,
|
|
121
|
+
originator,
|
|
122
|
+
});
|
|
123
|
+
if (settings.baseURL !== OPENAI_CHATGPT_CODEX_BASE_URL) {
|
|
124
|
+
throw new OpenAiChatGptAuthError('OpenAI ChatGPT inference endpoint is invalid.');
|
|
125
|
+
}
|
|
126
|
+
assertExpectedIdentity(settings, expectedIdentity);
|
|
127
|
+
|
|
128
|
+
const headers = new Headers(request.headers);
|
|
129
|
+
applyAccessHeaders(headers, settings);
|
|
130
|
+
const authenticatedRequest = new Request(request, {
|
|
131
|
+
headers,
|
|
132
|
+
});
|
|
133
|
+
authenticatedRequest.signal.throwIfAborted();
|
|
134
|
+
return transport(authenticatedRequest);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
settings: {
|
|
139
|
+
apiKey: '',
|
|
140
|
+
baseURL: OPENAI_CHATGPT_CODEX_BASE_URL,
|
|
141
|
+
fetch: fetchWithCurrentAccess,
|
|
142
|
+
},
|
|
143
|
+
middleware: createOpenAiChatGptInstructionsMiddleware(),
|
|
144
|
+
// the ChatGPT Codex backend serves the Responses API only
|
|
145
|
+
apis: ['responses'],
|
|
146
|
+
};
|
|
147
|
+
};
|
|
@@ -2,26 +2,49 @@ import * as plugins from './plugins.js';
|
|
|
2
2
|
|
|
3
3
|
export type TOpenAiReasoningEffort = 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
4
4
|
export type TOpenAiTextVerbosity = 'low' | 'medium' | 'high';
|
|
5
|
+
/** `responses` calls `/responses`; `chat` calls `/chat/completions`, the API most OpenAI-compatible servers implement. */
|
|
6
|
+
export type TOpenAiApi = 'responses' | 'chat';
|
|
7
|
+
/** Provider options of the Responses API (`api: 'responses'`, the default). */
|
|
5
8
|
export interface IOpenAiProviderOptions extends plugins.JSONObject, plugins.OpenAIResponsesProviderOptions {}
|
|
9
|
+
/**
|
|
10
|
+
* Provider options of the Chat Completions API (`api: 'chat'`). Responses-only options such as
|
|
11
|
+
* `reasoningSummary`, `previousResponseId`, `include`, `instructions` or `truncation` do not apply
|
|
12
|
+
* to it; the chat model ignores them.
|
|
13
|
+
*/
|
|
14
|
+
export interface IOpenAiChatProviderOptions extends plugins.JSONObject, plugins.OpenAIChatProviderOptions {}
|
|
6
15
|
|
|
7
16
|
/** The provider owns inference; optional authentication components supply this connection. */
|
|
8
17
|
export interface IOpenAiModelConnection {
|
|
9
18
|
settings: plugins.OpenAIProviderSettings;
|
|
10
19
|
middleware?: plugins.LanguageModelV4Middleware;
|
|
20
|
+
/** The OpenAI APIs this connection serves. Unset means every API; a model asking for another one is refused. */
|
|
21
|
+
apis?: readonly TOpenAiApi[];
|
|
11
22
|
}
|
|
12
23
|
|
|
13
24
|
export interface IOpenAiModelOptions extends plugins.ISmartAiOptions {
|
|
14
25
|
provider: 'openai';
|
|
15
26
|
connection?: IOpenAiModelConnection;
|
|
27
|
+
/** The API the model calls. Defaults to `responses`. */
|
|
28
|
+
api?: TOpenAiApi;
|
|
16
29
|
}
|
|
17
30
|
|
|
18
31
|
export const createOpenAiModelProvider = (): plugins.IModelProvider<IOpenAiModelOptions> => ({
|
|
19
32
|
id: 'openai',
|
|
20
33
|
getModel: (options) => {
|
|
21
|
-
const
|
|
34
|
+
const api = options.api ?? 'responses';
|
|
35
|
+
if (api !== 'responses' && api !== 'chat') {
|
|
36
|
+
throw new Error(`Unknown OpenAI API "${String(api)}"; use "responses" or "chat".`);
|
|
37
|
+
}
|
|
38
|
+
const servedApis = options.connection?.apis;
|
|
39
|
+
if (servedApis && !servedApis.includes(api)) {
|
|
40
|
+
const served = servedApis.map((entry) => `"${entry}"`).join(', ');
|
|
41
|
+
throw new Error(`This connection serves only the ${served} API; api "${api}" cannot be used with it.`);
|
|
42
|
+
}
|
|
43
|
+
const openai = plugins.createOpenAI(options.connection?.settings ?? {
|
|
22
44
|
apiKey: options.apiKey,
|
|
23
45
|
...(options.baseUrl ? { baseURL: options.baseUrl } : {}),
|
|
24
|
-
})
|
|
46
|
+
});
|
|
47
|
+
const model = api === 'chat' ? openai.chat(options.model) : openai(options.model);
|
|
25
48
|
return options.connection?.middleware
|
|
26
49
|
? plugins.wrapLanguageModel({ model, middleware: options.connection.middleware })
|
|
27
50
|
: model;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { createOpenAI } from '@ai-sdk/openai';
|
|
2
2
|
import { wrapLanguageModel } from 'ai';
|
|
3
3
|
export { createOpenAI, wrapLanguageModel };
|
|
4
|
-
export type {
|
|
4
|
+
export type {
|
|
5
|
+
OpenAIChatLanguageModelOptions as OpenAIChatProviderOptions,
|
|
6
|
+
OpenAIProviderSettings,
|
|
7
|
+
OpenAIResponsesProviderOptions,
|
|
8
|
+
} from '@ai-sdk/openai';
|
|
5
9
|
export type { LanguageModelV4Middleware } from '@ai-sdk/provider';
|
|
6
10
|
export type { IModelProvider, ISmartAiOptions, JSONObject } from '@modelprofile.com/flexharness-models';
|
|
@@ -11,6 +11,41 @@ pnpm add @modelprofile.com/flexharness-providers
|
|
|
11
11
|
See the [toolbox usage and migration guide](https://code.foss.global/modelprofile.com/flexharness#readme)
|
|
12
12
|
for composition examples and the SmartAI/SmartAgent migration map.
|
|
13
13
|
|
|
14
|
+
`createOpenAiModelProvider()` calls the Responses API at `https://api.openai.com/v1` by
|
|
15
|
+
default. `baseUrl` points it at another endpoint, for example `https://eu.api.openai.com/v1`
|
|
16
|
+
for OpenAI's European data residency. `api: 'chat'` calls `/chat/completions` instead of
|
|
17
|
+
`/responses`: most OpenAI-compatible servers implement only Chat Completions, so use it with
|
|
18
|
+
their base URL and key.
|
|
19
|
+
|
|
20
|
+
`api` applies to a supplied `connection` too; a connection that declares the APIs it serves refuses any other.
|
|
21
|
+
The ChatGPT connections from the `/auth` subpath serve the Responses API only (the Codex backend
|
|
22
|
+
has no Chat Completions endpoint), so asking one of them for `api: 'chat'` is refused when the
|
|
23
|
+
model is constructed.
|
|
24
|
+
|
|
25
|
+
Provider options differ per API. `IOpenAiProviderOptions` types the Responses options;
|
|
26
|
+
`IOpenAiChatProviderOptions` types the Chat Completions options. Responses-only options such as
|
|
27
|
+
`reasoningSummary`, `previousResponseId`, `include`, `instructions` and `truncation` do not apply
|
|
28
|
+
to `chat`: the chat model ignores them.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { ModelRegistry } from '@modelprofile.com/flexharness-models';
|
|
32
|
+
import { createOpenAiModelProvider } from '@modelprofile.com/flexharness-providers/openai';
|
|
33
|
+
|
|
34
|
+
const models = new ModelRegistry().register(createOpenAiModelProvider());
|
|
35
|
+
const model = models.getModel({
|
|
36
|
+
provider: 'openai',
|
|
37
|
+
model: 'served-model-name',
|
|
38
|
+
apiKey,
|
|
39
|
+
baseUrl: 'https://models.example.com/v1',
|
|
40
|
+
api: 'chat',
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
ChatGPT connections come from the `/auth` subpath. Use the dynamic connection
|
|
45
|
+
factory for delegated authority access so every provider HTTP request resolves
|
|
46
|
+
a current token while the connection retains its pinned account and residency
|
|
47
|
+
identity.
|
|
48
|
+
|
|
14
49
|
## Issue Reporting and Security
|
|
15
50
|
|
|
16
51
|
Report issues and security concerns through [community.foss.global](https://community.foss.global).
|
package/ts_providers/readme.md
CHANGED
|
@@ -36,7 +36,11 @@ Provider SDKs are installed together. Authentication, file access and vendor med
|
|
|
36
36
|
are separate entrypoints and are not imported by the provider factory root. For
|
|
37
37
|
ChatGPT authentication, pass
|
|
38
38
|
`connection: createOpenAiChatGptModelConnection(credentials)` from `/auth` to the
|
|
39
|
-
OpenAI model options.
|
|
39
|
+
OpenAI model options. Delegated runtimes use
|
|
40
|
+
`createOpenAiChatGptDynamicModelConnection({ expectedIdentity, resolveAccess })`
|
|
41
|
+
instead; it resolves current access at every provider HTTP request while keeping
|
|
42
|
+
account and residency identity fixed for the connection. API-key inference
|
|
43
|
+
needs no authentication setup.
|
|
40
44
|
|
|
41
45
|
The package includes the applicable OpenAI Codex license and third-party notices.
|
|
42
46
|
|