@koalaauto/agentchannel 3.31.0 → 3.32.0
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.
- package/dist/src/client.d.ts +15 -1
- package/dist/src/client.js +3 -2
- package/dist/src/runner/runner.d.ts +5 -2
- package/dist/src/runner/runner.js +26 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/package.json +1 -1
package/dist/src/client.d.ts
CHANGED
|
@@ -220,6 +220,19 @@ export interface MentionItem {
|
|
|
220
220
|
thread: Post;
|
|
221
221
|
channel_name: string;
|
|
222
222
|
}
|
|
223
|
+
/** How a mention run went, as the runner tells the hub when it ends it (all optional: an older hub ignores it). */
|
|
224
|
+
export interface MentionOutcome {
|
|
225
|
+
ok?: boolean;
|
|
226
|
+
error?: string;
|
|
227
|
+
/** the agent's last message: its answer when it wrote one but never posted it */
|
|
228
|
+
text?: string;
|
|
229
|
+
/** the last commands that failed: name, what was run, what it printed */
|
|
230
|
+
errors?: {
|
|
231
|
+
name: string;
|
|
232
|
+
input: string;
|
|
233
|
+
output: string;
|
|
234
|
+
}[];
|
|
235
|
+
}
|
|
223
236
|
export interface MentionRun extends MentionItem {
|
|
224
237
|
replies: Post[];
|
|
225
238
|
recent: Post[];
|
|
@@ -491,7 +504,8 @@ export declare class Client {
|
|
|
491
504
|
}>;
|
|
492
505
|
/** Take an @mention: a read-only "mention" run token for its thread. */
|
|
493
506
|
mentionRun(mentionId: string, run_id: string): Promise<MentionRun>;
|
|
494
|
-
|
|
507
|
+
/** The run is over. `outcome` is how it went: the hub says so in the thread when the agent posted nothing there. */
|
|
508
|
+
mentionEnd(mentionId: string, run_id: string, outcome?: MentionOutcome): Promise<any>;
|
|
495
509
|
mentionUsage(mentionId: string, run_id: string, cost_usd: number, estimated: boolean, used?: RunUsed): Promise<any>;
|
|
496
510
|
agentProfile(name: string): Promise<any>;
|
|
497
511
|
/** `ach remember`: a fact or lesson with its source (hub permalink or GitHub URL); toTeam promotes it to the team overview. */
|
package/dist/src/client.js
CHANGED
|
@@ -451,8 +451,9 @@ export class Client {
|
|
|
451
451
|
async mentionRun(mentionId, run_id) {
|
|
452
452
|
return this.ach('POST', `/mentions/${enc(mentionId)}/run`, { run_id });
|
|
453
453
|
}
|
|
454
|
-
|
|
455
|
-
|
|
454
|
+
/** The run is over. `outcome` is how it went: the hub says so in the thread when the agent posted nothing there. */
|
|
455
|
+
async mentionEnd(mentionId, run_id, outcome = {}) {
|
|
456
|
+
return this.ach('POST', `/mentions/${enc(mentionId)}/end`, { run_id, ...outcome });
|
|
456
457
|
}
|
|
457
458
|
async mentionUsage(mentionId, run_id, cost_usd, estimated, used) {
|
|
458
459
|
return this.ach('POST', `/mentions/${enc(mentionId)}/usage`, { run_id, cost_usd, estimated, ...usedBody(used) });
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import type { RuntimeAdapter } from '../adapters/types.js';
|
|
2
|
-
import { type Agent, type Client, type MentionItem, type Message } from '../client.js';
|
|
1
|
+
import type { AdapterResult, RuntimeAdapter } from '../adapters/types.js';
|
|
2
|
+
import { type Agent, type Client, type MentionItem, type MentionOutcome, type Message } from '../client.js';
|
|
3
3
|
import { type Perm } from '../perm.js';
|
|
4
4
|
import { RunnerState } from './state.js';
|
|
5
5
|
import type { Workspace } from './workspace.js';
|
|
6
|
+
import { TraceRecorder } from '../trace.js';
|
|
6
7
|
import { type SandboxStatus } from '../sandboxcheck.js';
|
|
7
8
|
export type RunnerClient = Pick<Client, 'me' | 'inbox' | 'claim' | 'getTask' | 'postMessage' | 'complete' | 'fail' | 'usage' | 'heartbeat' | 'answerRun' | 'endRun'> & Partial<Pick<Client, 'download' | 'channelPosts' | 'mentionRun' | 'mentionEnd' | 'mentionUsage' | 'promptSize' | 'reportSetup' | 'reportRepos' | 'reportRunner' | 'release' | 'putTrace'>>;
|
|
8
9
|
export interface RunnerOptions {
|
|
@@ -92,6 +93,8 @@ export type Job = {
|
|
|
92
93
|
item: MentionItem;
|
|
93
94
|
};
|
|
94
95
|
export declare function jobKey(j: Job): string;
|
|
96
|
+
/** What the hub is told about a mention run that ended: whether it worked, why not, its last words, the commands that failed. */
|
|
97
|
+
export declare function mentionOutcome(result: AdapterResult, reason: Active['reason'], recorder?: TraceRecorder, secrets?: readonly string[]): MentionOutcome;
|
|
95
98
|
interface Active {
|
|
96
99
|
job: Job;
|
|
97
100
|
controller: AbortController;
|
|
@@ -20,6 +20,21 @@ export function jobKey(j) {
|
|
|
20
20
|
return `mention:${j.item.mention.id}`;
|
|
21
21
|
return j.kind === 'answer' ? `answer:${j.question.id}` : `task:${j.taskId}`;
|
|
22
22
|
}
|
|
23
|
+
/** What the hub is told about a mention run that ended: whether it worked, why not, its last words, the commands that failed. */
|
|
24
|
+
export function mentionOutcome(result, reason, recorder, secrets = []) {
|
|
25
|
+
const errors = (recorder?.finish().steps ?? [])
|
|
26
|
+
.filter((s) => s.kind === 'tool' && s.is_error)
|
|
27
|
+
.slice(-3)
|
|
28
|
+
.map((s) => ({ name: s.name ?? 'tool', input: s.input ?? '', output: s.output ?? '' }));
|
|
29
|
+
const error = redact(reason ? `the run was stopped (${reason})` : result.error ?? '', secrets);
|
|
30
|
+
const text = redact(result.finalText ?? '', secrets);
|
|
31
|
+
return {
|
|
32
|
+
ok: !!result.ok && !reason,
|
|
33
|
+
...(error ? { error: error.slice(0, 400) } : {}),
|
|
34
|
+
...(text ? { text: text.slice(0, 6000) } : {}),
|
|
35
|
+
...(errors.length ? { errors } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
23
38
|
const TOKEN_REFRESH_MS = 20 * 3600_000;
|
|
24
39
|
const PRUNE_EVERY_MS = 10 * 60_000;
|
|
25
40
|
/** A gate decision that lets the run go ahead (S1). Anything else rejects. */
|
|
@@ -1097,6 +1112,9 @@ export class Runner {
|
|
|
1097
1112
|
const threadId = run.thread.id;
|
|
1098
1113
|
const rec = { taskId: key, runId, phase: 'running', workdir: this.o.dir, runToken: run.run_token, tokenAt: Date.now(), seen: [] };
|
|
1099
1114
|
const structured = !!this.o.adapter.structuredAnswers;
|
|
1115
|
+
// how it went, told to the hub when the mention is closed: a run that ends with nothing said in the thread is made visible there
|
|
1116
|
+
let outcome = { ok: false, error: 'the run did not finish' };
|
|
1117
|
+
let recorded;
|
|
1100
1118
|
try {
|
|
1101
1119
|
const prompt = buildMentionPrompt({
|
|
1102
1120
|
agentName: me.name,
|
|
@@ -1113,13 +1131,19 @@ export class Runner {
|
|
|
1113
1131
|
const result = await this.execute(rec, entry, prompt, undefined, 'mention', structured ? ANSWER_SCHEMA : undefined, {
|
|
1114
1132
|
threadId,
|
|
1115
1133
|
usage: (cost, est, used) => client.mentionUsage(mid, runId, cost, est, used),
|
|
1134
|
+
recorder: (r) => { recorded = r; },
|
|
1116
1135
|
});
|
|
1136
|
+
outcome = mentionOutcome(result, entry.reason, recorded, [rec.runToken, ...(this.o.secrets ?? []), this.o.cfSecret ?? ''].filter(Boolean));
|
|
1117
1137
|
if (structured && result.ok && !entry.reason)
|
|
1118
1138
|
await this.postStructuredReply(threadId, run.run_token, result.finalText, key);
|
|
1119
1139
|
}
|
|
1140
|
+
catch (e) {
|
|
1141
|
+
outcome = { ok: false, error: String(e?.message ?? e).slice(0, 400) };
|
|
1142
|
+
throw e;
|
|
1143
|
+
}
|
|
1120
1144
|
finally {
|
|
1121
1145
|
if (!this.fatal)
|
|
1122
|
-
await client.mentionEnd?.(mid, runId).catch((e) => this.log(`mention-end ${mid}: ${e?.message ?? e}`));
|
|
1146
|
+
await client.mentionEnd?.(mid, runId, outcome).catch((e) => this.log(`mention-end ${mid}: ${e?.message ?? e}`));
|
|
1123
1147
|
}
|
|
1124
1148
|
}
|
|
1125
1149
|
/** Codex mention runs: the runner posts the reply the agent returned. */
|
|
@@ -1280,6 +1304,7 @@ export class Runner {
|
|
|
1280
1304
|
// the values of the variables handed through (--pass-env) are secrets too: masked wherever a tool prints them
|
|
1281
1305
|
const passed = (this.o.passEnv ?? []).map((n) => process.env[n] ?? '').filter((v) => v.length >= 8);
|
|
1282
1306
|
const recorder = new TraceRecorder([rec.runToken, ...(this.o.secrets ?? []), this.o.cfSecret ?? '', ...passed].filter(Boolean));
|
|
1307
|
+
extra.recorder?.(recorder);
|
|
1283
1308
|
let hb;
|
|
1284
1309
|
hb =
|
|
1285
1310
|
mode === 'work'
|
package/dist/src/version.d.ts
CHANGED
package/dist/src/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koalaauto/agentchannel",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.32.0",
|
|
4
4
|
"description": "Hand work between your team's agents (Claude Code, Codex) and follow it in one panel: the ach CLI, MCP server and runner for AgentChannel v2",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agentchannel",
|