feat: publish standalone Pi connect extension

This commit is contained in:
Chengdong Zhang
2026-07-27 17:59:14 +08:00
parent 5e743418bd
commit 96ecccc287
9 changed files with 3360 additions and 16 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
dist/
node_modules/

View File

@@ -1,9 +1,9 @@
# Connect Local Pi Extension # Connect Local Pi Extension
Install with official Pi: Install with Pi:
```bash ```bash
pi install git:git@github.com:your-org/agentic-chat-core.git#packages/connect-local pi install https://github-cli.corp.ebay.com/adsguidance/agentic-chat-connect.git
``` ```
Prerequisite: [Pi coding agent](https://www.npmjs.com/package/@earendil-works/pi-coding-agent) installed globally or in your environment. Prerequisite: [Pi coding agent](https://www.npmjs.com/package/@earendil-works/pi-coding-agent) installed globally or in your environment.

3301
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,13 +1,12 @@
{ {
"name": "@pi-platform/connect-local", "name": "agentic-chat-connect",
"version": "0.1.18", "version": "0.1.0",
"private": true, "private": true,
"type": "module", "type": "module",
"keywords": ["pi-package"], "keywords": ["pi-package"],
"main": "./dist/index.js", "types": "./src/index.ts",
"types": "./dist/index.d.ts",
"pi": { "pi": {
"extensions": ["./dist/index.js"] "extensions": ["./src/index.ts"]
}, },
"scripts": { "scripts": {
"build": "tsc", "build": "tsc",
@@ -15,12 +14,14 @@
"test": "vitest run" "test": "vitest run"
}, },
"dependencies": { "dependencies": {
"@earendil-works/pi-coding-agent": "^0.80.10", "ws": "^8.21.1",
"@pi-platform/shared": "*", "zod": "^3.25.0 || ^4.0.0"
"ws": "^8.21.1"
}, },
"devDependencies": { "devDependencies": {
"@earendil-works/pi-coding-agent": "^0.80.10",
"@types/node": "^22.0.0",
"@types/ws": "^8.18.1", "@types/ws": "^8.18.1",
"typescript": "^5.4.0",
"vitest": "^4.1.10" "vitest": "^4.1.10"
} }
} }

View File

@@ -1,7 +1,7 @@
import os from 'node:os'; import os from 'node:os';
import path from 'node:path'; import path from 'node:path';
import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from '@earendil-works/pi-coding-agent'; import type { ExtensionAPI, ExtensionCommandContext, ExtensionContext } from '@earendil-works/pi-coding-agent';
import type { LocalAgentServerMessage } from '@pi-platform/shared'; import type { LocalAgentServerMessage } from './localAgentProtocol.js';
import { import {
clearReconnectCredential, clearReconnectCredential,
loadReconnectCredential, loadReconnectCredential,

37
src/localAgentProtocol.ts Normal file
View File

@@ -0,0 +1,37 @@
import { z } from 'zod';
export const DEFAULT_HEARTBEAT_INTERVAL_MS = 15_000;
const pairOkServerMessageSchema = z.object({
type: z.literal('pair.ok'),
projectName: z.string().min(1),
reconnectCredential: z.string().min(1),
connectionEpoch: z.number().int().positive(),
});
const reconnectOkServerMessageSchema = z.object({
type: z.literal('reconnect.ok'),
projectName: z.string().min(1),
connectionEpoch: z.number().int().positive(),
});
const taskDispatchServerMessageSchema = z.object({
type: z.literal('task.dispatch'),
taskId: z.string().min(1),
prompt: z.string().min(1),
});
const errorServerMessageSchema = z.object({
type: z.literal('error'),
code: z.string().min(1),
message: z.string().min(1),
});
export const localAgentServerMessageSchema = z.discriminatedUnion('type', [
pairOkServerMessageSchema,
reconnectOkServerMessageSchema,
taskDispatchServerMessageSchema,
errorServerMessageSchema,
]);
export type LocalAgentServerMessage = z.infer<typeof localAgentServerMessageSchema>;

View File

@@ -1,6 +1,6 @@
import { EventEmitter } from 'node:events'; import { EventEmitter } from 'node:events';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { DEFAULT_HEARTBEAT_INTERVAL_MS } from '@pi-platform/shared'; import { DEFAULT_HEARTBEAT_INTERVAL_MS } from './localAgentProtocol.js';
import { LocalAgentWsClient } from './wsClient.js'; import { LocalAgentWsClient } from './wsClient.js';
let latestSocket: { send: ReturnType<typeof vi.fn>; close: () => void } | undefined; let latestSocket: { send: ReturnType<typeof vi.fn>; close: () => void } | undefined;

View File

@@ -2,7 +2,7 @@ import {
DEFAULT_HEARTBEAT_INTERVAL_MS, DEFAULT_HEARTBEAT_INTERVAL_MS,
localAgentServerMessageSchema, localAgentServerMessageSchema,
type LocalAgentServerMessage, type LocalAgentServerMessage,
} from '@pi-platform/shared'; } from './localAgentProtocol.js';
import { WebSocket } from 'ws'; import { WebSocket } from 'ws';
export interface LocalAgentWsClientOptions { export interface LocalAgentWsClientOptions {

View File

@@ -1,10 +1,13 @@
{ {
"extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"skipLibCheck": true,
"outDir": "./dist", "outDir": "./dist",
"rootDir": "./src" "rootDir": "./src"
}, },
"include": ["src"], "include": ["src"],
"exclude": ["src/**/*.test.ts"], "exclude": ["src/**/*.test.ts"]
"references": [{ "path": "../shared" }]
} }