pi-opencode-go-provider 1.1.14 → 1.1.15
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/CHANGELOG.md +6 -0
- package/README.md +5 -0
- package/package.json +2 -2
- package/scripts/test-pi-compat.mjs +85 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.1.15
|
|
4
|
+
|
|
5
|
+
- Pin Pi SDK development dependencies to 1.0.0 while retaining wildcard host peers.
|
|
6
|
+
- Verify real manifest loading, provider catalogs, startup/shutdown and native/bundled Pi hosts offline.
|
|
7
|
+
- Exercise real transport adapters with Unicode text, tool calls, empty responses, usage, request hooks and cancellation; no live provider calls.
|
|
8
|
+
|
|
3
9
|
## 1.1.14
|
|
4
10
|
|
|
5
11
|
- Test against Pi 0.99.0 and declare host-provided modules as wildcard peers.
|
package/README.md
CHANGED
|
@@ -11,6 +11,11 @@ _Go-optimized endpoints for lower latency — 14+ models for [pi](https://github
|
|
|
11
11
|
|
|
12
12
|
</div>
|
|
13
13
|
|
|
14
|
+
## Pi 1.0 compatibility
|
|
15
|
+
|
|
16
|
+
Tested with Pi **1.0.0**. Host-provided packages remain wildcard peers; development uses exact SDK pins.
|
|
17
|
+
Run `bun run test:pi` for offline manifest, catalog, lifecycle and streaming checks. To test an installed host, set `PI1_HOST_PACKAGE` to its package directory; add `PI1_HOST_ENTRY=bundle` for its bundled CLI runtime. The probe stubs all network requests and never uses a live provider endpoint.
|
|
18
|
+
|
|
14
19
|
---
|
|
15
20
|
|
|
16
21
|
## Features
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-opencode-go-provider",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.15",
|
|
4
4
|
"description": "Opencode Go provider extension for pi - Fast, efficient GLM, Kimi, and MiniMax models through the opencode.ai API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
]
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@earendil-works/pi-coding-agent": "0.
|
|
36
|
+
"@earendil-works/pi-coding-agent": "1.0.0",
|
|
37
37
|
"@types/node": "~22.19.0",
|
|
38
38
|
"typescript": "^6.0.3"
|
|
39
39
|
},
|
|
@@ -1,76 +1,115 @@
|
|
|
1
|
+
// Offline Pi 1.0 manifest, lifecycle, catalog and real transport regression.
|
|
1
2
|
import assert from 'node:assert/strict';
|
|
2
3
|
import { mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
3
4
|
import { tmpdir } from 'node:os';
|
|
4
5
|
import { dirname, join, resolve } from 'node:path';
|
|
5
|
-
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
6
7
|
|
|
7
|
-
// Import Pi only after selecting a disposable agent directory. Never read user auth/cache.
|
|
8
8
|
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
9
9
|
const home = await mkdtemp(join(tmpdir(), 'pi-provider-compat-'));
|
|
10
10
|
const previousHome = process.env.PI_CODING_AGENT_DIR;
|
|
11
11
|
const previousFetch = globalThis.fetch;
|
|
12
12
|
process.env.PI_CODING_AGENT_DIR = home;
|
|
13
|
+
// Never allow a background catalog/account request to reach a real endpoint.
|
|
13
14
|
globalThis.fetch = async () => new Response('', { status: 503 });
|
|
14
15
|
let session;
|
|
15
16
|
try {
|
|
16
|
-
const
|
|
17
|
-
|
|
17
|
+
const host = process.env.PI1_HOST_PACKAGE;
|
|
18
|
+
const hostEntry = process.env.PI1_HOST_ENTRY === 'bundle' ? 'dist/bundle/index.js' : 'dist/index.js';
|
|
19
|
+
const sdk = await import(host ? pathToFileURL(join(host, hostEntry)).href : '@earendil-works/pi-coding-agent');
|
|
20
|
+
const { createAgentSession, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager, VERSION } = sdk;
|
|
21
|
+
assert.equal(VERSION, '1.0.0', 'executing host version');
|
|
22
|
+
assert.equal((await import('@earendil-works/pi-coding-agent')).VERSION, '1.0.0', 'development host version');
|
|
18
23
|
const manifest = JSON.parse(await readFile(join(root, 'package.json'), 'utf8'));
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
assert.equal(manifest.dependencies?.[name], undefined, `${name} must not be installed as a runtime dependency`);
|
|
24
|
+
for (const name of ['@earendil-works/pi-ai', '@earendil-works/pi-agent-core', '@earendil-works/pi-coding-agent', '@earendil-works/pi-tui', 'typebox']) {
|
|
25
|
+
assert.equal(manifest.dependencies?.[name], undefined, `${name}: do not bundle host packages`);
|
|
22
26
|
if (manifest.peerDependencies?.[name] !== undefined) assert.equal(manifest.peerDependencies[name], '*');
|
|
27
|
+
if (name !== 'typebox' && manifest.devDependencies?.[name]) assert.equal(manifest.devDependencies[name], '1.0.0');
|
|
23
28
|
}
|
|
24
|
-
const settingsManager = SettingsManager.inMemory({ compaction: { enabled: false }, retry: { enabled: false } });
|
|
25
|
-
const resourceLoader = new DefaultResourceLoader({
|
|
26
|
-
|
|
27
|
-
additionalExtensionPaths: [join(root, 'index.ts')],
|
|
28
|
-
noSkills: true, noPromptTemplates: true, noThemes: true, noContextFiles: true,
|
|
29
|
-
});
|
|
29
|
+
const settingsManager = SettingsManager.inMemory({ packages: [root], compaction: { enabled: false }, retry: { enabled: false } });
|
|
30
|
+
const resourceLoader = new DefaultResourceLoader({ cwd: home, agentDir: home, settingsManager,
|
|
31
|
+
noSkills: true, noPromptTemplates: true, noThemes: true, noContextFiles: true });
|
|
30
32
|
await resourceLoader.reload();
|
|
31
33
|
const loaded = resourceLoader.getExtensions();
|
|
32
|
-
assert.deepEqual(loaded.errors, []
|
|
33
|
-
assert.deepEqual(loaded.warnings ?? [], []
|
|
34
|
-
assert.equal(loaded.extensions.length,
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
assert.deepEqual(loaded.errors, []);
|
|
35
|
+
assert.deepEqual(loaded.warnings ?? [], []);
|
|
36
|
+
assert.equal(loaded.extensions.length, manifest.pi.extensions.length, 'all manifest entrypoints load');
|
|
37
|
+
// Endpoint/header-only re-registration (e.g. MCR) retains the prior catalog.
|
|
38
|
+
const registrations = [...loaded.runtime.pendingProviderRegistrations.reduce((byName, { name, config }) =>
|
|
39
|
+
byName.set(name, { name, config: { ...byName.get(name)?.config, ...config } }), new Map()).values()];
|
|
40
|
+
assert(registrations.length > 0, 'providers register before session startup');
|
|
37
41
|
const modelRuntime = await ModelRuntime.create({ authPath: join(home, 'auth.json'), modelsPath: null, modelsStorePath: join(home, 'models-cache'), allowModelNetwork: false });
|
|
38
|
-
({ session } = await createAgentSession({ cwd: home, agentDir: home, resourceLoader, modelRuntime, settingsManager, sessionManager: SessionManager.inMemory(home)
|
|
42
|
+
({ session } = await createAgentSession({ cwd: home, agentDir: home, resourceLoader, modelRuntime, settingsManager, sessionManager: SessionManager.inMemory(home) }));
|
|
39
43
|
const errors = [];
|
|
40
|
-
await session.bindExtensions({ mode: 'print', onError:
|
|
41
|
-
await new Promise(
|
|
42
|
-
|
|
44
|
+
await session.bindExtensions({ mode: 'print', onError: error => errors.push(error) });
|
|
45
|
+
await new Promise(done => setImmediate(done));
|
|
46
|
+
const tools = new Set();
|
|
47
|
+
for (const extension of loaded.extensions) for (const [name, { definition }] of extension.tools) {
|
|
48
|
+
assert.equal(definition.name, name); assert.equal(typeof definition.execute, 'function');
|
|
49
|
+
assert.equal(typeof definition.parameters, 'object'); assert(!tools.has(name)); tools.add(name);
|
|
50
|
+
assert(session.getAllTools().some(tool => tool.name === name));
|
|
51
|
+
}
|
|
52
|
+
let modelCount = 0, streamChecks = 0;
|
|
43
53
|
for (const { name, config } of registrations) {
|
|
44
54
|
const models = modelRuntime.getAllModels(name);
|
|
45
|
-
assert.equal(models.length, config.models.length, `${name}:
|
|
46
|
-
assert
|
|
47
|
-
assert.equal(new Set(models.map(
|
|
55
|
+
assert.equal(models.length, config.models.length, `${name}: catalog survives registration`);
|
|
56
|
+
assert(models.length > 0);
|
|
57
|
+
assert.equal(new Set(models.map(m => `${m.type}/${m.id}`)).size, models.length);
|
|
48
58
|
for (const model of models) {
|
|
49
|
-
assert.equal(model.provider, name);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (const cost of Object.values(model.cost)) assert.ok(Number.isFinite(cost) && cost >= 0);
|
|
59
|
+
assert.equal(model.provider, name); assert(model.api && model.baseUrl && model.id && model.name);
|
|
60
|
+
if (model.type === 'image') assert(model.output.includes('image'));
|
|
61
|
+
else assert(model.contextWindow > 0);
|
|
62
|
+
if ((model.type ?? 'chat') === 'chat') assert(model.maxTokens > 0);
|
|
63
|
+
assert(model.input.includes('text'));
|
|
64
|
+
for (const cost of Object.values(model.cost)) assert(Number.isFinite(cost) && cost >= 0);
|
|
56
65
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
const chatModels = modelRuntime.getModels(name);
|
|
67
|
+
const model = chatModels.find(m => m.api === 'openai-completions') ?? chatModels[0];
|
|
68
|
+
assert(model, 'a chat model is available for offline transport checks');
|
|
69
|
+
const user = { role: 'user', content: 'hello', timestamp: 1 };
|
|
70
|
+
async function probe(tool = false, empty = false) {
|
|
71
|
+
let payloadCalls = 0, responseCalls = 0, observed = 0, wire;
|
|
72
|
+
const fetch = async (_url, init) => {
|
|
73
|
+
wire = JSON.parse(init.body);
|
|
74
|
+
const delta = tool ? { tool_calls: [{ index: 0, id: 'call_probe', type: 'function', function: { name: 'probe', arguments: '{"value":7}' } }] } : { content: empty ? '' : 'Hello 界' };
|
|
75
|
+
const chunks = [{ id: 'offline', choices: [{ index: 0, delta: { role: 'assistant', ...delta }, finish_reason: null }] }, { id: 'offline', choices: [{ index: 0, delta: {}, finish_reason: tool ? 'tool_calls' : 'stop' }], usage: { prompt_tokens: 10, completion_tokens: 2, total_tokens: 12 } }];
|
|
76
|
+
return new Response(chunks.map(c => `data: ${JSON.stringify(c)}\n\n`).join('') + 'data: [DONE]\n\n', { headers: { 'content-type': 'text/event-stream' } });
|
|
77
|
+
};
|
|
78
|
+
const stream = modelRuntime.streamSimple(model, { messages: [{ role: 'system', content: 'Offline probe', toolsAdded: [{ name: 'probe', description: 'Probe', parameters: { type: 'object', properties: { value: { type: 'integer' } }, required: ['value'] } }], timestamp: 0 }, user] }, {
|
|
79
|
+
apiKey: 'offline-placeholder', maxTokens: 32, maxRetries: 0, fetch,
|
|
80
|
+
onPayload: p => { payloadCalls++; return { ...p, temperature: 0.123 }; },
|
|
81
|
+
onResponse: () => { responseCalls++; }, onProviderStreamEvent: () => { observed++; },
|
|
82
|
+
});
|
|
83
|
+
const events = []; for await (const event of stream) events.push(event.type);
|
|
84
|
+
const result = await stream.result();
|
|
85
|
+
assert.equal(result.stopReason, tool ? 'toolUse' : 'stop', result.errorMessage);
|
|
86
|
+
assert.equal(events.filter(e => e === 'start').length, 1);
|
|
87
|
+
assert.equal(events.filter(e => e === 'done' || e === 'error').length, 1);
|
|
88
|
+
assert.equal(events.at(-1), 'done');
|
|
89
|
+
assert.equal(payloadCalls, 1); assert.equal(responseCalls, 1); assert(observed >= 2);
|
|
90
|
+
assert.equal(wire.temperature, 0.123); assert.equal(wire.tools[0].function.name, 'probe');
|
|
91
|
+
assert.equal(result.usage.totalTokens, 12);
|
|
92
|
+
if (tool) assert.deepEqual(result.content.find(c => c.type === 'toolCall').arguments, { value: 7 });
|
|
93
|
+
else if (!empty) assert.equal(result.content.find(c => c.type === 'text').text, 'Hello 界');
|
|
94
|
+
streamChecks++;
|
|
64
95
|
}
|
|
96
|
+
await probe(); await probe(true); await probe(false, true);
|
|
97
|
+
// Abort after preflight: the SDK's lazy preflight reports an already-aborted
|
|
98
|
+
// auth operation as an error; this checks provider transport cancellation.
|
|
99
|
+
const controller = new AbortController();
|
|
100
|
+
const aborted = await modelRuntime.streamSimple(model, { messages: [user] }, {
|
|
101
|
+
apiKey: 'offline-placeholder', signal: controller.signal, maxRetries: 0,
|
|
102
|
+
onPayload: () => { controller.abort(); },
|
|
103
|
+
fetch: async () => { throw new DOMException('Aborted', 'AbortError'); },
|
|
104
|
+
}).result();
|
|
105
|
+
assert.equal(aborted.stopReason, 'aborted', aborted.errorMessage); streamChecks++;
|
|
65
106
|
modelCount += models.length;
|
|
66
107
|
}
|
|
67
|
-
await session.extensionRunner.emit({ type: 'session_shutdown' });
|
|
68
|
-
assert.deepEqual(errors, []
|
|
69
|
-
console.log(
|
|
108
|
+
await session.extensionRunner.emit({ type: 'session_shutdown', reason: 'quit' });
|
|
109
|
+
assert.deepEqual(errors, []);
|
|
110
|
+
console.log(JSON.stringify({ repo: manifest.name, pi: VERSION, hostEntry, extensions: loaded.extensions.length, tools: tools.size, models: modelCount, streamChecks, lifecycle: 'passed' }));
|
|
70
111
|
} finally {
|
|
71
|
-
session?.dispose();
|
|
72
|
-
|
|
73
|
-
if (previousHome === undefined) delete process.env.PI_CODING_AGENT_DIR;
|
|
74
|
-
else process.env.PI_CODING_AGENT_DIR = previousHome;
|
|
112
|
+
session?.dispose(); globalThis.fetch = previousFetch;
|
|
113
|
+
if (previousHome === undefined) delete process.env.PI_CODING_AGENT_DIR; else process.env.PI_CODING_AGENT_DIR = previousHome;
|
|
75
114
|
await rm(home, { recursive: true, force: true });
|
|
76
115
|
}
|