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",
|
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
||||||
"version": "0.1.13",
|
"version": "0.1.14",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
||||||
"version": "0.1.13",
|
"version": "0.1.14",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kubernetes/client-node": "^1.0.0"
|
"@kubernetes/client-node": "^1.0.0"
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
"vitest": "^4.1.4"
|
"vitest": "^4.1.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@paperclipai/adapter-utils": ">=0.3.0"
|
"@paperclipai/adapter-utils": ">=0.3.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@emnapi/core": {
|
"node_modules/@emnapi/core": {
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@farhoodliquor/paperclip-adapter-opencode-k8s",
|
"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",
|
"description": "Paperclip adapter plugin that runs OpenCode agents as Kubernetes Jobs",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"@kubernetes/client-node": "^1.0.0"
|
"@kubernetes/client-node": "^1.0.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@paperclipai/adapter-utils": ">=0.3.0"
|
"@paperclipai/adapter-utils": ">=0.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@paperclipai/adapter-utils": "^2026.411.0-canary.8",
|
"@paperclipai/adapter-utils": "^2026.411.0-canary.8",
|
||||||
|
|||||||
+3
-15
@@ -1,12 +1,6 @@
|
|||||||
import type { AdapterExecutionContext, AdapterExecutionResult } from "@paperclipai/adapter-utils";
|
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";
|
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 {
|
import {
|
||||||
parseOpenCodeJsonl,
|
parseOpenCodeJsonl,
|
||||||
isOpenCodeUnknownSessionError,
|
isOpenCodeUnknownSessionError,
|
||||||
@@ -137,7 +131,7 @@ async function streamPodLogs(
|
|||||||
|
|
||||||
const writable = new Writable({
|
const writable = new Writable({
|
||||||
write(chunk: Buffer, _encoding, callback) {
|
write(chunk: Buffer, _encoding, callback) {
|
||||||
const text = chunk.toString("utf-8");
|
const text = redactHomePathUserSegments(chunk.toString("utf-8"));
|
||||||
chunks.push(text);
|
chunks.push(text);
|
||||||
void onLog("stdout", text).then(() => callback(), callback);
|
void onLog("stdout", text).then(() => callback(), callback);
|
||||||
},
|
},
|
||||||
@@ -398,13 +392,7 @@ export async function execute(ctx: AdapterExecutionContext): Promise<AdapterExec
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
const provider = parseModelProvider(model);
|
const provider = parseModelProvider(model);
|
||||||
// Build a minimal env record for biller inference
|
const biller = inferOpenAiCompatibleBiller(process.env, null) ?? provider ?? "unknown";
|
||||||
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 parsedError = typeof parsed.errorMessage === "string" ? parsed.errorMessage.trim() : "";
|
const parsedError = typeof parsed.errorMessage === "string" ? parsed.errorMessage.trim() : "";
|
||||||
const rawExitCode = exitCode;
|
const rawExitCode = exitCode;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { ServerAdapterModule } from "@paperclipai/adapter-utils";
|
import type { ServerAdapterModule } from "@paperclipai/adapter-utils";
|
||||||
|
import { getAdapterSessionManagement } from "@paperclipai/adapter-utils";
|
||||||
import { type, models, agentConfigurationDoc } from "../index.js";
|
import { type, models, agentConfigurationDoc } from "../index.js";
|
||||||
import { execute } from "./execute.js";
|
import { execute } from "./execute.js";
|
||||||
import { testEnvironment } from "./test.js";
|
import { testEnvironment } from "./test.js";
|
||||||
@@ -15,6 +16,16 @@ export function createServerAdapter(): ServerAdapterModule {
|
|||||||
supportsLocalAgentJwt: true,
|
supportsLocalAgentJwt: true,
|
||||||
agentConfigurationDoc,
|
agentConfigurationDoc,
|
||||||
getConfigSchema,
|
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,
|
parseObject,
|
||||||
buildPaperclipEnv,
|
buildPaperclipEnv,
|
||||||
renderTemplate,
|
renderTemplate,
|
||||||
|
joinPromptSections,
|
||||||
|
stringifyPaperclipWakePayload,
|
||||||
|
renderPaperclipWakePrompt,
|
||||||
} from "@paperclipai/adapter-utils/server-utils";
|
} 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";
|
import type { SelfPodInfo } from "./k8s-client.js";
|
||||||
|
|
||||||
export interface JobBuildInput {
|
export interface JobBuildInput {
|
||||||
|
|||||||
Reference in New Issue
Block a user