@alisio/plugin-openai-compatible 0.1.0-alpha.3 → 0.1.0-alpha.6
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/index.js +2 -1
- package/dist/provider.js +44 -5
- package/dist/version.d.ts +8 -0
- package/dist/version.js +28 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { definePlugin, } from "@alisio/sdk";
|
|
2
2
|
import { OpenAICompatibleProvider } from "./provider.js";
|
|
3
|
+
import { loadVersion } from "./version.js";
|
|
3
4
|
const defaults = {
|
|
4
5
|
baseURL: "https://api.openai.com/v1",
|
|
5
6
|
apiKeyEnv: "OPENAI_API_KEY",
|
|
@@ -16,7 +17,7 @@ export function createOpenAICompatiblePlugin() {
|
|
|
16
17
|
name: "OpenAI compatible",
|
|
17
18
|
description: "OpenAI Chat Completions or Responses compatible endpoint",
|
|
18
19
|
categories: ["model-provider"],
|
|
19
|
-
version:
|
|
20
|
+
version: loadVersion(import.meta.url),
|
|
20
21
|
apiVersion: 1,
|
|
21
22
|
setup(api) {
|
|
22
23
|
api.providers.register({
|
package/dist/provider.js
CHANGED
|
@@ -132,12 +132,23 @@ export class OpenAICompatibleProvider {
|
|
|
132
132
|
if (choice.finish_reason)
|
|
133
133
|
finish = choice.finish_reason;
|
|
134
134
|
}
|
|
135
|
-
if (finish !== "stop" && finish !== "tool_calls")
|
|
135
|
+
if (finish !== "stop" && finish !== "tool_calls" && finish !== "length")
|
|
136
136
|
throw new Error(`Provider response incomplete: ${finish ?? "stream ended"}`);
|
|
137
137
|
const completed = [...calls.entries()].sort(([a], [b]) => a - b).map(([, c]) => c);
|
|
138
138
|
if (completed.some((c) => !c.id || !c.name))
|
|
139
139
|
throw new Error("Incomplete tool call");
|
|
140
|
-
|
|
140
|
+
if (finish === "length" && !text.trim())
|
|
141
|
+
throw new Error("Provider response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
|
|
142
|
+
yield {
|
|
143
|
+
type: "completed",
|
|
144
|
+
message: {
|
|
145
|
+
role: "assistant",
|
|
146
|
+
text,
|
|
147
|
+
calls: completed,
|
|
148
|
+
...(finish === "length" ? { truncated: true } : {}),
|
|
149
|
+
},
|
|
150
|
+
usage,
|
|
151
|
+
};
|
|
141
152
|
}
|
|
142
153
|
async *responses(request) {
|
|
143
154
|
const input = [];
|
|
@@ -190,10 +201,38 @@ export class OpenAICompatibleProvider {
|
|
|
190
201
|
yield { type: "text_delta", delta: event.delta };
|
|
191
202
|
if (event.type === "response.reasoning_summary_text.delta")
|
|
192
203
|
yield { type: "reasoning_delta", delta: event.delta };
|
|
193
|
-
if (event.type === "response.failed" ||
|
|
194
|
-
event.type === "response.incomplete" ||
|
|
195
|
-
event.type === "error")
|
|
204
|
+
if (event.type === "response.failed" || event.type === "error")
|
|
196
205
|
throw new Error(`Provider response failed: ${event.type}`);
|
|
206
|
+
if (event.type === "response.incomplete") {
|
|
207
|
+
complete = true;
|
|
208
|
+
const r = event.response;
|
|
209
|
+
const calls = r.output
|
|
210
|
+
.filter((x) => x.type === "function_call")
|
|
211
|
+
.map((x) => ({ id: x.call_id, name: x.name, arguments: x.arguments }));
|
|
212
|
+
const text = r.output
|
|
213
|
+
.filter((x) => x.type === "message")
|
|
214
|
+
.flatMap((x) => x.content)
|
|
215
|
+
.filter((x) => x.type === "output_text")
|
|
216
|
+
.map((x) => x.text)
|
|
217
|
+
.join("");
|
|
218
|
+
if (!text.trim())
|
|
219
|
+
throw new Error("Provider response cut off by max output tokens before any usable content; raise limits.maxOutputTokens");
|
|
220
|
+
if (calls.some((c) => !c.id || !c.name))
|
|
221
|
+
throw new Error("Incomplete tool call");
|
|
222
|
+
yield {
|
|
223
|
+
type: "completed",
|
|
224
|
+
message: { role: "assistant", text, calls, providerData: r.output, truncated: true },
|
|
225
|
+
usage: r.usage
|
|
226
|
+
? {
|
|
227
|
+
input: r.usage.input_tokens,
|
|
228
|
+
output: r.usage.output_tokens,
|
|
229
|
+
...(typeof r.usage.input_tokens_details?.cached_tokens === "number"
|
|
230
|
+
? { cachedInput: r.usage.input_tokens_details.cached_tokens }
|
|
231
|
+
: {}),
|
|
232
|
+
}
|
|
233
|
+
: undefined,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
197
236
|
if (event.type === "response.completed") {
|
|
198
237
|
complete = true;
|
|
199
238
|
const r = event.response;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads this plugin package's version at runtime so plugin metadata, user-agent defaults and CLI
|
|
3
|
+
* reports stay in sync with the published package without a build-time constant to update.
|
|
4
|
+
* The manifest is resolved relative to the module (`src/version.ts` → `../package.json` in the
|
|
5
|
+
* source tree; `dist/version.js` → `../package.json` of the installed package). Standalone
|
|
6
|
+
* binaries inject the version at build time via ALISIO_PACKAGE_VERSION (scripts/binary-build.ts).
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadVersion(fromHere: string): string;
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Fallback used when neither the build-time injection nor the package manifest is readable
|
|
6
|
+
* (e.g. an unpackaged embed). Keep it a development marker, never a publish literal, so it
|
|
7
|
+
* cannot silently desync from the published package.
|
|
8
|
+
*/
|
|
9
|
+
const FALLBACK = "dev";
|
|
10
|
+
/**
|
|
11
|
+
* Reads this plugin package's version at runtime so plugin metadata, user-agent defaults and CLI
|
|
12
|
+
* reports stay in sync with the published package without a build-time constant to update.
|
|
13
|
+
* The manifest is resolved relative to the module (`src/version.ts` → `../package.json` in the
|
|
14
|
+
* source tree; `dist/version.js` → `../package.json` of the installed package). Standalone
|
|
15
|
+
* binaries inject the version at build time via ALISIO_PACKAGE_VERSION (scripts/binary-build.ts).
|
|
16
|
+
*/
|
|
17
|
+
export function loadVersion(fromHere) {
|
|
18
|
+
if (process.env.ALISIO_PACKAGE_VERSION)
|
|
19
|
+
return process.env.ALISIO_PACKAGE_VERSION;
|
|
20
|
+
try {
|
|
21
|
+
const manifest = join(dirname(fileURLToPath(fromHere)), "..", "package.json");
|
|
22
|
+
const parsed = JSON.parse(readFileSync(manifest, "utf8"));
|
|
23
|
+
return typeof parsed.version === "string" && parsed.version ? parsed.version : FALLBACK;
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return FALLBACK;
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alisio/plugin-openai-compatible",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.6",
|
|
4
4
|
"description": "Built-in OpenAI-compatible model provider for Alisio.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"openai": "7.23.0"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@alisio/sdk": "^0.1.0-alpha.
|
|
27
|
+
"@alisio/sdk": "^0.1.0-alpha.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@alisio/sdk": "0.1.0-alpha.
|
|
30
|
+
"@alisio/sdk": "0.1.0-alpha.5"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public",
|