@ycodium-ai/agent-pi 0.2.3710 → 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 +151 -47
- package/locales/en.json +14 -2
- package/locales/zh-CN.json +14 -2
- package/package.json +7 -3
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
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
+
import * as NodeOS2 from "node:os";
|
|
3
|
+
import * as NodePath3 from "node:path";
|
|
2
4
|
import { definePlugin } from "@ycodium-ai/plugin-api";
|
|
5
|
+
import {
|
|
6
|
+
EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
7
|
+
readExecutorEffectiveRequest
|
|
8
|
+
} from "@ycodium-ai/plugin-api/executor";
|
|
3
9
|
|
|
4
10
|
// src/config.ts
|
|
5
11
|
import * as NodeCrypto from "node:crypto";
|
|
@@ -17,6 +23,14 @@ var DEFAULT_PI_API_PROTOCOL = "openai-completions";
|
|
|
17
23
|
function isPiApiProtocol(value) {
|
|
18
24
|
return PI_API_PROTOCOLS.some((protocol) => protocol === value);
|
|
19
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
|
+
}
|
|
20
34
|
function readPiApiProtocol(value) {
|
|
21
35
|
if (value === void 0) return DEFAULT_PI_API_PROTOCOL;
|
|
22
36
|
if (isPiApiProtocol(value)) return value;
|
|
@@ -42,12 +56,16 @@ function parseConfig(value, instanceId) {
|
|
|
42
56
|
const custom = (Array.isArray(config.customModels) ? config.customModels : []).map(
|
|
43
57
|
(entry) => string(typeof entry === "string" ? entry : record(entry).slug).trim()
|
|
44
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";
|
|
45
62
|
return {
|
|
46
63
|
binaryPath: string(config.binaryPath).trim() || "pi",
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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))] : [],
|
|
51
69
|
environment,
|
|
52
70
|
homePath: homePath ? NodePath.resolve(homePath) : NodePath.join(NodeOS.homedir(), ".pi", "ycodium", identifier(instanceId))
|
|
53
71
|
};
|
|
@@ -59,7 +77,24 @@ function nativeApiBaseUrl(baseUrl, apiProtocol) {
|
|
|
59
77
|
if (apiProtocol === "anthropic-messages") url.pathname = url.pathname.replace(/\/v1$/, "");
|
|
60
78
|
return url.toString().replace(/\/$/, "");
|
|
61
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" });
|
|
62
96
|
function validateConnection(config) {
|
|
97
|
+
if (config.connection === "pi") return;
|
|
63
98
|
let url;
|
|
64
99
|
try {
|
|
65
100
|
url = new URL(config.apiBaseUrl);
|
|
@@ -74,13 +109,14 @@ function validateConnection(config) {
|
|
|
74
109
|
function requestedModel(config, selection) {
|
|
75
110
|
const raw = string(record(selection).model).trim();
|
|
76
111
|
if (!raw) return void 0;
|
|
112
|
+
if (config.connection === "pi") {
|
|
113
|
+
nativeModel(config, raw);
|
|
114
|
+
return raw;
|
|
115
|
+
}
|
|
77
116
|
const id = matchCatalogModel(raw, config.models) ?? matchCatalogModel(raw.replace(/^ycodium\//, ""), config.models);
|
|
78
117
|
if (id) return id;
|
|
79
|
-
throw
|
|
80
|
-
|
|
81
|
-
`Pi instance does not list model "${raw}". Choose one of: ${config.models.join(", ")}. Provider setting changes apply after the session restarts.`
|
|
82
|
-
),
|
|
83
|
-
{ 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.`
|
|
84
120
|
);
|
|
85
121
|
}
|
|
86
122
|
function redact(config, value) {
|
|
@@ -98,6 +134,8 @@ var PI_CARD = {
|
|
|
98
134
|
commandName: "pi",
|
|
99
135
|
launchArgs: "",
|
|
100
136
|
homeEnvVar: "",
|
|
137
|
+
// 设置表单里留空的格子此刻会用什么,见 index.ts 的同名命令。
|
|
138
|
+
effectiveCommand: "effectiveConfig",
|
|
101
139
|
environment: [],
|
|
102
140
|
install: { kind: "npm" },
|
|
103
141
|
signIn: [],
|
|
@@ -125,8 +163,21 @@ var PI_CARD = {
|
|
|
125
163
|
configSchema: {
|
|
126
164
|
type: "object",
|
|
127
165
|
additionalProperties: true,
|
|
128
|
-
"x-ycodium-form-order": [
|
|
166
|
+
"x-ycodium-form-order": [
|
|
167
|
+
"connection",
|
|
168
|
+
"apiProtocol",
|
|
169
|
+
"apiBaseUrl",
|
|
170
|
+
"model",
|
|
171
|
+
"binaryPath",
|
|
172
|
+
"homePath"
|
|
173
|
+
],
|
|
129
174
|
properties: {
|
|
175
|
+
// 不给默认值:没存这一项的存量实例按有没有 API 地址判断,见 readPiConnection。
|
|
176
|
+
connection: {
|
|
177
|
+
type: "string",
|
|
178
|
+
enum: PI_CONNECTIONS,
|
|
179
|
+
"x-ycodium-form": { titleKey: "form.connection.title" }
|
|
180
|
+
},
|
|
130
181
|
apiProtocol: {
|
|
131
182
|
type: "string",
|
|
132
183
|
enum: PI_API_PROTOCOLS,
|
|
@@ -324,6 +375,15 @@ var PiRpc = class {
|
|
|
324
375
|
};
|
|
325
376
|
|
|
326
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
|
+
`;
|
|
327
387
|
function resumeCursor(config, input) {
|
|
328
388
|
const stored = record(input.discardResumeCursor ? void 0 : input.resumeCursor);
|
|
329
389
|
const sessionId = string(stored.sessionId);
|
|
@@ -354,25 +414,25 @@ function initializeResumeCursor(cursor, state) {
|
|
|
354
414
|
cursor.sessionFile = sessionFile;
|
|
355
415
|
}
|
|
356
416
|
async function createLaunch(config, input, cursor) {
|
|
357
|
-
const
|
|
358
|
-
const baseUrl = nativeApiBaseUrl(config.apiBaseUrl, apiProtocol);
|
|
417
|
+
const custom = config.connection === "custom";
|
|
359
418
|
await NodeFSP.mkdir(config.homePath, { recursive: true });
|
|
360
419
|
const directory = await NodeFSP.mkdtemp(NodePath2.join(config.homePath, "launch-"));
|
|
361
420
|
try {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
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
|
+
}
|
|
371
432
|
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
);
|
|
433
|
+
}),
|
|
434
|
+
{ mode: 384 }
|
|
435
|
+
);
|
|
376
436
|
const servers = Object.fromEntries(
|
|
377
437
|
(input?.mcpServers ?? []).map((server) => {
|
|
378
438
|
const t = server.transport;
|
|
@@ -389,17 +449,16 @@ async function createLaunch(config, input, cursor) {
|
|
|
389
449
|
];
|
|
390
450
|
})
|
|
391
451
|
);
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
);
|
|
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;
|
|
397
457
|
const args = [
|
|
398
458
|
"--mode",
|
|
399
459
|
"rpc",
|
|
400
460
|
"--no-approve",
|
|
401
|
-
"--model",
|
|
402
|
-
`ycodium/${requestedModel(config, input?.modelSelection) ?? config.model}`,
|
|
461
|
+
...model ? ["--model", launchModel(config, model)] : [],
|
|
403
462
|
"--no-extensions",
|
|
404
463
|
"--no-skills"
|
|
405
464
|
];
|
|
@@ -407,7 +466,13 @@ async function createLaunch(config, input, cursor) {
|
|
|
407
466
|
await NodeFSP.mkdir(cursor.sessionDirectory, { recursive: true });
|
|
408
467
|
args.push("--session-dir", cursor.sessionDirectory, "--session-id", cursor.sessionId);
|
|
409
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
|
+
});
|
|
410
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"));
|
|
411
476
|
if (input?.skills)
|
|
412
477
|
for (const name of input.skills.names) {
|
|
413
478
|
const skill = NodePath2.resolve(input.skills.skillsDir, name);
|
|
@@ -416,16 +481,14 @@ async function createLaunch(config, input, cursor) {
|
|
|
416
481
|
throw new Error("Invalid Pi skill path.");
|
|
417
482
|
args.push("--skill", skill);
|
|
418
483
|
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
...config.environment,
|
|
424
|
-
PI_CODING_AGENT_DIR: directory,
|
|
425
|
-
PI_OFFLINE: "1",
|
|
426
|
-
PI_SKIP_VERSION_CHECK: "1"
|
|
427
|
-
}
|
|
484
|
+
const env = {
|
|
485
|
+
...config.environment,
|
|
486
|
+
PI_OFFLINE: "1",
|
|
487
|
+
PI_SKIP_VERSION_CHECK: "1"
|
|
428
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 };
|
|
429
492
|
} catch (cause) {
|
|
430
493
|
await NodeFSP.rm(directory, { recursive: true, force: true });
|
|
431
494
|
throw cause;
|
|
@@ -1063,7 +1126,7 @@ function createPiInstance(value, host) {
|
|
|
1063
1126
|
runtimeMode: input.runtimeMode,
|
|
1064
1127
|
nativeModeId,
|
|
1065
1128
|
status: "starting",
|
|
1066
|
-
model,
|
|
1129
|
+
...model ? { model } : {},
|
|
1067
1130
|
createdAt: now(),
|
|
1068
1131
|
updatedAt: now(),
|
|
1069
1132
|
resumeCursor: cursor,
|
|
@@ -1099,7 +1162,7 @@ function createPiInstance(value, host) {
|
|
|
1099
1162
|
throw new Error("Pi startup was cancelled.");
|
|
1100
1163
|
}
|
|
1101
1164
|
initializeResumeCursor(cursor, booked.connection.state);
|
|
1102
|
-
const startedModel =
|
|
1165
|
+
const startedModel = modelSlug(config, booked.connection.state.model);
|
|
1103
1166
|
if (startedModel) {
|
|
1104
1167
|
session.model = startedModel;
|
|
1105
1168
|
session.modelSource = "reported";
|
|
@@ -1177,6 +1240,29 @@ function createPiInstance(value, host) {
|
|
|
1177
1240
|
});
|
|
1178
1241
|
try {
|
|
1179
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
|
+
}
|
|
1180
1266
|
const models = (Array.isArray(result.models) ? result.models : []).map(record).filter((m) => m.provider === "ycodium" && m.id === config.model).map((m) => ({
|
|
1181
1267
|
slug: config.model,
|
|
1182
1268
|
name: string(m.name) || config.model,
|
|
@@ -1275,9 +1361,9 @@ function createPiInstance(value, host) {
|
|
|
1275
1361
|
try {
|
|
1276
1362
|
if (model !== booked.session.model) {
|
|
1277
1363
|
const switched = record(
|
|
1278
|
-
await conn.rpc.request("set_model",
|
|
1364
|
+
await conn.rpc.request("set_model", nativeModel(config, model), signal)
|
|
1279
1365
|
);
|
|
1280
|
-
const reportedModel =
|
|
1366
|
+
const reportedModel = modelSlug(config, switched);
|
|
1281
1367
|
booked.session.model = reportedModel || model;
|
|
1282
1368
|
if (reportedModel) {
|
|
1283
1369
|
booked.session.modelSource = "reported";
|
|
@@ -1442,11 +1528,29 @@ function createPiInstance(value, host) {
|
|
|
1442
1528
|
// src/index.ts
|
|
1443
1529
|
var index_default = definePlugin({
|
|
1444
1530
|
id: "agent-pi",
|
|
1445
|
-
apiVersion:
|
|
1531
|
+
apiVersion: 60,
|
|
1446
1532
|
executors: [
|
|
1447
|
-
{
|
|
1533
|
+
{
|
|
1534
|
+
card: PI_CARD,
|
|
1535
|
+
createInstance: async (config, host) => createPiInstance(config, host),
|
|
1536
|
+
lifecycle: [{ kind: "detect", reversible: true }]
|
|
1537
|
+
}
|
|
1448
1538
|
],
|
|
1449
1539
|
activate(ctx) {
|
|
1540
|
+
ctx.command({
|
|
1541
|
+
name: "effectiveConfig",
|
|
1542
|
+
description: "Settings form: the session directory an empty path resolves to.",
|
|
1543
|
+
scope: "read",
|
|
1544
|
+
payloadSchema: EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
|
|
1545
|
+
handle: async (payload) => {
|
|
1546
|
+
const { instanceId } = readExecutorEffectiveRequest(payload);
|
|
1547
|
+
return {
|
|
1548
|
+
homePath: instanceId === void 0 ? { detailKey: "form.homePath.newInstance" } : {
|
|
1549
|
+
value: NodePath3.join(NodeOS2.homedir(), ".pi", "ycodium", identifier(instanceId))
|
|
1550
|
+
}
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
});
|
|
1450
1554
|
ctx.log.info("Pi executor ready");
|
|
1451
1555
|
}
|
|
1452
1556
|
});
|
package/locales/en.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
+
"presentation": {
|
|
3
|
+
"name": "Pi",
|
|
4
|
+
"description": "Use Pi in Ycodium with its own sign-in and models, or your own model API."
|
|
5
|
+
},
|
|
2
6
|
"setupNote": "Pi runs tools with the permissions of its process; it does not provide a sandbox or per-tool approvals.",
|
|
3
7
|
"connectionNotVerified": "API credentials and model access will be checked on the first request.",
|
|
4
8
|
"connection": {
|
|
9
|
+
"modes": {
|
|
10
|
+
"pi": "Pi's own sign-in and models",
|
|
11
|
+
"custom": "Custom API service"
|
|
12
|
+
},
|
|
5
13
|
"protocolUnknown": "Choose a supported protocol",
|
|
6
14
|
"invalidProtocol": "The saved API protocol is unsupported. Choose one of the supported protocols.",
|
|
7
15
|
"protocols": {
|
|
@@ -21,6 +29,9 @@
|
|
|
21
29
|
"keyRequired": "Enter an API key."
|
|
22
30
|
},
|
|
23
31
|
"form": {
|
|
32
|
+
"connection": {
|
|
33
|
+
"title": "Connection"
|
|
34
|
+
},
|
|
24
35
|
"apiProtocol": {
|
|
25
36
|
"title": "API protocol"
|
|
26
37
|
},
|
|
@@ -34,11 +45,12 @@
|
|
|
34
45
|
},
|
|
35
46
|
"binaryPath": {
|
|
36
47
|
"title": "Pi executable",
|
|
37
|
-
"description": "
|
|
48
|
+
"description": "Absolute path to Pi 1.4.0 or newer."
|
|
38
49
|
},
|
|
39
50
|
"homePath": {
|
|
40
51
|
"title": "Session directory",
|
|
41
|
-
"description": "Optional storage root for this instance. Keep separate instances in separate directories."
|
|
52
|
+
"description": "Optional storage root for this instance. Keep separate instances in separate directories.",
|
|
53
|
+
"newInstance": "A private directory for this provider, created when you add it"
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
56
|
}
|
package/locales/zh-CN.json
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
{
|
|
2
|
+
"presentation": {
|
|
3
|
+
"name": "Pi",
|
|
4
|
+
"description": "在 Ycodium 里使用 Pi,用 Pi 自己的登录和模型,或接你自己的模型 API。"
|
|
5
|
+
},
|
|
2
6
|
"setupNote": "Pi 按进程权限执行工具,不提供沙箱或逐工具审批。",
|
|
3
7
|
"connectionNotVerified": "首次请求时将验证 API 凭据和模型访问权限。",
|
|
4
8
|
"connection": {
|
|
9
|
+
"modes": {
|
|
10
|
+
"pi": "Pi 自己的登录和模型",
|
|
11
|
+
"custom": "自定义 API 服务"
|
|
12
|
+
},
|
|
5
13
|
"protocolUnknown": "请选择支持的协议",
|
|
6
14
|
"invalidProtocol": "已保存的 API 协议不受支持,请重新选择。",
|
|
7
15
|
"protocols": {
|
|
@@ -21,6 +29,9 @@
|
|
|
21
29
|
"keyRequired": "请填写 API Key。"
|
|
22
30
|
},
|
|
23
31
|
"form": {
|
|
32
|
+
"connection": {
|
|
33
|
+
"title": "连接方式"
|
|
34
|
+
},
|
|
24
35
|
"apiProtocol": {
|
|
25
36
|
"title": "API 协议"
|
|
26
37
|
},
|
|
@@ -34,11 +45,12 @@
|
|
|
34
45
|
},
|
|
35
46
|
"binaryPath": {
|
|
36
47
|
"title": "Pi 程序",
|
|
37
|
-
"description": "
|
|
48
|
+
"description": "Pi 1.4.0 或更高版本程序的绝对路径。"
|
|
38
49
|
},
|
|
39
50
|
"homePath": {
|
|
40
51
|
"title": "会话目录",
|
|
41
|
-
"description": "可选的实例存储根目录。不同实例应使用各自的目录。"
|
|
52
|
+
"description": "可选的实例存储根目录。不同实例应使用各自的目录。",
|
|
53
|
+
"newInstance": "添加后为这个 provider 建一个私有目录"
|
|
42
54
|
}
|
|
43
55
|
}
|
|
44
56
|
}
|
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,14 +30,16 @@
|
|
|
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.
|
|
33
|
+
"@ycodium-ai/plugin-api": "0.2.3799",
|
|
34
34
|
"@ycodium/contracts": "0.0.33",
|
|
35
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 its own sign-in and models, or your own model API.",
|
|
42
|
+
"descriptionKey": "presentation.description",
|
|
41
43
|
"icon": "./assets/icon.svg",
|
|
42
44
|
"permissions": [
|
|
43
45
|
{
|
|
@@ -53,11 +55,13 @@
|
|
|
53
55
|
"driverKind": "pi",
|
|
54
56
|
"ownedFields": {
|
|
55
57
|
"add": [
|
|
58
|
+
"connection",
|
|
56
59
|
"apiProtocol",
|
|
57
60
|
"apiBaseUrl",
|
|
58
61
|
"model"
|
|
59
62
|
],
|
|
60
63
|
"edit": [
|
|
64
|
+
"connection",
|
|
61
65
|
"apiProtocol",
|
|
62
66
|
"apiBaseUrl",
|
|
63
67
|
"model"
|