mirror of
https://github.com/harivansh-afk/clanker-agent.git
synced 2026-04-15 07:04:45 +00:00
Merge pull request #276 from getcompanion-ai/fix-package
fix grind package installation
This commit is contained in:
commit
a46e9ede61
2 changed files with 90 additions and 5 deletions
|
|
@ -195,6 +195,10 @@ export class GatewayRuntime {
|
||||||
|
|
||||||
return new Promise<GatewayMessageResult>((resolve) => {
|
return new Promise<GatewayMessageResult>((resolve) => {
|
||||||
managedSession.queue.push({ ...queuedMessage, resolve });
|
managedSession.queue.push({ ...queuedMessage, resolve });
|
||||||
|
this.logSession(
|
||||||
|
managedSession,
|
||||||
|
`queued source=${queuedMessage.request.source ?? "extension"} depth=${managedSession.queue.length}`,
|
||||||
|
);
|
||||||
this.emitState(managedSession);
|
this.emitState(managedSession);
|
||||||
void this.processNext(managedSession);
|
void this.processNext(managedSession);
|
||||||
});
|
});
|
||||||
|
|
@ -274,6 +278,21 @@ export class GatewayRuntime {
|
||||||
return session ? this.createSnapshot(session) : undefined;
|
return session ? this.createSnapshot(session) : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private summarizeText(text: string, maxLength = 96): string {
|
||||||
|
const singleLine = text.replace(/\s+/g, " ").trim();
|
||||||
|
if (singleLine.length <= maxLength) {
|
||||||
|
return singleLine;
|
||||||
|
}
|
||||||
|
return `${singleLine.slice(0, maxLength)}...`;
|
||||||
|
}
|
||||||
|
|
||||||
|
private logSession(
|
||||||
|
managedSession: ManagedGatewaySession,
|
||||||
|
message: string,
|
||||||
|
): void {
|
||||||
|
this.log(`[session] session=${managedSession.sessionKey} ${message}`);
|
||||||
|
}
|
||||||
|
|
||||||
private async getOrLoadExistingSession(
|
private async getOrLoadExistingSession(
|
||||||
sessionKey: string,
|
sessionKey: string,
|
||||||
): Promise<ManagedGatewaySession | null> {
|
): Promise<ManagedGatewaySession | null> {
|
||||||
|
|
@ -353,6 +372,10 @@ export class GatewayRuntime {
|
||||||
|
|
||||||
managedSession.processing = true;
|
managedSession.processing = true;
|
||||||
managedSession.lastActiveAt = Date.now();
|
managedSession.lastActiveAt = Date.now();
|
||||||
|
this.logSession(
|
||||||
|
managedSession,
|
||||||
|
`processing source=${queued.request.source ?? "extension"} remaining=${managedSession.queue.length}`,
|
||||||
|
);
|
||||||
this.emitState(managedSession);
|
this.emitState(managedSession);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -425,6 +448,7 @@ export class GatewayRuntime {
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case "turn_start":
|
case "turn_start":
|
||||||
managedSession.lastActiveAt = Date.now();
|
managedSession.lastActiveAt = Date.now();
|
||||||
|
this.logSession(managedSession, "turn_start");
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "turn_start",
|
type: "turn_start",
|
||||||
sessionKey: managedSession.sessionKey,
|
sessionKey: managedSession.sessionKey,
|
||||||
|
|
@ -432,6 +456,7 @@ export class GatewayRuntime {
|
||||||
return;
|
return;
|
||||||
case "turn_end":
|
case "turn_end":
|
||||||
managedSession.lastActiveAt = Date.now();
|
managedSession.lastActiveAt = Date.now();
|
||||||
|
this.logSession(managedSession, "turn_end");
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "turn_end",
|
type: "turn_end",
|
||||||
sessionKey: managedSession.sessionKey,
|
sessionKey: managedSession.sessionKey,
|
||||||
|
|
@ -476,6 +501,10 @@ export class GatewayRuntime {
|
||||||
managedSession.lastActiveAt = Date.now();
|
managedSession.lastActiveAt = Date.now();
|
||||||
if (event.message.role === "assistant") {
|
if (event.message.role === "assistant") {
|
||||||
managedSession.activeAssistantMessage = null;
|
managedSession.activeAssistantMessage = null;
|
||||||
|
this.logSession(
|
||||||
|
managedSession,
|
||||||
|
`assistant_complete text="${this.summarizeText(extractMessageText(event.message))}"`,
|
||||||
|
);
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "message_complete",
|
type: "message_complete",
|
||||||
sessionKey: managedSession.sessionKey,
|
sessionKey: managedSession.sessionKey,
|
||||||
|
|
@ -499,6 +528,10 @@ export class GatewayRuntime {
|
||||||
return;
|
return;
|
||||||
case "tool_execution_start":
|
case "tool_execution_start":
|
||||||
managedSession.lastActiveAt = Date.now();
|
managedSession.lastActiveAt = Date.now();
|
||||||
|
this.logSession(
|
||||||
|
managedSession,
|
||||||
|
`tool_start name=${event.toolName} call=${event.toolCallId}`,
|
||||||
|
);
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "tool_start",
|
type: "tool_start",
|
||||||
sessionKey: managedSession.sessionKey,
|
sessionKey: managedSession.sessionKey,
|
||||||
|
|
@ -531,6 +564,10 @@ export class GatewayRuntime {
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
this.logSession(
|
||||||
|
managedSession,
|
||||||
|
`tool_complete name=${event.toolName} call=${event.toolCallId} ok=${!event.isError}`,
|
||||||
|
);
|
||||||
this.emit(managedSession, {
|
this.emit(managedSession, {
|
||||||
type: "tool_complete",
|
type: "tool_complete",
|
||||||
sessionKey: managedSession.sessionKey,
|
sessionKey: managedSession.sessionKey,
|
||||||
|
|
@ -656,8 +693,6 @@ export class GatewayRuntime {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.log(`[http] --> ${method} ${path}`);
|
|
||||||
|
|
||||||
if (method === "GET" && path === "/ready") {
|
if (method === "GET" && path === "/ready") {
|
||||||
this.requireAuth(request, response);
|
this.requireAuth(request, response);
|
||||||
if (response.writableEnded) return;
|
if (response.writableEnded) return;
|
||||||
|
|
@ -1101,9 +1136,6 @@ export class GatewayRuntime {
|
||||||
statusCode: number,
|
statusCode: number,
|
||||||
payload: unknown,
|
payload: unknown,
|
||||||
): void {
|
): void {
|
||||||
if (statusCode >= 400) {
|
|
||||||
this.log(`[http] <-- ${statusCode} ${JSON.stringify(payload)}`);
|
|
||||||
}
|
|
||||||
response.statusCode = statusCode;
|
response.statusCode = statusCode;
|
||||||
response.setHeader("content-type", "application/json; charset=utf-8");
|
response.setHeader("content-type", "application/json; charset=utf-8");
|
||||||
response.end(JSON.stringify(payload));
|
response.end(JSON.stringify(payload));
|
||||||
|
|
|
||||||
53
scripts/bundle-sandbox-builtins.mjs
Normal file
53
scripts/bundle-sandbox-builtins.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { mkdir } from "node:fs/promises";
|
||||||
|
import path from "node:path";
|
||||||
|
import { build } from "esbuild";
|
||||||
|
|
||||||
|
const sourceRoot = process.env.PI_BUILTIN_EXTENSIONS_SRC
|
||||||
|
? path.resolve(process.env.PI_BUILTIN_EXTENSIONS_SRC)
|
||||||
|
: path.resolve(process.cwd(), "packages");
|
||||||
|
const outputRoot = process.env.PI_BUILTIN_EXTENSIONS_OUT
|
||||||
|
? path.resolve(process.env.PI_BUILTIN_EXTENSIONS_OUT)
|
||||||
|
: path.resolve(process.cwd(), ".tmp/builtins");
|
||||||
|
|
||||||
|
const entries = [
|
||||||
|
{
|
||||||
|
name: "pi-channels",
|
||||||
|
entry: path.join(sourceRoot, "pi-channels", "src", "index.ts"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pi-teams",
|
||||||
|
entry: path.join(sourceRoot, "pi-teams", "extensions", "index.ts"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pi-grind",
|
||||||
|
entry: path.join(sourceRoot, "pi-grind", "src", "index.ts"),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const external = [
|
||||||
|
"@mariozechner/pi-agent-core",
|
||||||
|
"@mariozechner/pi-ai",
|
||||||
|
"@mariozechner/pi-ai/oauth",
|
||||||
|
"@mariozechner/pi-coding-agent",
|
||||||
|
"@mariozechner/pi-tui",
|
||||||
|
"@sinclair/typebox",
|
||||||
|
];
|
||||||
|
|
||||||
|
await mkdir(outputRoot, { recursive: true });
|
||||||
|
|
||||||
|
for (const { name, entry } of entries) {
|
||||||
|
const outdir = path.join(outputRoot, name);
|
||||||
|
await mkdir(outdir, { recursive: true });
|
||||||
|
await build({
|
||||||
|
entryPoints: [entry],
|
||||||
|
outfile: path.join(outdir, "index.js"),
|
||||||
|
bundle: true,
|
||||||
|
format: "esm",
|
||||||
|
platform: "node",
|
||||||
|
target: "node22",
|
||||||
|
sourcemap: false,
|
||||||
|
logLevel: "info",
|
||||||
|
external,
|
||||||
|
});
|
||||||
|
console.log(`Bundled ${name} -> ${path.join(outdir, "index.js")}`);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue