@ycodium-ai/agent-pi 0.2.3681 → 0.2.3766

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 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";
@@ -98,6 +104,8 @@ var PI_CARD = {
98
104
  commandName: "pi",
99
105
  launchArgs: "",
100
106
  homeEnvVar: "",
107
+ // 设置表单里留空的格子此刻会用什么,见 index.ts 的同名命令。
108
+ effectiveCommand: "effectiveConfig",
101
109
  environment: [],
102
110
  install: { kind: "npm" },
103
111
  signIn: [],
@@ -673,16 +681,29 @@ var PiTurn = class {
673
681
  model;
674
682
  sessionId;
675
683
  onFinish;
676
- constructor(emit, model, sessionId, onFinish) {
684
+ modelSource;
685
+ constructor(emit, model, sessionId, onFinish, modelSource) {
677
686
  this.emit = emit;
678
687
  this.model = model;
679
688
  this.sessionId = sessionId;
680
689
  this.onFinish = onFinish;
690
+ this.modelSource = modelSource;
681
691
  }
682
692
  start() {
683
693
  if (this.started || this.completed) return;
684
694
  this.started = true;
685
- this.emit("turn.started", { model: this.model }, { turnId: this.id });
695
+ this.emit(
696
+ "turn.started",
697
+ {
698
+ model: this.model,
699
+ ...this.modelSource === void 0 ? {} : { modelSource: this.modelSource }
700
+ },
701
+ { turnId: this.id }
702
+ );
703
+ }
704
+ /** `set_model` 的回包晚于 `turn.started` 才到:把 Pi 报出的实际型号补报给宿主。 */
705
+ reportModel(model) {
706
+ this.emit("thread.metadata.updated", { model, modelSource: "reported" }, { turnId: this.id });
686
707
  }
687
708
  finish(state, errorMessage) {
688
709
  if (this.completed) return;
@@ -1086,6 +1107,11 @@ function createPiInstance(value, host) {
1086
1107
  throw new Error("Pi startup was cancelled.");
1087
1108
  }
1088
1109
  initializeResumeCursor(cursor, booked.connection.state);
1110
+ const startedModel = string(record(booked.connection.state.model).id);
1111
+ if (startedModel) {
1112
+ session.model = startedModel;
1113
+ session.modelSource = "reported";
1114
+ }
1089
1115
  session.status = "idle";
1090
1116
  booked.emit("session.started", {});
1091
1117
  return { ...session };
@@ -1238,11 +1264,17 @@ function createPiInstance(value, host) {
1238
1264
  if (booked.turn) throw new Error("Pi already has an active turn.");
1239
1265
  const cursor = record(booked.session.resumeCursor);
1240
1266
  const model = requested ?? booked.session.model ?? config.model;
1241
- const turn = new PiTurn(booked.emit, model, string(cursor.sessionId), () => {
1242
- if (booked.turn === turn) booked.turn = void 0;
1243
- booked.session.status = "idle";
1244
- booked.session.updatedAt = now();
1245
- });
1267
+ const turn = new PiTurn(
1268
+ booked.emit,
1269
+ model,
1270
+ string(cursor.sessionId),
1271
+ () => {
1272
+ if (booked.turn === turn) booked.turn = void 0;
1273
+ booked.session.status = "idle";
1274
+ booked.session.updatedAt = now();
1275
+ },
1276
+ model === booked.session.model ? booked.session.modelSource : "echo"
1277
+ );
1246
1278
  booked.turn = turn;
1247
1279
  booked.session.status = "running";
1248
1280
  turn.start();
@@ -1250,8 +1282,17 @@ function createPiInstance(value, host) {
1250
1282
  const dispatch = (async () => {
1251
1283
  try {
1252
1284
  if (model !== booked.session.model) {
1253
- await conn.rpc.request("set_model", { provider: "ycodium", modelId: model }, signal);
1254
- booked.session.model = model;
1285
+ const switched = record(
1286
+ await conn.rpc.request("set_model", { provider: "ycodium", modelId: model }, signal)
1287
+ );
1288
+ const reportedModel = string(switched.id);
1289
+ booked.session.model = reportedModel || model;
1290
+ if (reportedModel) {
1291
+ booked.session.modelSource = "reported";
1292
+ turn.reportModel(reportedModel);
1293
+ } else {
1294
+ delete booked.session.modelSource;
1295
+ }
1255
1296
  }
1256
1297
  if (booked.stopping || booked.closing) return turn.finish("interrupted");
1257
1298
  const prompting = conn.rpc.request("prompt", { message: input.input ?? "" }, signal);
@@ -1409,11 +1450,29 @@ function createPiInstance(value, host) {
1409
1450
  // src/index.ts
1410
1451
  var index_default = definePlugin({
1411
1452
  id: "agent-pi",
1412
- apiVersion: 52,
1453
+ apiVersion: 56,
1413
1454
  executors: [
1414
- { card: PI_CARD, createInstance: async (config, host) => createPiInstance(config, host) }
1455
+ {
1456
+ card: PI_CARD,
1457
+ createInstance: async (config, host) => createPiInstance(config, host),
1458
+ lifecycle: [{ kind: "detect", reversible: true }]
1459
+ }
1415
1460
  ],
1416
1461
  activate(ctx) {
1462
+ ctx.command({
1463
+ name: "effectiveConfig",
1464
+ description: "Settings form: the session directory an empty path resolves to.",
1465
+ scope: "read",
1466
+ payloadSchema: EXECUTOR_EFFECTIVE_PAYLOAD_SCHEMA,
1467
+ handle: async (payload) => {
1468
+ const { instanceId } = readExecutorEffectiveRequest(payload);
1469
+ return {
1470
+ homePath: instanceId === void 0 ? { detailKey: "form.homePath.newInstance" } : {
1471
+ value: NodePath3.join(NodeOS2.homedir(), ".pi", "ycodium", identifier(instanceId))
1472
+ }
1473
+ };
1474
+ }
1475
+ });
1417
1476
  ctx.log.info("Pi executor ready");
1418
1477
  }
1419
1478
  });
package/locales/en.json CHANGED
@@ -1,4 +1,8 @@
1
1
  {
2
+ "presentation": {
3
+ "name": "Pi",
4
+ "description": "Use Pi in Ycodium with 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": {
@@ -34,11 +38,12 @@
34
38
  },
35
39
  "binaryPath": {
36
40
  "title": "Pi executable",
37
- "description": "Optional path to Pi 1.4.0 or newer. Uses pi from PATH when empty."
41
+ "description": "Absolute path to Pi 1.4.0 or newer."
38
42
  },
39
43
  "homePath": {
40
44
  "title": "Session directory",
41
- "description": "Optional storage root for this instance. Keep separate instances in separate directories."
45
+ "description": "Optional storage root for this instance. Keep separate instances in separate directories.",
46
+ "newInstance": "A private directory for this provider, created when you add it"
42
47
  }
43
48
  }
44
49
  }
@@ -1,4 +1,8 @@
1
1
  {
2
+ "presentation": {
3
+ "name": "Pi",
4
+ "description": "在 Ycodium 里使用 Pi,接你自己的模型 API。"
5
+ },
2
6
  "setupNote": "Pi 按进程权限执行工具,不提供沙箱或逐工具审批。",
3
7
  "connectionNotVerified": "首次请求时将验证 API 凭据和模型访问权限。",
4
8
  "connection": {
@@ -34,11 +38,12 @@
34
38
  },
35
39
  "binaryPath": {
36
40
  "title": "Pi 程序",
37
- "description": "可选的 Pi 1.4.0 或更高版本程序路径。留空则从 PATH 查找 pi。"
41
+ "description": "Pi 1.4.0 或更高版本程序的绝对路径。"
38
42
  },
39
43
  "homePath": {
40
44
  "title": "会话目录",
41
- "description": "可选的实例存储根目录。不同实例应使用各自的目录。"
45
+ "description": "可选的实例存储根目录。不同实例应使用各自的目录。",
46
+ "newInstance": "添加后为这个 provider 建一个私有目录"
42
47
  }
43
48
  }
44
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ycodium-ai/agent-pi",
3
- "version": "0.2.3681",
3
+ "version": "0.2.3766",
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.3681",
33
+ "@ycodium-ai/plugin-api": "0.2.3766",
34
34
  "ycodium-executor-testing": "0.0.0",
35
35
  "@ycodium/contracts": "0.0.33"
36
36
  },
37
37
  "ycodium": {
38
38
  "plugin": "./dist/index.js",
39
39
  "displayName": "Pi",
40
- "description": "Run Pi with your model API, native session resume and searchable Ycodium tools.",
40
+ "displayNameKey": "presentation.name",
41
+ "description": "Use Pi in Ycodium with your own model API.",
42
+ "descriptionKey": "presentation.description",
41
43
  "icon": "./assets/icon.svg",
42
44
  "permissions": [
43
45
  {