Replace local utility stubs with fork's adapter-utils imports
- Replace joinPromptSections, stringifyPaperclipWakePayload, and
renderPaperclipWakePrompt with imports from adapter-utils/server-utils
(the fork's renderPaperclipWakePrompt adds execution stage routing,
resume delta sections, and full comment batch rendering)
- Replace local inferOpenAiCompatibleBiller with import from adapter-utils
- Declare sessionManagement using getAdapterSessionManagement("opencode_local")
with fallback defaults for proper session compaction policy
- Add log redaction via redactHomePathUserSegments in streamPodLogs
- Bump peerDependency to >=0.3.1 and version to 0.1.14
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Generated
+3
-3
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
||||
"version": "0.1.13",
|
||||
"version": "0.1.14",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
||||
"version": "0.1.13",
|
||||
"version": "0.1.14",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@kubernetes/client-node": "^1.0.0"
|
||||
@@ -18,7 +18,7 @@
|
||||
"vitest": "^4.1.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@paperclipai/adapter-utils": ">=0.3.0"
|
||||
"@paperclipai/adapter-utils": ">=0.3.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/core": {
|
||||
|
||||
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
||||
"version": "0.1.13",
|
||||
"version": "0.1.14",
|
||||
"description": "Paperclip adapter plugin that runs OpenCode agents as Kubernetes Jobs",
|
||||
"license": "MIT",
|
||||
"type": "module",
|
||||
@@ -26,7 +26,7 @@
|
||||
"@kubernetes/client-node": "^1.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@paperclipai/adapter-utils": ">=0.3.0"
|
||||
"@paperclipai/adapter-utils": ">=0.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@paperclipai/adapter-utils": "^2026.411.0-canary.8",
|
||||
|
||||
+3
-15
@@ -1,12 +1,6 @@
|
||||
import type { AdapterExecutionContext, AdapterExecutionResult } from "@paperclipai/adapter-utils";
|
||||
import { inferOpenAiCompatibleBiller, redactHomePathUserSegments } from "@paperclipai/adapter-utils";
|
||||
import { asString, asNumber, asBoolean, parseObject } from "@paperclipai/adapter-utils/server-utils";
|
||||
|
||||
function inferOpenAiCompatibleBiller(env: Record<string, string>, _fallback: string | null): string | null {
|
||||
if (env.OPENROUTER_API_KEY) return "openrouter";
|
||||
if (env.OPENAI_BASE_URL?.includes("openrouter")) return "openrouter";
|
||||
if (env.OPENAI_API_KEY) return "openai";
|
||||
return null;
|
||||
}
|
||||
import {
|
||||
parseOpenCodeJsonl,
|
||||
isOpenCodeUnknownSessionError,
|
||||
@@ -137,7 +131,7 @@ async function streamPodLogs(
|
||||
|
||||
const writable = new Writable({
|
||||
write(chunk: Buffer, _encoding, callback) {
|
||||
const text = chunk.toString("utf-8");
|
||||
const text = redactHomePathUserSegments(chunk.toString("utf-8"));
|
||||
chunks.push(text);
|
||||
void onLog("stdout", text).then(() => callback(), callback);
|
||||
},
|
||||
@@ -398,13 +392,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
||||
: null;
|
||||
|
||||
const provider = parseModelProvider(model);
|
||||
// Build a minimal env record for biller inference
|
||||
const billerEnv: Record<string, string> = {};
|
||||
for (const key of ["OPENAI_API_KEY", "OPENAI_BASE_URL", "OPENROUTER_API_KEY"]) {
|
||||
const val = process.env[key];
|
||||
if (val) billerEnv[key] = val;
|
||||
}
|
||||
const biller = inferOpenAiCompatibleBiller(billerEnv, null) ?? provider ?? "unknown";
|
||||
const biller = inferOpenAiCompatibleBiller(process.env, null) ?? provider ?? "unknown";
|
||||
|
||||
const parsedError = typeof parsed.errorMessage === "string" ? parsed.errorMessage.trim() : "";
|
||||
const rawExitCode = exitCode;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { ServerAdapterModule } from "@paperclipai/adapter-utils";
|
||||
import { getAdapterSessionManagement } from "@paperclipai/adapter-utils";
|
||||
import { type, models, agentConfigurationDoc } from "../index.js";
|
||||
import { execute } from "./execute.js";
|
||||
import { testEnvironment } from "./test.js";
|
||||
@@ -15,6 +16,16 @@ export function createServerAdapter(): ServerAdapterModule {
|
||||
supportsLocalAgentJwt: true,
|
||||
agentConfigurationDoc,
|
||||
getConfigSchema,
|
||||
sessionManagement: getAdapterSessionManagement("opencode_local") ?? {
|
||||
supportsSessionResume: true,
|
||||
nativeContextManagement: "unknown",
|
||||
defaultSessionCompaction: {
|
||||
enabled: true,
|
||||
maxSessionRuns: 20,
|
||||
maxRawInputTokens: 500_000,
|
||||
maxSessionAgeHours: 24,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,39 +8,10 @@ import {
|
||||
parseObject,
|
||||
buildPaperclipEnv,
|
||||
renderTemplate,
|
||||
joinPromptSections,
|
||||
stringifyPaperclipWakePayload,
|
||||
renderPaperclipWakePrompt,
|
||||
} from "@paperclipai/adapter-utils/server-utils";
|
||||
|
||||
function joinPromptSections(sections: string[], separator = "\n\n"): string {
|
||||
return sections.filter((s) => s.trim().length > 0).join(separator);
|
||||
}
|
||||
|
||||
function stringifyPaperclipWakePayload(wake: unknown): string | null {
|
||||
if (!wake || typeof wake !== "object") return null;
|
||||
try {
|
||||
const json = JSON.stringify(wake);
|
||||
return json === "{}" ? null : json;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function renderPaperclipWakePrompt(wake: unknown, _opts?: { resumedSession?: boolean }): string {
|
||||
if (!wake || typeof wake !== "object") return "";
|
||||
const w = wake as Record<string, unknown>;
|
||||
const reason = typeof w.reason === "string" ? w.reason.trim() : "";
|
||||
const comments = Array.isArray(w.comments) ? w.comments : [];
|
||||
if (!reason && comments.length === 0) return "";
|
||||
const parts: string[] = [];
|
||||
if (reason) parts.push(`Wake reason: ${reason}`);
|
||||
for (const c of comments) {
|
||||
if (typeof c === "object" && c !== null) {
|
||||
const comment = c as Record<string, unknown>;
|
||||
const body = typeof comment.body === "string" ? comment.body.trim() : "";
|
||||
if (body) parts.push(`Comment: ${body}`);
|
||||
}
|
||||
}
|
||||
return parts.join("\n\n");
|
||||
}
|
||||
import type { SelfPodInfo } from "./k8s-client.js";
|
||||
|
||||
export interface JobBuildInput {
|
||||
|
||||
Reference in New Issue
Block a user