@ycodium-ai/agent-pi 0.2.3681 → 0.2.3710

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -10
  2. package/package.json +4 -4
package/dist/index.js CHANGED
@@ -673,16 +673,29 @@ var PiTurn = class {
673
673
  model;
674
674
  sessionId;
675
675
  onFinish;
676
- constructor(emit, model, sessionId, onFinish) {
676
+ modelSource;
677
+ constructor(emit, model, sessionId, onFinish, modelSource) {
677
678
  this.emit = emit;
678
679
  this.model = model;
679
680
  this.sessionId = sessionId;
680
681
  this.onFinish = onFinish;
682
+ this.modelSource = modelSource;
681
683
  }
682
684
  start() {
683
685
  if (this.started || this.completed) return;
684
686
  this.started = true;
685
- this.emit("turn.started", { model: this.model }, { turnId: this.id });
687
+ this.emit(
688
+ "turn.started",
689
+ {
690
+ model: this.model,
691
+ ...this.modelSource === void 0 ? {} : { modelSource: this.modelSource }
692
+ },
693
+ { turnId: this.id }
694
+ );
695
+ }
696
+ /** `set_model` 的回包晚于 `turn.started` 才到:把 Pi 报出的实际型号补报给宿主。 */
697
+ reportModel(model) {
698
+ this.emit("thread.metadata.updated", { model, modelSource: "reported" }, { turnId: this.id });
686
699
  }
687
700
  finish(state, errorMessage) {
688
701
  if (this.completed) return;
@@ -1086,6 +1099,11 @@ function createPiInstance(value, host) {
1086
1099
  throw new Error("Pi startup was cancelled.");
1087
1100
  }
1088
1101
  initializeResumeCursor(cursor, booked.connection.state);
1102
+ const startedModel = string(record(booked.connection.state.model).id);
1103
+ if (startedModel) {
1104
+ session.model = startedModel;
1105
+ session.modelSource = "reported";
1106
+ }
1089
1107
  session.status = "idle";
1090
1108
  booked.emit("session.started", {});
1091
1109
  return { ...session };
@@ -1238,11 +1256,17 @@ function createPiInstance(value, host) {
1238
1256
  if (booked.turn) throw new Error("Pi already has an active turn.");
1239
1257
  const cursor = record(booked.session.resumeCursor);
1240
1258
  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
- });
1259
+ const turn = new PiTurn(
1260
+ booked.emit,
1261
+ model,
1262
+ string(cursor.sessionId),
1263
+ () => {
1264
+ if (booked.turn === turn) booked.turn = void 0;
1265
+ booked.session.status = "idle";
1266
+ booked.session.updatedAt = now();
1267
+ },
1268
+ model === booked.session.model ? booked.session.modelSource : "echo"
1269
+ );
1246
1270
  booked.turn = turn;
1247
1271
  booked.session.status = "running";
1248
1272
  turn.start();
@@ -1250,8 +1274,17 @@ function createPiInstance(value, host) {
1250
1274
  const dispatch = (async () => {
1251
1275
  try {
1252
1276
  if (model !== booked.session.model) {
1253
- await conn.rpc.request("set_model", { provider: "ycodium", modelId: model }, signal);
1254
- booked.session.model = model;
1277
+ const switched = record(
1278
+ await conn.rpc.request("set_model", { provider: "ycodium", modelId: model }, signal)
1279
+ );
1280
+ const reportedModel = string(switched.id);
1281
+ booked.session.model = reportedModel || model;
1282
+ if (reportedModel) {
1283
+ booked.session.modelSource = "reported";
1284
+ turn.reportModel(reportedModel);
1285
+ } else {
1286
+ delete booked.session.modelSource;
1287
+ }
1255
1288
  }
1256
1289
  if (booked.stopping || booked.closing) return turn.finish("interrupted");
1257
1290
  const prompting = conn.rpc.request("prompt", { message: input.input ?? "" }, signal);
@@ -1409,7 +1442,7 @@ function createPiInstance(value, host) {
1409
1442
  // src/index.ts
1410
1443
  var index_default = definePlugin({
1411
1444
  id: "agent-pi",
1412
- apiVersion: 52,
1445
+ apiVersion: 53,
1413
1446
  executors: [
1414
1447
  { card: PI_CARD, createInstance: async (config, host) => createPiInstance(config, host) }
1415
1448
  ],
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.3710",
4
4
  "description": "Pi executor over the native RPC protocol.",
5
5
  "keywords": [
6
6
  "ycodium",
@@ -30,9 +30,9 @@
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",
34
- "ycodium-executor-testing": "0.0.0",
35
- "@ycodium/contracts": "0.0.33"
33
+ "@ycodium-ai/plugin-api": "0.2.3710",
34
+ "@ycodium/contracts": "0.0.33",
35
+ "ycodium-executor-testing": "0.0.0"
36
36
  },
37
37
  "ycodium": {
38
38
  "plugin": "./dist/index.js",