@astro-minimax/ai 0.2.0 → 0.5.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 +21 -0
- package/dist/provider-manager/openai.d.ts.map +1 -1
- package/dist/provider-manager/openai.js +40 -11
- package/dist/server/dev-server.js +0 -0
- package/package.json +36 -13
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Souloss
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/provider-manager/openai.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../src/provider-manager/openai.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC5F,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAgDhD,qBAAa,aAAc,SAAQ,mBAAmB;IACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,IAAI,EAAG,QAAQ,CAAU;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB,OAAO,CAAC,QAAQ,CAA4C;IAC5D,OAAO,CAAC,MAAM,CAAuB;gBAEzB,MAAM,EAAE,oBAAoB;IAuBlC,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAyCvE,SAAS,IAAI,oBAAoB;IAIjC,WAAW,IAAI;QAAE,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAA;KAAE;CAGzD"}
|
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
|
|
2
2
|
import { streamText, convertToModelMessages } from 'ai';
|
|
3
|
-
import { ProxyAgent, fetch as undiciFetch } from 'undici';
|
|
4
3
|
import { BaseProviderAdapter } from './base.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (
|
|
8
|
-
return
|
|
9
|
-
|
|
10
|
-
//
|
|
11
|
-
|
|
4
|
+
let proxyInitialized = false;
|
|
5
|
+
async function setupGlobalProxy() {
|
|
6
|
+
if (proxyInitialized)
|
|
7
|
+
return;
|
|
8
|
+
// Check if running in a Node.js-like environment with proxy configured
|
|
9
|
+
// In Cloudflare Edge Runtime with nodejs_compat, process exists but undici APIs don't work
|
|
10
|
+
if (typeof process === 'undefined' || !process.env) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const proxyUrl = process.env.https_proxy || process.env.HTTPS_PROXY ||
|
|
14
|
+
process.env.http_proxy || process.env.HTTP_PROXY;
|
|
15
|
+
if (!proxyUrl) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
// Dynamic import - will fail or return stubs in Cloudflare Edge Runtime
|
|
20
|
+
const undici = await import('undici');
|
|
21
|
+
// Verify the APIs actually exist (they won't in Edge Runtime polyfills)
|
|
22
|
+
if (typeof undici.setGlobalDispatcher !== 'function' ||
|
|
23
|
+
typeof undici.ProxyAgent !== 'function') {
|
|
24
|
+
console.log('[OpenAIAdapter] undici APIs not available, skipping proxy setup (likely Edge Runtime)');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
undici.setGlobalDispatcher(new undici.ProxyAgent(proxyUrl));
|
|
28
|
+
console.log('[OpenAIAdapter] Global proxy dispatcher set:', proxyUrl);
|
|
29
|
+
proxyInitialized = true;
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
// Expected in Cloudflare Edge Runtime - undici import may fail or APIs may not exist
|
|
33
|
+
console.log('[OpenAIAdapter] Proxy setup skipped:', e instanceof Error ? e.message : String(e));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
let proxySetupPromise = null;
|
|
37
|
+
function ensureProxySetup() {
|
|
38
|
+
if (!proxySetupPromise) {
|
|
39
|
+
proxySetupPromise = setupGlobalProxy();
|
|
40
|
+
}
|
|
41
|
+
return proxySetupPromise;
|
|
12
42
|
}
|
|
13
43
|
export class OpenAIAdapter extends BaseProviderAdapter {
|
|
14
44
|
id;
|
|
@@ -31,17 +61,16 @@ export class OpenAIAdapter extends BaseProviderAdapter {
|
|
|
31
61
|
this.evidenceModel = config.evidenceModel ?? this.keywordModel;
|
|
32
62
|
this.timeout = config.timeout ?? 30000;
|
|
33
63
|
this.config = config;
|
|
34
|
-
const proxyFetch = createProxyFetch();
|
|
35
64
|
this.provider = createOpenAICompatible({
|
|
36
65
|
name: `openai-${config.id}`,
|
|
37
66
|
baseURL: config.baseURL,
|
|
38
67
|
apiKey: config.apiKey,
|
|
39
68
|
includeUsage: true,
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
...(proxyFetch && { fetch: proxyFetch }),
|
|
42
69
|
});
|
|
70
|
+
ensureProxySetup().catch(() => { });
|
|
43
71
|
}
|
|
44
72
|
async streamText(options) {
|
|
73
|
+
await ensureProxySetup();
|
|
45
74
|
const { system, messages, temperature = 0.7, maxOutputTokens, topP, abortSignal, onError } = options;
|
|
46
75
|
const abortController = new AbortController();
|
|
47
76
|
const timeoutId = setTimeout(() => abortController.abort(), this.timeout);
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,10 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astro-minimax/ai",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "Vendor-agnostic AI integration package with full RAG pipeline for astro-minimax blogs.",
|
|
5
|
+
"description": "Vendor-agnostic AI integration package with full RAG pipeline for astro-minimax blogs — supports OpenAI, Cloudflare AI, and custom providers.",
|
|
6
6
|
"author": "Souloss",
|
|
7
7
|
"license": "MIT",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"astro",
|
|
10
|
+
"ai",
|
|
11
|
+
"llm",
|
|
12
|
+
"rag",
|
|
13
|
+
"openai",
|
|
14
|
+
"cloudflare-ai",
|
|
15
|
+
"vector-search",
|
|
16
|
+
"streaming",
|
|
17
|
+
"chatbot"
|
|
18
|
+
],
|
|
19
|
+
"homepage": "https://github.com/souloss/astro-minimax#readme",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/souloss/astro-minimax/issues"
|
|
22
|
+
},
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/souloss/astro-minimax",
|
|
26
|
+
"directory": "packages/ai"
|
|
27
|
+
},
|
|
8
28
|
"bin": {
|
|
9
29
|
"astro-ai-dev": "./dist/server/dev-server.js"
|
|
10
30
|
},
|
|
@@ -56,18 +76,14 @@
|
|
|
56
76
|
"README.md"
|
|
57
77
|
],
|
|
58
78
|
"sideEffects": false,
|
|
59
|
-
"scripts": {
|
|
60
|
-
"build": "tsc -p tsconfig.build.json",
|
|
61
|
-
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
62
|
-
"clean": "rm -rf dist",
|
|
63
|
-
"prepublishOnly": "pnpm run clean && pnpm run build"
|
|
64
|
-
},
|
|
65
79
|
"dependencies": {
|
|
66
80
|
"@ai-sdk/openai-compatible": "^2.0.35",
|
|
67
|
-
"@astro-minimax/notify": "workspace:*",
|
|
68
81
|
"ai": "^6.0.116",
|
|
69
|
-
"
|
|
70
|
-
"
|
|
82
|
+
"workers-ai-provider": "^3.1.2",
|
|
83
|
+
"@astro-minimax/notify": "0.5.0"
|
|
84
|
+
},
|
|
85
|
+
"optionalDependencies": {
|
|
86
|
+
"undici": "^6.0.0"
|
|
71
87
|
},
|
|
72
88
|
"peerDependencies": {
|
|
73
89
|
"@ai-sdk/react": "^3.0.0",
|
|
@@ -88,6 +104,13 @@
|
|
|
88
104
|
"typescript": "^5.9.3"
|
|
89
105
|
},
|
|
90
106
|
"engines": {
|
|
91
|
-
"node": ">=22.12.0"
|
|
107
|
+
"node": ">=22.12.0",
|
|
108
|
+
"pnpm": ">=9.0.0"
|
|
109
|
+
},
|
|
110
|
+
"scripts": {
|
|
111
|
+
"build": "tsc -p tsconfig.build.json",
|
|
112
|
+
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
113
|
+
"typecheck": "tsc --noEmit",
|
|
114
|
+
"clean": "rm -rf dist"
|
|
92
115
|
}
|
|
93
|
-
}
|
|
116
|
+
}
|