@d-ai/pi 0.2.0 → 0.2.1
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 +40 -59
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1514,74 +1514,55 @@ function remoteMediaFromJob(client, result, request, mimeType) {
|
|
|
1514
1514
|
}
|
|
1515
1515
|
|
|
1516
1516
|
// src/provider.ts
|
|
1517
|
-
|
|
1518
|
-
import { openAICompletionsApi } from "@earendil-works/pi-ai/api/openai-completions.lazy";
|
|
1519
|
-
import { openAIResponsesApi } from "@earendil-works/pi-ai/api/openai-responses.lazy";
|
|
1517
|
+
var KEY_TTL_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
1520
1518
|
function registerDaiProvider(pi) {
|
|
1521
|
-
pi.registerProvider(
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
};
|
|
1554
|
-
}
|
|
1555
|
-
}
|
|
1519
|
+
pi.registerProvider("dai", {
|
|
1520
|
+
name: "D.AI",
|
|
1521
|
+
baseUrl: `${DEFAULT_BASE_URL2}/v1`,
|
|
1522
|
+
api: "openai-completions",
|
|
1523
|
+
apiKey: "$DAI_API_KEY",
|
|
1524
|
+
authHeader: true,
|
|
1525
|
+
models: [],
|
|
1526
|
+
async refreshModels(context) {
|
|
1527
|
+
if (context.allowNetwork === false) {
|
|
1528
|
+
return [];
|
|
1529
|
+
}
|
|
1530
|
+
const file = await loadFileConfig();
|
|
1531
|
+
const key = file.apiKey ?? process.env.DAI_API_KEY;
|
|
1532
|
+
const origin = normalizeOrigin(file.baseUrl ?? DEFAULT_BASE_URL2);
|
|
1533
|
+
const catalog = await discoverDaiCatalog({
|
|
1534
|
+
origin,
|
|
1535
|
+
...key === void 0 ? {} : { apiKey: key },
|
|
1536
|
+
...context.signal === void 0 ? {} : { signal: context.signal }
|
|
1537
|
+
});
|
|
1538
|
+
return toProviderModels(catalog.chat, `${origin}/v1`);
|
|
1539
|
+
},
|
|
1540
|
+
oauth: {
|
|
1541
|
+
name: "D.AI API key",
|
|
1542
|
+
async login(callbacks) {
|
|
1543
|
+
const key = (await callbacks.onPrompt({ message: "D.AI API key (ddsk_...)" })).trim();
|
|
1544
|
+
await saveFileConfig({ apiKey: key });
|
|
1545
|
+
process.env.DAI_API_KEY = key;
|
|
1546
|
+
return {
|
|
1547
|
+
refresh: key,
|
|
1548
|
+
access: key,
|
|
1549
|
+
expires: Date.now() + KEY_TTL_MS
|
|
1550
|
+
};
|
|
1556
1551
|
},
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
if (!context.allowNetwork) {
|
|
1560
|
-
return context.stored?.models ?? [];
|
|
1561
|
-
}
|
|
1562
|
-
const file = await loadFileConfig();
|
|
1563
|
-
const key = (context.credential && "key" in context.credential ? context.credential.key : void 0) || file.apiKey;
|
|
1564
|
-
const origin = normalizeOrigin(file.baseUrl ?? DEFAULT_BASE_URL2);
|
|
1565
|
-
const catalog = await discoverDaiCatalog({
|
|
1566
|
-
origin,
|
|
1567
|
-
...key === void 0 ? {} : { apiKey: key },
|
|
1568
|
-
signal: context.signal
|
|
1569
|
-
});
|
|
1570
|
-
return toPiModels(catalog.chat, `${origin}/v1`);
|
|
1552
|
+
async refreshToken(credentials) {
|
|
1553
|
+
return credentials;
|
|
1571
1554
|
},
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
"openai-responses": openAIResponsesApi()
|
|
1555
|
+
getApiKey(credentials) {
|
|
1556
|
+
return credentials.access;
|
|
1575
1557
|
}
|
|
1576
|
-
}
|
|
1577
|
-
);
|
|
1558
|
+
}
|
|
1559
|
+
});
|
|
1578
1560
|
}
|
|
1579
|
-
function
|
|
1561
|
+
function toProviderModels(models, baseUrl) {
|
|
1580
1562
|
return models.map((model) => ({
|
|
1581
1563
|
id: model.id,
|
|
1582
1564
|
name: model.name,
|
|
1583
1565
|
api: model.api,
|
|
1584
|
-
provider: "dai",
|
|
1585
1566
|
baseUrl,
|
|
1586
1567
|
reasoning: model.reasoning,
|
|
1587
1568
|
input: model.input,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d-ai/pi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Pi extension for D.AI image, video, and music generation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "tsup src/index.ts --format esm --dts --clean --external @earendil-works/pi-coding-agent --external
|
|
20
|
+
"build": "tsup src/index.ts --format esm --dts --clean --external @earendil-works/pi-coding-agent --external typebox",
|
|
21
21
|
"typecheck": "tsc --noEmit",
|
|
22
22
|
"test": "vitest run",
|
|
23
23
|
"check": "npm run typecheck && npm test && npm run build",
|