@ycodium-ai/agent-pi 0.2.3766 → 0.2.3799
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/README.md +26 -10
- package/assets/ICON-LICENSE +28 -0
- package/assets/icon.svg +1 -1
- package/assets/ui.js +2 -2
- package/dist/index.js +124 -46
- package/locales/en.json +8 -1
- package/locales/zh-CN.json +8 -1
- package/package.json +7 -5
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# @ycodium-ai/agent-pi
|
|
2
2
|
|
|
3
|
-
Run Pi in Ycodium
|
|
3
|
+
Run Pi in Ycodium. By default an instance uses Pi's own sign-in, model providers
|
|
4
|
+
and default model, and lists the models Pi reports; nothing needs to be filled in.
|
|
5
|
+
An instance can instead connect Pi to one model API service: choose Chat Completions,
|
|
4
6
|
OpenAI Responses or Anthropic Messages, then configure the API base URL, API key
|
|
5
|
-
and model ID in Settings → Providers
|
|
6
|
-
|
|
7
|
-
instances configured on the connected machine.
|
|
7
|
+
and model ID in Settings → Providers. The connection form is available on Web and
|
|
8
|
+
Desktop; Mobile uses instances configured on the connected machine.
|
|
8
9
|
|
|
9
10
|
## Requirements
|
|
10
11
|
|
|
@@ -15,7 +16,9 @@ npm install -g @earendil-works/pi-coding-agent
|
|
|
15
16
|
```
|
|
16
17
|
|
|
17
18
|
Pi must be on that machine's `PATH`, or its executable path must be set under the
|
|
18
|
-
instance's advanced settings.
|
|
19
|
+
instance's advanced settings. With Pi's own sign-in, sign in once by running `pi` and
|
|
20
|
+
`/login`, or configure a provider in Pi; an empty model list is reported as signed out.
|
|
21
|
+
For a custom API service, choose the request protocol supported by your service.
|
|
19
22
|
For Chat Completions or OpenAI Responses, supply the API base URL, usually ending
|
|
20
23
|
in `/v1`, without `/chat/completions` or `/responses`. For Anthropic Messages,
|
|
21
24
|
supply the service root or a base URL ending in `/v1`; the runtime resolves the
|
|
@@ -38,7 +41,20 @@ server restart does not restore it; reinstall the package to restore it.
|
|
|
38
41
|
|
|
39
42
|
## Connection and sessions
|
|
40
43
|
|
|
41
|
-
The
|
|
44
|
+
The optional `connection` field is `pi` (Pi's own configuration) or `custom`.
|
|
45
|
+
Instances saved without it use `custom` when an API base URL is set and `pi`
|
|
46
|
+
otherwise: instances with an API base URL keep their service, and ones without a base URL, which
|
|
47
|
+
could not start before, now use Pi's own configuration. With `pi`, the hidden `apiProtocol`, `model`
|
|
48
|
+
and custom service fields stay saved but are not read.
|
|
49
|
+
|
|
50
|
+
With `pi`, Pi reads its usual configuration directory (`PI_CODING_AGENT_DIR`, or
|
|
51
|
+
`~/.pi/agent`); set that variable in the instance environment to give one instance a
|
|
52
|
+
separate Pi account. Models are reported as `provider/model` from Pi's
|
|
53
|
+
`get_available_models`, and Pi's current model is the default. Host MCP servers are
|
|
54
|
+
registered for each session by a small launch-time extension through
|
|
55
|
+
`registerMcpServer`, so Pi's `mcp.json` is never written.
|
|
56
|
+
|
|
57
|
+
For `custom`, the form stores the API key as the sensitive `YCODIUM_PI_API_KEY` environment
|
|
42
58
|
variable. Existing keys are masked; leaving the masked field empty preserves the
|
|
43
59
|
saved key. Enter a new key to replace it. The URL and model are stored in the
|
|
44
60
|
instance's `apiBaseUrl` and `model` configuration fields. The optional `apiProtocol`
|
|
@@ -47,10 +63,10 @@ Connections without that field use Chat Completions. An unknown saved protocol
|
|
|
47
63
|
is shown as invalid and must be explicitly replaced. Advanced configurations
|
|
48
64
|
can also supply `YCODIUM_PI_API_BASE_URL`.
|
|
49
65
|
|
|
50
|
-
The plugin starts `pi --mode rpc` through Ycodium's managed process API.
|
|
51
|
-
|
|
52
|
-
provider)
|
|
53
|
-
extensions. MCP tools are discovered on demand rather than all advertised in the first request.
|
|
66
|
+
The plugin starts `pi --mode rpc` through Ycodium's managed process API. For
|
|
67
|
+
`custom` it provides a temporary configuration directory with model and MCP configuration
|
|
68
|
+
(every listed model under one `ycodium` provider). Both connections enable Pi's built-in
|
|
69
|
+
MCP and tool-search extensions. MCP tools are discovered on demand rather than all advertised in the first request.
|
|
54
70
|
Native session files live in a directory specific
|
|
55
71
|
to the instance under `~/.pi/ycodium/`, unless a session directory is configured
|
|
56
72
|
under advanced settings. Keep that directory stable to resume existing sessions;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
icon.svg in this directory uses the path data of icons/pi.svg from
|
|
2
|
+
@lobehub/icons-static-svg 1.101.0, part of Lobe Icons
|
|
3
|
+
(https://github.com/lobehub/lobe-icons), filled with a single color and with
|
|
4
|
+
the viewBox cropped to the mark. Pi is a trademark of its owner.
|
|
5
|
+
|
|
6
|
+
The Lobe Icons license follows.
|
|
7
|
+
|
|
8
|
+
MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2023 LobeHub
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
package/assets/icon.svg
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="1 1 22 22" fill="#F09082" fill-rule="evenodd"><path d="M1 1h16.5v11H12v5.5H6.5V23H1V1zm5.5 5.5V12H12V6.5H6.5z"/><path d="M17.5 12H23v11h-5.5V12z"/></svg>
|
package/assets/ui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var O=window.__ycodiumPluginHost.modules?.["@ycodium-ai/plugin-api/provider-settings"];if(!O)throw new Error("This plugin needs a newer Ycodium app. Update the app.");var{PROVIDER_SETTINGS_VIEW_CAPABILITY:U,accountDirectoryCandidates:Z,accountDirectorySlug:ee,accountProbeHasSignedInAccount:te,allocateAccountDirectory:oe,providerInstanceAccountPaths:ne}=O;var q=window.__ycodiumPluginHost.react;var{Activity:re,Children:ae,Component:ce,Fragment:se,Profiler:le,PureComponent:pe,StrictMode:ue,Suspense:me,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:de,__COMPILER_RUNTIME:fe,act:ge,cache:Pe,cacheSignal:ye,captureOwnerStack:Se,cloneElement:ve,createContext:k,createElement:S,createRef:Ie,forwardRef:we,isValidElement:he,lazy:Ce,memo:xe,startTransition:Te,unstable_useCacheRefresh:_e,use:be,useActionState:Ee,useCallback:Ne,useContext:L,useDebugValue:Ae,useDeferredValue:Re,useEffect:B,useEffectEvent:Oe,useId:D,useImperativeHandle:Ue,useInsertionEffect:ke,useLayoutEffect:Le,useMemo:Be,useOptimistic:De,useReducer:Ve,useRef:$e,useState:He,useSyncExternalStore:Ke,useTransition:Me,version:Ye}=q;var V=k(null),$=V.Provider;function d(){let e=L(V);if(e===null)throw new Error("Pi UI has not been registered.");return e}var v=["openai-completions","openai-responses","anthropic-messages"],H="openai-completions";function f(e){return v.some(t=>t===e)}var I=["pi","custom"];function w(e){return I.some(t=>t===e)}function K(e,t){return w(e)?e:t.trim()?"custom":"pi"}var h="connection",P="YCODIUM_PI_API_KEY";function C(e){try{let t=new URL(e.trim());return(t.protocol==="http:"||t.protocol==="https:")&&!t.username&&!t.password&&!t.search&&!t.hash}catch{return!1}}function x(e){let t=e.config.apiBaseUrl,n=e.environment.find(s=>s.name==="YCODIUM_PI_API_BASE_URL")?.value;return K(e.config.connection,typeof t=="string"&&t.trim()?t:n??"")}function M(e){if(x(e)==="pi")return!0;let{apiProtocol:t,apiBaseUrl:n,model:s}=e.config,a=e.environment.find(u=>u.name===P);return(t===void 0||f(t))&&typeof n=="string"&&C(n)&&typeof s=="string"&&s.trim().length>0&&a!==void 0&&(a.valueRedacted===!0||a.value.trim().length>0)}function Y(e,t){let n=e.trim();return!n&&t?{}:{environment:[{name:P,value:n,sensitive:!0}]}}function T(e){return S(d().ui.DraftInput,e)}function g(e){return(t=>S(d().ui[e],{...t,className:`ycodium-pi-ui ${typeof t.className=="string"?t.className:""}`}))}var _=g("Select"),b=g("SelectTrigger"),E=g("SelectPopup"),N=g("SelectItem"),A=g("SelectValue");function R(){let e=d().i18n.usePluginTranslation();return{t:(t,n)=>e(t,n)}}var{jsx:i,jsxs:l,Fragment:F}=window.__ycodiumPluginHost.jsxRuntime;function j({instance:e,readOnly:t,onReport:n,onChange:s}){let{t:a}=R(),u=D(),c=x(e),r=M(e),o=r&&c==="custom"?a("connectionNotVerified"):void 0;B(()=>n({complete:r,hidesSignIn:!0,signInAfterAdd:!1,notice:o}),[r,o,n]);let m=e.environment.find(p=>p.name===P),G=m?.valueRedacted===!0,y=e.config.apiProtocol,W=y===void 0?H:f(y)?y:null;return l("div",{className:"ycodium-pi-ui grid min-w-0 gap-4",children:[l("div",{className:"grid min-w-0 gap-1",children:[i("span",{id:`${u}-connection-label`,className:"text-control-4 font-medium",children:a("form.connection.title")}),l(_,{value:c,disabled:t,onValueChange:p=>{!t&&w(p)&&s({config:{connection:p}})},children:[i(b,{"aria-labelledby":`${u}-connection-label`,children:i(A,{children:a(`connection.modes.${c}`)})}),i(E,{children:I.map(p=>i(N,{value:p,children:a(`connection.modes.${p}`)},p))})]})]}),c==="custom"?i(J,{id:u,instance:e,readOnly:t,onChange:s,storedKey:G,keyValue:m?.value??"",protocol:W}):null]})}function J({id:e,instance:t,readOnly:n,onChange:s,storedKey:a,keyValue:u,protocol:c}){let{t:r}=R();return l(F,{children:[l("div",{className:"grid min-w-0 gap-1",children:[i("span",{id:`${e}-protocol-label`,className:"text-control-4 font-medium",children:r("form.apiProtocol.title")}),l(_,{value:c,disabled:n,onValueChange:o=>{!n&&f(o)&&s({config:{apiProtocol:o}})},children:[i(b,{"aria-labelledby":`${e}-protocol-label`,"aria-describedby":c===null?`${e}-protocol-description`:void 0,"aria-invalid":c===null,children:i(A,{children:r(c===null?"connection.protocolUnknown":`connection.protocols.${c}`)})}),i(E,{children:v.map(o=>i(N,{value:o,children:r(`connection.protocols.${o}`)},o))})]}),c===null?i("span",{id:`${e}-protocol-description`,className:"text-ui-sm text-destructive-foreground",children:r("connection.invalidProtocol")}):null]}),["apiBaseUrl","model"].map(o=>l("label",{className:"grid min-w-0 gap-1",children:[i("span",{className:"text-control-4 font-medium",children:r(`form.${o}.title`)}),i(T,{value:typeof t.config[o]=="string"?t.config[o]:"",onCommit:m=>{n||s({config:{[o]:m.trim()}})},validate:m=>(o==="apiBaseUrl"?C(m):m.trim().length>0)?null:r(o==="apiBaseUrl"?"connection.invalidUrl":"connection.modelRequired"),disabled:n,autoComplete:"off",spellCheck:!1,"aria-label":r(`form.${o}.title`),"aria-describedby":`${e}-${o}-description`}),i("span",{id:`${e}-${o}-description`,className:"text-ui-sm text-muted-foreground",children:r(o==="apiBaseUrl"&&c!==null?`connection.baseUrlGuidance.${c}`:`form.${o}.description`)})]},o)),l("label",{className:"grid min-w-0 gap-1",children:[i("span",{className:"text-control-4 font-medium",children:r("connection.key")}),i(T,{type:"password",autoComplete:"off",spellCheck:!1,disabled:n,"aria-label":r("connection.key"),value:a?"":u,placeholder:a?r("connection.stored"):void 0,validate:o=>a||o.trim()?null:r("connection.keyRequired"),onCommit:o=>{n||s(Y(o,a))}})]})]})}var z=`/*! tailwindcss v4.3.0 | MIT License | https://tailwindcss.com */
|
|
2
2
|
@layer properties, theme, base, components, utilities;
|
|
3
3
|
@layer properties;
|
|
4
4
|
@layer utilities {
|
|
@@ -63,4 +63,4 @@ var C=window.__ycodiumPluginHost.modules?.["@ycodium-ai/plugin-api/provider-sett
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
-
`;function
|
|
66
|
+
`;function X(e){let t=n=>l($,{value:e,children:[i("style",{children:z}),i(j,{...n})]});return{pages:{},panels:{},views:{[h]:t},viewCapabilities:{[h]:[U]}}}export{X as default};
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,14 @@ var DEFAULT_PI_API_PROTOCOL = "openai-completions";
|
|
|
23
23
|
function isPiApiProtocol(value) {
|
|
24
24
|
return PI_API_PROTOCOLS.some((protocol) => protocol === value);
|
|
25
25
|
}
|
|
26
|
+
var PI_CONNECTIONS = ["pi", "custom"];
|
|
27
|
+
function isPiConnection(value) {
|
|
28
|
+
return PI_CONNECTIONS.some((connection) => connection === value);
|
|
29
|
+
}
|
|
30
|
+
function readPiConnection(value, apiBaseUrl) {
|
|
31
|
+
if (isPiConnection(value)) return value;
|
|
32
|
+
return apiBaseUrl.trim() ? "custom" : "pi";
|
|
33
|
+
}
|
|
26
34
|
function readPiApiProtocol(value) {
|
|
27
35
|
if (value === void 0) return DEFAULT_PI_API_PROTOCOL;
|
|
28
36
|
if (isPiApiProtocol(value)) return value;
|
|
@@ -48,12 +56,16 @@ function parseConfig(value, instanceId) {
|
|
|
48
56
|
const custom = (Array.isArray(config.customModels) ? config.customModels : []).map(
|
|
49
57
|
(entry) => string(typeof entry === "string" ? entry : record(entry).slug).trim()
|
|
50
58
|
);
|
|
59
|
+
const apiBaseUrl = string(config.apiBaseUrl).trim() || environment.YCODIUM_PI_API_BASE_URL?.trim() || "";
|
|
60
|
+
const connection = readPiConnection(config.connection, apiBaseUrl);
|
|
61
|
+
const customService = connection === "custom";
|
|
51
62
|
return {
|
|
52
63
|
binaryPath: string(config.binaryPath).trim() || "pi",
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
connection,
|
|
65
|
+
apiBaseUrl,
|
|
66
|
+
apiProtocol: customService ? readPiApiProtocol(config.apiProtocol) : DEFAULT_PI_API_PROTOCOL,
|
|
67
|
+
model: customService ? model : "",
|
|
68
|
+
models: customService ? [...new Set([model, ...custom].filter(Boolean))] : [],
|
|
57
69
|
environment,
|
|
58
70
|
homePath: homePath ? NodePath.resolve(homePath) : NodePath.join(NodeOS.homedir(), ".pi", "ycodium", identifier(instanceId))
|
|
59
71
|
};
|
|
@@ -65,7 +77,24 @@ function nativeApiBaseUrl(baseUrl, apiProtocol) {
|
|
|
65
77
|
if (apiProtocol === "anthropic-messages") url.pathname = url.pathname.replace(/\/v1$/, "");
|
|
66
78
|
return url.toString().replace(/\/$/, "");
|
|
67
79
|
}
|
|
80
|
+
var CUSTOM_PROVIDER = "ycodium";
|
|
81
|
+
function modelSlug(config, model) {
|
|
82
|
+
const entry = record(model), id = string(entry.id), provider = string(entry.provider);
|
|
83
|
+
if (!id || id === "unknown") return "";
|
|
84
|
+
return config.connection === "custom" || !provider ? id : `${provider}/${id}`;
|
|
85
|
+
}
|
|
86
|
+
function nativeModel(config, slug) {
|
|
87
|
+
if (config.connection === "custom") return { provider: CUSTOM_PROVIDER, modelId: slug };
|
|
88
|
+
const split = slug.indexOf("/");
|
|
89
|
+
if (split <= 0) throw providerRejected(`Pi model "${slug}" must be written as provider/model.`);
|
|
90
|
+
return { provider: slug.slice(0, split), modelId: slug.slice(split + 1) };
|
|
91
|
+
}
|
|
92
|
+
function launchModel(config, slug) {
|
|
93
|
+
return config.connection === "custom" ? `${CUSTOM_PROVIDER}/${slug}` : slug;
|
|
94
|
+
}
|
|
95
|
+
var providerRejected = (message) => Object.assign(new Error(message), { code: "provider-rejected" });
|
|
68
96
|
function validateConnection(config) {
|
|
97
|
+
if (config.connection === "pi") return;
|
|
69
98
|
let url;
|
|
70
99
|
try {
|
|
71
100
|
url = new URL(config.apiBaseUrl);
|
|
@@ -80,13 +109,14 @@ function validateConnection(config) {
|
|
|
80
109
|
function requestedModel(config, selection) {
|
|
81
110
|
const raw = string(record(selection).model).trim();
|
|
82
111
|
if (!raw) return void 0;
|
|
112
|
+
if (config.connection === "pi") {
|
|
113
|
+
nativeModel(config, raw);
|
|
114
|
+
return raw;
|
|
115
|
+
}
|
|
83
116
|
const id = matchCatalogModel(raw, config.models) ?? matchCatalogModel(raw.replace(/^ycodium\//, ""), config.models);
|
|
84
117
|
if (id) return id;
|
|
85
|
-
throw
|
|
86
|
-
|
|
87
|
-
`Pi instance does not list model "${raw}". Choose one of: ${config.models.join(", ")}. Provider setting changes apply after the session restarts.`
|
|
88
|
-
),
|
|
89
|
-
{ code: "provider-rejected" }
|
|
118
|
+
throw providerRejected(
|
|
119
|
+
`Pi instance does not list model "${raw}". Choose one of: ${config.models.join(", ")}. Provider setting changes apply after the session restarts.`
|
|
90
120
|
);
|
|
91
121
|
}
|
|
92
122
|
function redact(config, value) {
|
|
@@ -133,8 +163,21 @@ var PI_CARD = {
|
|
|
133
163
|
configSchema: {
|
|
134
164
|
type: "object",
|
|
135
165
|
additionalProperties: true,
|
|
136
|
-
"x-ycodium-form-order": [
|
|
166
|
+
"x-ycodium-form-order": [
|
|
167
|
+
"connection",
|
|
168
|
+
"apiProtocol",
|
|
169
|
+
"apiBaseUrl",
|
|
170
|
+
"model",
|
|
171
|
+
"binaryPath",
|
|
172
|
+
"homePath"
|
|
173
|
+
],
|
|
137
174
|
properties: {
|
|
175
|
+
// 不给默认值:没存这一项的存量实例按有没有 API 地址判断,见 readPiConnection。
|
|
176
|
+
connection: {
|
|
177
|
+
type: "string",
|
|
178
|
+
enum: PI_CONNECTIONS,
|
|
179
|
+
"x-ycodium-form": { titleKey: "form.connection.title" }
|
|
180
|
+
},
|
|
138
181
|
apiProtocol: {
|
|
139
182
|
type: "string",
|
|
140
183
|
enum: PI_API_PROTOCOLS,
|
|
@@ -332,6 +375,15 @@ var PiRpc = class {
|
|
|
332
375
|
};
|
|
333
376
|
|
|
334
377
|
// src/connection.ts
|
|
378
|
+
var PI_MCP_SERVERS_ENV = "YCODIUM_PI_MCP_SERVERS";
|
|
379
|
+
var MCP_EXTENSION_SOURCE = `import { readFileSync } from "node:fs";
|
|
380
|
+
export default function (pi) {
|
|
381
|
+
const file = process.env.${PI_MCP_SERVERS_ENV};
|
|
382
|
+
if (!file) return;
|
|
383
|
+
const { mcpServers } = JSON.parse(readFileSync(file, "utf8"));
|
|
384
|
+
for (const [name, server] of Object.entries(mcpServers)) pi.registerMcpServer(name, server);
|
|
385
|
+
}
|
|
386
|
+
`;
|
|
335
387
|
function resumeCursor(config, input) {
|
|
336
388
|
const stored = record(input.discardResumeCursor ? void 0 : input.resumeCursor);
|
|
337
389
|
const sessionId = string(stored.sessionId);
|
|
@@ -362,25 +414,25 @@ function initializeResumeCursor(cursor, state) {
|
|
|
362
414
|
cursor.sessionFile = sessionFile;
|
|
363
415
|
}
|
|
364
416
|
async function createLaunch(config, input, cursor) {
|
|
365
|
-
const
|
|
366
|
-
const baseUrl = nativeApiBaseUrl(config.apiBaseUrl, apiProtocol);
|
|
417
|
+
const custom = config.connection === "custom";
|
|
367
418
|
await NodeFSP.mkdir(config.homePath, { recursive: true });
|
|
368
419
|
const directory = await NodeFSP.mkdtemp(NodePath2.join(config.homePath, "launch-"));
|
|
369
420
|
try {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
421
|
+
if (custom)
|
|
422
|
+
await NodeFSP.writeFile(
|
|
423
|
+
NodePath2.join(directory, "models.json"),
|
|
424
|
+
JSON.stringify({
|
|
425
|
+
providers: {
|
|
426
|
+
[CUSTOM_PROVIDER]: {
|
|
427
|
+
baseUrl: nativeApiBaseUrl(config.apiBaseUrl, config.apiProtocol),
|
|
428
|
+
api: config.apiProtocol,
|
|
429
|
+
apiKey: `\${${PI_API_KEY_ENV}}`,
|
|
430
|
+
models: config.models.map((id) => ({ id }))
|
|
431
|
+
}
|
|
379
432
|
}
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
);
|
|
433
|
+
}),
|
|
434
|
+
{ mode: 384 }
|
|
435
|
+
);
|
|
384
436
|
const servers = Object.fromEntries(
|
|
385
437
|
(input?.mcpServers ?? []).map((server) => {
|
|
386
438
|
const t = server.transport;
|
|
@@ -397,17 +449,16 @@ async function createLaunch(config, input, cursor) {
|
|
|
397
449
|
];
|
|
398
450
|
})
|
|
399
451
|
);
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
);
|
|
452
|
+
const mcpServersPath = NodePath2.join(directory, "mcp.json");
|
|
453
|
+
await NodeFSP.writeFile(mcpServersPath, JSON.stringify({ mcpServers: servers }), {
|
|
454
|
+
mode: 384
|
|
455
|
+
});
|
|
456
|
+
const model = requestedModel(config, input?.modelSelection) ?? config.model;
|
|
405
457
|
const args = [
|
|
406
458
|
"--mode",
|
|
407
459
|
"rpc",
|
|
408
460
|
"--no-approve",
|
|
409
|
-
"--model",
|
|
410
|
-
`ycodium/${requestedModel(config, input?.modelSelection) ?? config.model}`,
|
|
461
|
+
...model ? ["--model", launchModel(config, model)] : [],
|
|
411
462
|
"--no-extensions",
|
|
412
463
|
"--no-skills"
|
|
413
464
|
];
|
|
@@ -415,7 +466,13 @@ async function createLaunch(config, input, cursor) {
|
|
|
415
466
|
await NodeFSP.mkdir(cursor.sessionDirectory, { recursive: true });
|
|
416
467
|
args.push("--session-dir", cursor.sessionDirectory, "--session-id", cursor.sessionId);
|
|
417
468
|
} else args.push("--no-session", "--no-prompt-templates", "--no-context-files");
|
|
469
|
+
const mcpExtension = !custom && Boolean(input?.mcpServers?.length);
|
|
470
|
+
if (mcpExtension)
|
|
471
|
+
await NodeFSP.writeFile(NodePath2.join(directory, "ycodium-mcp.js"), MCP_EXTENSION_SOURCE, {
|
|
472
|
+
mode: 384
|
|
473
|
+
});
|
|
418
474
|
if (input?.mcpServers?.length) args.push("-e", "builtin:mcp", "-e", "builtin:tool-search");
|
|
475
|
+
if (mcpExtension) args.push("-e", NodePath2.join(directory, "ycodium-mcp.js"));
|
|
419
476
|
if (input?.skills)
|
|
420
477
|
for (const name of input.skills.names) {
|
|
421
478
|
const skill = NodePath2.resolve(input.skills.skillsDir, name);
|
|
@@ -424,16 +481,14 @@ async function createLaunch(config, input, cursor) {
|
|
|
424
481
|
throw new Error("Invalid Pi skill path.");
|
|
425
482
|
args.push("--skill", skill);
|
|
426
483
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
...config.environment,
|
|
432
|
-
PI_CODING_AGENT_DIR: directory,
|
|
433
|
-
PI_OFFLINE: "1",
|
|
434
|
-
PI_SKIP_VERSION_CHECK: "1"
|
|
435
|
-
}
|
|
484
|
+
const env = {
|
|
485
|
+
...config.environment,
|
|
486
|
+
PI_OFFLINE: "1",
|
|
487
|
+
PI_SKIP_VERSION_CHECK: "1"
|
|
436
488
|
};
|
|
489
|
+
if (custom) env.PI_CODING_AGENT_DIR = directory;
|
|
490
|
+
else if (mcpExtension) env[PI_MCP_SERVERS_ENV] = mcpServersPath;
|
|
491
|
+
return { directory, args, env };
|
|
437
492
|
} catch (cause) {
|
|
438
493
|
await NodeFSP.rm(directory, { recursive: true, force: true });
|
|
439
494
|
throw cause;
|
|
@@ -1071,7 +1126,7 @@ function createPiInstance(value, host) {
|
|
|
1071
1126
|
runtimeMode: input.runtimeMode,
|
|
1072
1127
|
nativeModeId,
|
|
1073
1128
|
status: "starting",
|
|
1074
|
-
model,
|
|
1129
|
+
...model ? { model } : {},
|
|
1075
1130
|
createdAt: now(),
|
|
1076
1131
|
updatedAt: now(),
|
|
1077
1132
|
resumeCursor: cursor,
|
|
@@ -1107,7 +1162,7 @@ function createPiInstance(value, host) {
|
|
|
1107
1162
|
throw new Error("Pi startup was cancelled.");
|
|
1108
1163
|
}
|
|
1109
1164
|
initializeResumeCursor(cursor, booked.connection.state);
|
|
1110
|
-
const startedModel =
|
|
1165
|
+
const startedModel = modelSlug(config, booked.connection.state.model);
|
|
1111
1166
|
if (startedModel) {
|
|
1112
1167
|
session.model = startedModel;
|
|
1113
1168
|
session.modelSource = "reported";
|
|
@@ -1185,6 +1240,29 @@ function createPiInstance(value, host) {
|
|
|
1185
1240
|
});
|
|
1186
1241
|
try {
|
|
1187
1242
|
const result = record(await conn.rpc.request("get_available_models", {}, combined));
|
|
1243
|
+
if (config.connection === "pi") {
|
|
1244
|
+
const current = modelSlug(config, conn.state.model);
|
|
1245
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1246
|
+
const models2 = (Array.isArray(result.models) ? result.models : []).map(record).map((m) => ({ slug: modelSlug(config, m), name: string(m.name) || string(m.id) })).filter((m) => m.slug && !seen.has(m.slug) && seen.add(m.slug)).map((m) => ({ ...m, isDefault: m.slug === current }));
|
|
1247
|
+
if (!models2.length)
|
|
1248
|
+
return {
|
|
1249
|
+
...nativeMode,
|
|
1250
|
+
installed: true,
|
|
1251
|
+
version,
|
|
1252
|
+
readiness: "error",
|
|
1253
|
+
auth: { status: "unauthenticated" },
|
|
1254
|
+
detail: "Pi has no available models. Run pi in a terminal and sign in with /login, or configure a model provider in Pi.",
|
|
1255
|
+
models: []
|
|
1256
|
+
};
|
|
1257
|
+
return {
|
|
1258
|
+
installed: true,
|
|
1259
|
+
version,
|
|
1260
|
+
readiness: "ready",
|
|
1261
|
+
auth: { status: "unknown" },
|
|
1262
|
+
models: models2,
|
|
1263
|
+
...nativeMode
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1188
1266
|
const models = (Array.isArray(result.models) ? result.models : []).map(record).filter((m) => m.provider === "ycodium" && m.id === config.model).map((m) => ({
|
|
1189
1267
|
slug: config.model,
|
|
1190
1268
|
name: string(m.name) || config.model,
|
|
@@ -1283,9 +1361,9 @@ function createPiInstance(value, host) {
|
|
|
1283
1361
|
try {
|
|
1284
1362
|
if (model !== booked.session.model) {
|
|
1285
1363
|
const switched = record(
|
|
1286
|
-
await conn.rpc.request("set_model",
|
|
1364
|
+
await conn.rpc.request("set_model", nativeModel(config, model), signal)
|
|
1287
1365
|
);
|
|
1288
|
-
const reportedModel =
|
|
1366
|
+
const reportedModel = modelSlug(config, switched);
|
|
1289
1367
|
booked.session.model = reportedModel || model;
|
|
1290
1368
|
if (reportedModel) {
|
|
1291
1369
|
booked.session.modelSource = "reported";
|
|
@@ -1450,7 +1528,7 @@ function createPiInstance(value, host) {
|
|
|
1450
1528
|
// src/index.ts
|
|
1451
1529
|
var index_default = definePlugin({
|
|
1452
1530
|
id: "agent-pi",
|
|
1453
|
-
apiVersion:
|
|
1531
|
+
apiVersion: 60,
|
|
1454
1532
|
executors: [
|
|
1455
1533
|
{
|
|
1456
1534
|
card: PI_CARD,
|
package/locales/en.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"presentation": {
|
|
3
3
|
"name": "Pi",
|
|
4
|
-
"description": "Use Pi in Ycodium with your own model API."
|
|
4
|
+
"description": "Use Pi in Ycodium with its own sign-in and models, or your own model API."
|
|
5
5
|
},
|
|
6
6
|
"setupNote": "Pi runs tools with the permissions of its process; it does not provide a sandbox or per-tool approvals.",
|
|
7
7
|
"connectionNotVerified": "API credentials and model access will be checked on the first request.",
|
|
8
8
|
"connection": {
|
|
9
|
+
"modes": {
|
|
10
|
+
"pi": "Pi's own sign-in and models",
|
|
11
|
+
"custom": "Custom API service"
|
|
12
|
+
},
|
|
9
13
|
"protocolUnknown": "Choose a supported protocol",
|
|
10
14
|
"invalidProtocol": "The saved API protocol is unsupported. Choose one of the supported protocols.",
|
|
11
15
|
"protocols": {
|
|
@@ -25,6 +29,9 @@
|
|
|
25
29
|
"keyRequired": "Enter an API key."
|
|
26
30
|
},
|
|
27
31
|
"form": {
|
|
32
|
+
"connection": {
|
|
33
|
+
"title": "Connection"
|
|
34
|
+
},
|
|
28
35
|
"apiProtocol": {
|
|
29
36
|
"title": "API protocol"
|
|
30
37
|
},
|
package/locales/zh-CN.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"presentation": {
|
|
3
3
|
"name": "Pi",
|
|
4
|
-
"description": "在 Ycodium 里使用 Pi
|
|
4
|
+
"description": "在 Ycodium 里使用 Pi,用 Pi 自己的登录和模型,或接你自己的模型 API。"
|
|
5
5
|
},
|
|
6
6
|
"setupNote": "Pi 按进程权限执行工具,不提供沙箱或逐工具审批。",
|
|
7
7
|
"connectionNotVerified": "首次请求时将验证 API 凭据和模型访问权限。",
|
|
8
8
|
"connection": {
|
|
9
|
+
"modes": {
|
|
10
|
+
"pi": "Pi 自己的登录和模型",
|
|
11
|
+
"custom": "自定义 API 服务"
|
|
12
|
+
},
|
|
9
13
|
"protocolUnknown": "请选择支持的协议",
|
|
10
14
|
"invalidProtocol": "已保存的 API 协议不受支持,请重新选择。",
|
|
11
15
|
"protocols": {
|
|
@@ -25,6 +29,9 @@
|
|
|
25
29
|
"keyRequired": "请填写 API Key。"
|
|
26
30
|
},
|
|
27
31
|
"form": {
|
|
32
|
+
"connection": {
|
|
33
|
+
"title": "连接方式"
|
|
34
|
+
},
|
|
28
35
|
"apiProtocol": {
|
|
29
36
|
"title": "API 协议"
|
|
30
37
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/agent-pi",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3799",
|
|
4
4
|
"description": "Pi executor over the native RPC protocol.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ycodium",
|
|
@@ -30,15 +30,15 @@
|
|
|
30
30
|
"tailwindcss": "^4.0.0",
|
|
31
31
|
"typescript": "~6.0.3",
|
|
32
32
|
"vite-plus": "0.2.2",
|
|
33
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
34
|
-
"ycodium
|
|
35
|
-
"
|
|
33
|
+
"@ycodium-ai/plugin-api": "0.2.3799",
|
|
34
|
+
"@ycodium/contracts": "0.0.33",
|
|
35
|
+
"ycodium-executor-testing": "0.0.0"
|
|
36
36
|
},
|
|
37
37
|
"ycodium": {
|
|
38
38
|
"plugin": "./dist/index.js",
|
|
39
39
|
"displayName": "Pi",
|
|
40
40
|
"displayNameKey": "presentation.name",
|
|
41
|
-
"description": "Use Pi in Ycodium with your own model API.",
|
|
41
|
+
"description": "Use Pi in Ycodium with its own sign-in and models, or your own model API.",
|
|
42
42
|
"descriptionKey": "presentation.description",
|
|
43
43
|
"icon": "./assets/icon.svg",
|
|
44
44
|
"permissions": [
|
|
@@ -55,11 +55,13 @@
|
|
|
55
55
|
"driverKind": "pi",
|
|
56
56
|
"ownedFields": {
|
|
57
57
|
"add": [
|
|
58
|
+
"connection",
|
|
58
59
|
"apiProtocol",
|
|
59
60
|
"apiBaseUrl",
|
|
60
61
|
"model"
|
|
61
62
|
],
|
|
62
63
|
"edit": [
|
|
64
|
+
"connection",
|
|
63
65
|
"apiProtocol",
|
|
64
66
|
"apiBaseUrl",
|
|
65
67
|
"model"
|