loopengine 0.4.1 → 0.4.2
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/core/audit-store.d.ts +23 -1
- package/dist/core/audit-store.js +112 -3
- package/dist/core/durable-approvals.d.ts +28 -2
- package/dist/core/durable-approvals.js +113 -3
- package/dist/core/messaging/threads.d.ts +3 -2
- package/dist/core/messaging/threads.js +85 -6
- package/dist/core/run-agent.js +2 -0
- package/dist/core/session-store.d.ts +35 -3
- package/dist/core/session-store.js +81 -3
- package/dist/core/usage.d.ts +11 -0
- package/dist/core/usage.js +51 -3
- package/dist/core/workflow-runs.d.ts +6 -0
- package/dist/core/workflow-runs.js +11 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models.yaml +58 -0
- package/dist/web/agents-config-page.js +115 -2
- package/dist/web/change-log.d.ts +12 -0
- package/dist/web/change-log.js +86 -0
- package/dist/web/global-config.d.ts +20 -0
- package/dist/web/global-config.js +45 -3
- package/dist/web/inbox-admin.d.ts +34 -2
- package/dist/web/inbox-admin.js +45 -6
- package/dist/web/inbox-page.js +56 -5
- package/dist/web/workflow-health.d.ts +66 -0
- package/dist/web/workflow-health.js +76 -0
- package/package.json +1 -1
|
@@ -27,8 +27,10 @@
|
|
|
27
27
|
// still serializes concurrent withSession calls for the same sessionId
|
|
28
28
|
// itself (KeyedMutex / a Redis lock), same as before.
|
|
29
29
|
import { randomUUID } from 'node:crypto';
|
|
30
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
30
31
|
import path from 'node:path';
|
|
31
32
|
import { Redis } from 'ioredis';
|
|
33
|
+
import { auditDb } from './audit-store.js';
|
|
32
34
|
import { SessionKnit, FileStorage } from './sessionknit.js';
|
|
33
35
|
/** Serializes async work per key within this process. Good enough for
|
|
34
36
|
* FileSessionStore (single process); RedisSessionStore needs a real
|
|
@@ -141,6 +143,77 @@ export class FileSessionStore extends SessionKnitStore {
|
|
|
141
143
|
super(new FileStorage(dir), (sessionId, fn) => fileMutex.run(path.resolve(dir, sessionId), fn));
|
|
142
144
|
}
|
|
143
145
|
}
|
|
146
|
+
/** SessionKnit Storage in the workspace's database (core/audit-store.ts):
|
|
147
|
+
* one row per entry, with when it was written. A write is durable when
|
|
148
|
+
* it returns, so flush() has nothing to do. A session still in
|
|
149
|
+
* FileStorage's JSONL under `importFrom` is copied in the first time
|
|
150
|
+
* it's read. */
|
|
151
|
+
export class SqliteEntryStorage {
|
|
152
|
+
db;
|
|
153
|
+
importFrom;
|
|
154
|
+
constructor(db, importFrom) {
|
|
155
|
+
this.db = db;
|
|
156
|
+
this.importFrom = importFrom;
|
|
157
|
+
}
|
|
158
|
+
async append(sessionId, entry) {
|
|
159
|
+
this.insert(sessionId, entry, new Date().toISOString());
|
|
160
|
+
}
|
|
161
|
+
insert(sessionId, entry, at) {
|
|
162
|
+
this.db.prepare('INSERT INTO session_entries (session_id, id, parent_id, at, data) VALUES (?, ?, ?, ?, ?)')
|
|
163
|
+
.run(sessionId, entry.id, entry.parentId, at, JSON.stringify(entry.message));
|
|
164
|
+
}
|
|
165
|
+
async flush() { }
|
|
166
|
+
async readAll(sessionId) {
|
|
167
|
+
return (await this.readTimed(sessionId)).map(({ at: _at, ...entry }) => entry);
|
|
168
|
+
}
|
|
169
|
+
/** The entries with when each was written (imported ones: the file's
|
|
170
|
+
* time, the same for each). */
|
|
171
|
+
async readTimed(sessionId) {
|
|
172
|
+
const read = () => this.db.prepare('SELECT id, parent_id, at, data FROM session_entries WHERE session_id = ? ORDER BY seq').all(sessionId);
|
|
173
|
+
let rows = read();
|
|
174
|
+
if (!rows.length && this.importFrom && this.importFile(sessionId))
|
|
175
|
+
rows = read();
|
|
176
|
+
return rows.map((r) => ({ id: r.id, parentId: r.parent_id, message: JSON.parse(r.data), at: r.at }));
|
|
177
|
+
}
|
|
178
|
+
importFile(sessionId) {
|
|
179
|
+
const file = path.join(this.importFrom, `${sessionId.replace(/[/\\]/g, '_')}.jsonl`);
|
|
180
|
+
if (!existsSync(file))
|
|
181
|
+
return false;
|
|
182
|
+
const entries = readFileSync(file, 'utf8').split('\n').filter(Boolean).flatMap((line) => {
|
|
183
|
+
try {
|
|
184
|
+
return [JSON.parse(line)];
|
|
185
|
+
}
|
|
186
|
+
catch {
|
|
187
|
+
return [];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
if (!entries.length)
|
|
191
|
+
return false;
|
|
192
|
+
const at = new Date().toISOString();
|
|
193
|
+
this.db.exec('BEGIN');
|
|
194
|
+
try {
|
|
195
|
+
for (const entry of entries)
|
|
196
|
+
this.insert(sessionId, entry, at);
|
|
197
|
+
this.db.exec('COMMIT');
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
this.db.exec('ROLLBACK');
|
|
201
|
+
throw err;
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/** Sessions in the workspace's database; one process, like
|
|
207
|
+
* FileSessionStore. Sessions in `.sessions` files (`importFrom`) are
|
|
208
|
+
* copied in as they're first read. */
|
|
209
|
+
export class SqliteSessionStore extends SessionKnitStore {
|
|
210
|
+
entries;
|
|
211
|
+
constructor(db, options = {}) {
|
|
212
|
+
const entries = new SqliteEntryStorage(db, options.importFrom);
|
|
213
|
+
super(entries, (sessionId, fn) => fileMutex.run(`sqlite:${sessionId}`, fn));
|
|
214
|
+
this.entries = entries;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
144
217
|
/** SessionKnit Storage backed by a Redis list — one RPUSH per appended
|
|
145
218
|
* entry. Redis is already durable per write, so unlike FileStorage there's
|
|
146
219
|
* nothing to debounce: flush() is a no-op. */
|
|
@@ -260,9 +333,14 @@ export class RedisSessionStore extends SessionKnitStore {
|
|
|
260
333
|
}
|
|
261
334
|
}
|
|
262
335
|
/** Picks the store from environment so adapters don't hardcode a backend:
|
|
263
|
-
* REDIS_URL set -> RedisSessionStore (required once you run >1 instance)
|
|
264
|
-
* otherwise
|
|
336
|
+
* REDIS_URL set -> RedisSessionStore (required once you run >1 instance);
|
|
337
|
+
* otherwise the workspace's database, reading what's in .sessions as
|
|
338
|
+
* each session is first opened; FileSessionStore under .sessions where
|
|
339
|
+
* there's no database. */
|
|
265
340
|
export function createSessionStore() {
|
|
266
341
|
const redisUrl = process.env.REDIS_URL;
|
|
267
|
-
|
|
342
|
+
if (redisUrl)
|
|
343
|
+
return new RedisSessionStore(redisUrl);
|
|
344
|
+
const db = auditDb();
|
|
345
|
+
return db ? new SqliteSessionStore(db, { importFrom: '.sessions' }) : new FileSessionStore('.sessions');
|
|
268
346
|
}
|
package/dist/core/usage.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export interface UsageEvent {
|
|
|
9
9
|
model?: string;
|
|
10
10
|
inputTokens: number;
|
|
11
11
|
outputTokens: number;
|
|
12
|
+
/** How long the call took, retries included. */
|
|
13
|
+
durationMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface UsageRow extends UsageEvent {
|
|
16
|
+
id: number;
|
|
17
|
+
/** What it cost in US dollars, where the model's price is known. */
|
|
18
|
+
costUsd?: number;
|
|
12
19
|
}
|
|
13
20
|
export type UsageSink = (event: UsageEvent) => void;
|
|
14
21
|
/** Replaces the sink for this whole process; undefined turns usage
|
|
@@ -16,3 +23,7 @@ export type UsageSink = (event: UsageEvent) => void;
|
|
|
16
23
|
export declare function setUsageSink(next: UsageSink | undefined): void;
|
|
17
24
|
/** Never throws — a broken sink must not fail the agent's turn. */
|
|
18
25
|
export declare function recordUsage(event: UsageEvent): void;
|
|
26
|
+
/** A session's model calls, oldest first. */
|
|
27
|
+
export declare function sessionUsage(agent: string, sessionId: string): UsageRow[];
|
|
28
|
+
/** Several sessions' model calls, by session, oldest first. */
|
|
29
|
+
export declare function usageBySession(agent: string, sessionIds: string[]): Map<string, UsageRow[]>;
|
package/dist/core/usage.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
// Token usage per model call
|
|
2
|
-
//
|
|
3
|
-
//
|
|
1
|
+
// Token usage per model call. Kept in the workspace's database
|
|
2
|
+
// (core/audit-store.ts) for each run's steps and totals, and also sent
|
|
3
|
+
// to a sink when one is configured with LOOPENGINE_USAGE_LOG (`stdout` for one JSON line per
|
|
4
4
|
// call on stdout, or a file path to append JSON lines to), or in code
|
|
5
5
|
// with setUsageSink() — a host billing for model usage, or anyone
|
|
6
6
|
// wanting a per-agent token count.
|
|
7
7
|
import { appendFileSync } from 'node:fs';
|
|
8
|
+
import { auditDb } from './audit-store.js';
|
|
8
9
|
function sinkFromEnv() {
|
|
9
10
|
const target = process.env.LOOPENGINE_USAGE_LOG;
|
|
10
11
|
if (!target)
|
|
@@ -21,6 +22,15 @@ export function setUsageSink(next) {
|
|
|
21
22
|
}
|
|
22
23
|
/** Never throws — a broken sink must not fail the agent's turn. */
|
|
23
24
|
export function recordUsage(event) {
|
|
25
|
+
const db = auditDb();
|
|
26
|
+
if (db) {
|
|
27
|
+
try {
|
|
28
|
+
db.prepare('INSERT INTO usage (at, agent, tenant, session_id, provider, model, input_tokens, output_tokens, duration_ms) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)').run(event.at, event.agent, event.tenant, event.sessionId ?? null, event.provider ?? null, event.model ?? null, event.inputTokens, event.outputTokens, event.durationMs ?? null);
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.error('[loopengine] could not record usage:', err);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
24
34
|
if (!sink)
|
|
25
35
|
return;
|
|
26
36
|
try {
|
|
@@ -30,3 +40,41 @@ export function recordUsage(event) {
|
|
|
30
40
|
console.error('[loopengine] usage sink failed:', err);
|
|
31
41
|
}
|
|
32
42
|
}
|
|
43
|
+
/** A session's model calls, oldest first. */
|
|
44
|
+
export function sessionUsage(agent, sessionId) {
|
|
45
|
+
const db = auditDb();
|
|
46
|
+
if (!db)
|
|
47
|
+
return [];
|
|
48
|
+
const rows = db.prepare('SELECT * FROM usage WHERE agent = ? AND session_id = ? ORDER BY id').all(agent, sessionId);
|
|
49
|
+
return rows.map(rowOf);
|
|
50
|
+
}
|
|
51
|
+
/** Several sessions' model calls, by session, oldest first. */
|
|
52
|
+
export function usageBySession(agent, sessionIds) {
|
|
53
|
+
const out = new Map();
|
|
54
|
+
const db = auditDb();
|
|
55
|
+
if (!db || !sessionIds.length)
|
|
56
|
+
return out;
|
|
57
|
+
for (let i = 0; i < sessionIds.length; i += 500) {
|
|
58
|
+
const chunk = sessionIds.slice(i, i + 500);
|
|
59
|
+
const rows = db.prepare(`SELECT * FROM usage WHERE agent = ? AND session_id IN (${chunk.map(() => '?').join(', ')}) ORDER BY id`).all(agent, ...chunk);
|
|
60
|
+
for (const r of rows) {
|
|
61
|
+
const row = rowOf(r);
|
|
62
|
+
out.set(row.sessionId, [...(out.get(row.sessionId) ?? []), row]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
67
|
+
function rowOf(r) {
|
|
68
|
+
return {
|
|
69
|
+
id: Number(r.id),
|
|
70
|
+
at: String(r.at),
|
|
71
|
+
agent: String(r.agent),
|
|
72
|
+
tenant: String(r.tenant),
|
|
73
|
+
...(r.session_id ? { sessionId: String(r.session_id) } : {}),
|
|
74
|
+
...(r.provider ? { provider: String(r.provider) } : {}),
|
|
75
|
+
...(r.model ? { model: String(r.model) } : {}),
|
|
76
|
+
inputTokens: Number(r.input_tokens),
|
|
77
|
+
outputTokens: Number(r.output_tokens),
|
|
78
|
+
...(r.duration_ms != null ? { durationMs: Number(r.duration_ms) } : {}),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -128,6 +128,8 @@ export interface RunStore {
|
|
|
128
128
|
bySession?(sessionId: string): Promise<WorkflowRun | undefined>;
|
|
129
129
|
/** Drops what's past keeping, instead of the runner's per-agent cap. */
|
|
130
130
|
prune?(): Promise<void>;
|
|
131
|
+
/** A workflow's runs started at or after `since`, however many. */
|
|
132
|
+
since?(agent: string, workflowId: string, since: string): Promise<WorkflowRun[]>;
|
|
131
133
|
}
|
|
132
134
|
/** One JSON file per run under `<dir>/runs/` — one server process. */
|
|
133
135
|
export declare class FileRunStore implements RunStore {
|
|
@@ -162,6 +164,7 @@ export declare class SqliteRunStore implements RunStore {
|
|
|
162
164
|
workflowId?: string;
|
|
163
165
|
limit?: number;
|
|
164
166
|
}): Promise<WorkflowRun[]>;
|
|
167
|
+
since(agent: string, workflowId: string, since: string): Promise<WorkflowRun[]>;
|
|
165
168
|
bySession(sessionId: string): Promise<WorkflowRun | undefined>;
|
|
166
169
|
get(runId: string): Promise<WorkflowRun | undefined>;
|
|
167
170
|
put(run: WorkflowRun): Promise<void>;
|
|
@@ -179,6 +182,9 @@ export declare function listRuns(agent: string, filter?: {
|
|
|
179
182
|
workflowId?: string;
|
|
180
183
|
limit?: number;
|
|
181
184
|
}): Promise<WorkflowRun[]>;
|
|
185
|
+
/** A workflow's runs started at or after `since` (an ISO time), oldest
|
|
186
|
+
* first; from the console's list where the store keeps no more. */
|
|
187
|
+
export declare function runsSince(agent: string, workflowId: string, since: string): Promise<WorkflowRun[]>;
|
|
182
188
|
/** One of an agent's runs; undefined for another agent's. */
|
|
183
189
|
export declare function getRun(agent: string, runId: string): Promise<WorkflowRun | undefined>;
|
|
184
190
|
export declare function isUnderWay(run: WorkflowRun): boolean;
|
|
@@ -154,6 +154,9 @@ export class SqliteRunStore {
|
|
|
154
154
|
: this.db.prepare('SELECT data FROM runs WHERE agent = ? ORDER BY started_at DESC LIMIT ?').all(agent, limit);
|
|
155
155
|
return rows.map((r) => this.read(r));
|
|
156
156
|
}
|
|
157
|
+
async since(agent, workflowId, since) {
|
|
158
|
+
return this.db.prepare('SELECT data FROM runs WHERE agent = ? AND workflow_id = ? AND started_at >= ? ORDER BY started_at').all(agent, workflowId, since).map((r) => this.read(r));
|
|
159
|
+
}
|
|
157
160
|
async bySession(sessionId) {
|
|
158
161
|
const row = this.db.prepare('SELECT data FROM runs WHERE session_id = ? ORDER BY started_at DESC LIMIT 1').get(sessionId);
|
|
159
162
|
return row ? this.read(row) : undefined;
|
|
@@ -206,6 +209,14 @@ export async function listRuns(agent, filter = {}) {
|
|
|
206
209
|
const runs = (await getRunStore().list()).filter((r) => r.agent === agent && (!filter.workflowId || r.workflow_id === filter.workflowId));
|
|
207
210
|
return filter.limit ? runs.slice(0, filter.limit) : runs;
|
|
208
211
|
}
|
|
212
|
+
/** A workflow's runs started at or after `since` (an ISO time), oldest
|
|
213
|
+
* first; from the console's list where the store keeps no more. */
|
|
214
|
+
export async function runsSince(agent, workflowId, since) {
|
|
215
|
+
const store = getRunStore();
|
|
216
|
+
if (store.since)
|
|
217
|
+
return store.since(agent, workflowId, since);
|
|
218
|
+
return (await listRuns(agent, { workflowId })).filter((r) => r.started_at >= since).reverse();
|
|
219
|
+
}
|
|
209
220
|
/** One of an agent's runs; undefined for another agent's. */
|
|
210
221
|
export async function getRun(agent, runId) {
|
|
211
222
|
if (!/^[A-Za-z0-9_-]+$/.test(runId))
|
package/dist/index.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export { Compactor, TruncatingSummarizer } from './core/compaction.js';
|
|
|
62
62
|
export type { Summarizer, RecoverResult, RecoverAction } from './core/compaction.js';
|
|
63
63
|
export { LLMSummarizer } from './core/llm-summarizer.js';
|
|
64
64
|
export type { LLMSummarizerOptions } from './core/llm-summarizer.js';
|
|
65
|
-
export { createCheckpointStore } from './core/durable-approvals.js';
|
|
65
|
+
export { createCheckpointStore, SqliteCheckpointStore } from './core/durable-approvals.js';
|
|
66
66
|
export type { TurnCheckpoint, CheckpointStore, OutstandingItem } from './core/durable-approvals.js';
|
|
67
67
|
export { addGatewayTool, agentDir, inferAgentNameFromToolUrl, disconnectComposioAccount, describeGatewayTools, listComposioConnections, listComposioTools, loadGatewayToolsFromDir, removeGatewayTool, removeGatewayToolSlug, GatewayToolExistsError, GatewayToolNotFoundError, } from './core/gateway-tools.js';
|
|
68
68
|
export type { GatewayToolEntry, GatewayToolDecision } from './core/gateway-tools.js';
|
package/dist/index.js
CHANGED
|
@@ -59,7 +59,7 @@ export { agentAsTool } from './core/agent-as-tool.js';
|
|
|
59
59
|
export { resumeAgent, loadRules, loadDefaultTools, loadSubagentAsTools, systemTools, systemSkillsDir } from './core/run-agent.js';
|
|
60
60
|
export { Compactor, TruncatingSummarizer } from './core/compaction.js';
|
|
61
61
|
export { LLMSummarizer } from './core/llm-summarizer.js';
|
|
62
|
-
export { createCheckpointStore } from './core/durable-approvals.js';
|
|
62
|
+
export { createCheckpointStore, SqliteCheckpointStore } from './core/durable-approvals.js';
|
|
63
63
|
export { addGatewayTool, agentDir, inferAgentNameFromToolUrl, disconnectComposioAccount, describeGatewayTools, listComposioConnections, listComposioTools, loadGatewayToolsFromDir, removeGatewayTool, removeGatewayToolSlug, GatewayToolExistsError, GatewayToolNotFoundError, } from './core/gateway-tools.js';
|
|
64
64
|
export { connectComposioSource } from './core/mcpplug.js';
|
|
65
65
|
export { ToolLane, buildLanes, runLanes } from './core/toollane.js';
|
package/dist/models.yaml
CHANGED
|
@@ -83,3 +83,61 @@ glm:
|
|
|
83
83
|
- glm-5.3
|
|
84
84
|
- glm-5.2
|
|
85
85
|
- glm-5.1
|
|
86
|
+
|
|
87
|
+
# Prices, in US dollars per million tokens (standard tier, the base rate
|
|
88
|
+
# for shorter prompts), for the cost shown on each case and in a
|
|
89
|
+
# workflow's health. Taken from each provider's pricing page on
|
|
90
|
+
# 2026-11-24. A workspace's models.yaml can set its own, model by model.
|
|
91
|
+
# Not listed: gemini-3.7-flash (not on Google's pricing page).
|
|
92
|
+
# Known changes: gemini-4-argon and gemini-4-carbon double from
|
|
93
|
+
# 2026-12-01, gemini-3.8-flash and gemini-3.6-flash from 2027-01-01.
|
|
94
|
+
# DeepSeek's are its off-peak rates; at peak hours (weekdays 01:00-04:00
|
|
95
|
+
# and 06:00-10:00 UTC) it charges twice these.
|
|
96
|
+
prices:
|
|
97
|
+
openai:
|
|
98
|
+
gpt-6.2-sol: { input: 2.00, cached_input: 0.10, output: 10.00 }
|
|
99
|
+
gpt-6.2-astra: { input: 8.00, cached_input: 0.40, output: 40.00 }
|
|
100
|
+
gpt-6.1-terra: { input: 1.00, cached_input: 0.05, output: 5.00 }
|
|
101
|
+
gpt-6.1-sol: { input: 2.00, cached_input: 0.10, output: 10.00 }
|
|
102
|
+
gpt-6-luna: { input: 0.10, cached_input: 0.01, output: 0.50 }
|
|
103
|
+
gpt-6-sol: { input: 2.00, cached_input: 0.20, output: 10.00 }
|
|
104
|
+
gpt-6-astra: { input: 10.00, cached_input: 1.00, output: 50.00 }
|
|
105
|
+
gpt-5.6-sol: { input: 4.00, cached_input: 0.40, output: 20.00 }
|
|
106
|
+
gpt-5.6-terra: { input: 2.00, cached_input: 0.20, output: 12.00 }
|
|
107
|
+
gpt-5.6-luna: { input: 0.20, cached_input: 0.02, output: 1.20 }
|
|
108
|
+
anthropic:
|
|
109
|
+
claude-fable-5-2: { input: 8, cached_input: 0.20, output: 40 }
|
|
110
|
+
claude-fable-5-1: { input: 10, cached_input: 0.25, output: 50 }
|
|
111
|
+
claude-opus-5-5: { input: 4, cached_input: 0.20, output: 20 }
|
|
112
|
+
claude-sonnet-5-5: { input: 2, cached_input: 0.10, output: 10 }
|
|
113
|
+
claude-haiku-5-5: { input: 0.10, cached_input: 0.01, output: 0.50 }
|
|
114
|
+
gemini:
|
|
115
|
+
gemini-4-neon: { input: 3.00, cached_input: 0.15, output: 15.00 }
|
|
116
|
+
gemini-4-argon: { input: 2.00, cached_input: 0.10, output: 10.00 }
|
|
117
|
+
gemini-4-carbon: { input: 2.00, cached_input: 0.10, output: 10.00 }
|
|
118
|
+
gemini-4-hydrogen: { input: 1.50, cached_input: 0.075, output: 7.50 }
|
|
119
|
+
gemini-3.8-flash: { input: 0.75, cached_input: 0.075, output: 3.75 }
|
|
120
|
+
gemini-3.6-flash: { input: 0.75, cached_input: 0.075, output: 3.75 }
|
|
121
|
+
gemini-3.1-pro-preview: { input: 2.00, cached_input: 0.20, output: 12.00 }
|
|
122
|
+
meta:
|
|
123
|
+
muse-spark-1.3: { input: 1.25, cached_input: 0.15, output: 4.25 }
|
|
124
|
+
muse-wonder: { input: 4.00, cached_input: 0.20, output: 20.00 }
|
|
125
|
+
muse-spark-1.2: { input: 1.25, cached_input: 0.15, output: 4.25 }
|
|
126
|
+
muse-spark-1.1: { input: 1.25, cached_input: 0.15, output: 4.25 }
|
|
127
|
+
xai:
|
|
128
|
+
grok-4.7: { input: 2.00, cached_input: 0.50, output: 6.00 }
|
|
129
|
+
grok-4.6: { input: 2.00, cached_input: 0.50, output: 6.00 }
|
|
130
|
+
grok-4.5: { input: 2.00, cached_input: 0.30, output: 6.00 }
|
|
131
|
+
deepseek:
|
|
132
|
+
deepseek-v4-pro: { input: 0.66, cached_input: 0.022, output: 1.98 }
|
|
133
|
+
deepseek-flash: { input: 0.15, cached_input: 0.003, output: 0.60 }
|
|
134
|
+
# The retired alias still runs as deepseek-flash.
|
|
135
|
+
deepseek-v4-flash: { input: 0.15, cached_input: 0.003, output: 0.60 }
|
|
136
|
+
kimi:
|
|
137
|
+
kimi-k3.1-pro: { input: 2.00, cached_input: 0.20, output: 10.00 }
|
|
138
|
+
kimi-k3: { input: 3.00, cached_input: 0.30, output: 15.00 }
|
|
139
|
+
kimi-k2.7-code: { input: 0.95, cached_input: 0.19, output: 4.00 }
|
|
140
|
+
glm:
|
|
141
|
+
glm-5.3: { input: 1.40, cached_input: 0.26, output: 4.40 }
|
|
142
|
+
glm-5.2: { input: 1.40, cached_input: 0.26, output: 4.40 }
|
|
143
|
+
glm-5.1: { input: 1.40, cached_input: 0.26, output: 4.40 }
|
|
@@ -208,6 +208,20 @@ export const agentsConfigPageHtml = `<!doctype html>
|
|
|
208
208
|
.wf-crit { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
|
|
209
209
|
.wf-crit-kind { font-size: 12px; color: var(--ink-muted); }
|
|
210
210
|
.wf-crit-rate { font-variant-numeric: tabular-nums; }
|
|
211
|
+
.wf-health { display: grid; gap: 12px; margin-bottom: 8px; }
|
|
212
|
+
.wf-health-alert { padding: 10px 12px; border-radius: 8px; background: var(--bad-soft); color: var(--bad); font-size: 13px; font-weight: 600; }
|
|
213
|
+
.wf-health-chart { margin: 0; display: grid; gap: 4px; }
|
|
214
|
+
.wf-health-chart svg { width: 100%; height: 96px; display: block; border-bottom: 1px solid var(--line); }
|
|
215
|
+
.wf-health-chart figcaption { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--ink-faint); }
|
|
216
|
+
.wf-health-table { overflow-x: auto; }
|
|
217
|
+
.wf-health-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
|
|
218
|
+
.wf-health-table th { text-align: left; font-weight: 600; color: var(--ink-muted); padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
|
219
|
+
.wf-health-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
|
220
|
+
.wf-change-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 8px; font-size: 13px; }
|
|
221
|
+
.wf-change-list li { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
|
|
222
|
+
.wf-change-kind { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-faint); min-width: 64px; }
|
|
223
|
+
.wf-change-kind.change { color: var(--accent-ink); }
|
|
224
|
+
.wf-change-text { flex: 1 1 280px; }
|
|
211
225
|
.wf-versions { display: grid; gap: 8px; margin-bottom: 12px; font-size: 13px; }
|
|
212
226
|
.wf-versions[hidden], .wf-versions-list[hidden], .wf-version-text[hidden] { display: none; }
|
|
213
227
|
.wf-versions-line, .wf-versions-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
|
|
@@ -1025,6 +1039,100 @@ ${renderMarkdownScript}
|
|
|
1025
1039
|
for (var i = 0; i < tabs.length; i++) tabs[i].setAttribute('aria-selected', String(tabs[i].dataset.tab === key));
|
|
1026
1040
|
var panels = card.querySelectorAll('.wf-panel');
|
|
1027
1041
|
for (var j = 0; j < panels.length; j++) panels[j].hidden = panels[j].dataset.panel !== key;
|
|
1042
|
+
if (key === 'changes') loadWorkflowChanges(card);
|
|
1043
|
+
}
|
|
1044
|
+
|
|
1045
|
+
// The Health panel: the last 30 days of runs, as totals, day by day and
|
|
1046
|
+
// per brief version, and any alert (a rate that just got worse).
|
|
1047
|
+
function loadWorkflowHealth(card, base) {
|
|
1048
|
+
var box = card.querySelector('.wf-health');
|
|
1049
|
+
if (!box) return;
|
|
1050
|
+
fetch(base + '/health', { headers: { accept: 'application/json' } })
|
|
1051
|
+
.then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
|
|
1052
|
+
.then(function (h) { box.innerHTML = '<h4 class="wf-sub">Health, last ' + h.days + ' days</h4>' + workflowHealthHtml(h); })
|
|
1053
|
+
.catch(function (err) { box.innerHTML = '<h4 class="wf-sub">Health</h4><p class="error">Could not load it: ' + escapeHtml(err.message) + '</p>'; });
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
function healthPct(part, whole) { return whole ? Math.round(100 * part / whole) + '%' : String.fromCharCode(8212); }
|
|
1057
|
+
function healthTime(ms) {
|
|
1058
|
+
if (ms == null) return String.fromCharCode(8212);
|
|
1059
|
+
if (ms < 60000) return (ms / 1000).toFixed(1) + ' s';
|
|
1060
|
+
var min = Math.round(ms / 60000);
|
|
1061
|
+
return min < 60 ? min + ' min' : Math.floor(min / 60) + ' h ' + (min % 60) + ' min';
|
|
1062
|
+
}
|
|
1063
|
+
function healthCost(usd) { return usd == null ? String.fromCharCode(8212) : '$' + (usd >= 0.1 ? usd.toFixed(2) : usd.toFixed(3)); }
|
|
1064
|
+
|
|
1065
|
+
// Runs per day as bars, the failed part of each in red.
|
|
1066
|
+
function healthChartHtml(daily) {
|
|
1067
|
+
var max = 1;
|
|
1068
|
+
daily.forEach(function (d) { if (d.runs > max) max = d.runs; });
|
|
1069
|
+
var w = 600, h = 96, gap = 2, bw = (w - gap * (daily.length - 1)) / daily.length;
|
|
1070
|
+
var bars = daily.map(function (d, i) {
|
|
1071
|
+
var x = (i * (bw + gap)).toFixed(1);
|
|
1072
|
+
var all = d.runs / max * (h - 4), bad = d.failed / max * (h - 4);
|
|
1073
|
+
var tip = '<title>' + escapeHtml(d.date) + ': ' + d.runs + ' run' + (d.runs === 1 ? '' : 's') + (d.failed ? ', ' + d.failed + ' failed' : '') + '</title>';
|
|
1074
|
+
return '<g>' + tip + '<rect x="' + x + '" y="0" width="' + bw.toFixed(1) + '" height="' + h + '" fill="transparent"/>' +
|
|
1075
|
+
(d.runs ? '<rect x="' + x + '" y="' + (h - all).toFixed(1) + '" width="' + bw.toFixed(1) + '" height="' + all.toFixed(1) + '" rx="1.5" fill="var(--accent)" opacity="0.75"/>' : '') +
|
|
1076
|
+
(d.failed ? '<rect x="' + x + '" y="' + (h - bad).toFixed(1) + '" width="' + bw.toFixed(1) + '" height="' + bad.toFixed(1) + '" rx="1.5" fill="var(--bad)"/>' : '') + '</g>';
|
|
1077
|
+
}).join('');
|
|
1078
|
+
var first = daily[0] ? daily[0].date.slice(5) : '', last = daily.length ? daily[daily.length - 1].date.slice(5) : '';
|
|
1079
|
+
return '<figure class="wf-health-chart"><svg viewBox="0 0 ' + w + ' ' + h + '" preserveAspectRatio="none" role="img" aria-label="Runs per day, failed in red">' + bars + '</svg>' +
|
|
1080
|
+
'<figcaption><span>' + escapeHtml(first) + '</span><span class="hint">Runs per day' + DOT + 'failed in red' + DOT + 'most ' + max + '</span><span>' + escapeHtml(last) + '</span></figcaption></figure>';
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
function workflowHealthHtml(h) {
|
|
1084
|
+
var t = h.total;
|
|
1085
|
+
if (!t.runs) return '<p class="hint" style="margin:0">No runs in the last ' + h.days + ' days.</p>';
|
|
1086
|
+
var decided = t.approved + t.denied;
|
|
1087
|
+
var alerts = (h.alerts || []).map(function (a) { return '<div class="wf-health-alert" role="alert">' + escapeHtml(a.text) + '</div>'; }).join('');
|
|
1088
|
+
var stat = function (label, value, detail) { return '<div class="wf-score"><span class="wf-score-k">' + label + '</span><strong class="wf-score-v">' + value + '</strong>' + (detail ? '<span class="hint">' + detail + '</span>' : '') + '</div>'; };
|
|
1089
|
+
var stats = '<div class="wf-scores">' +
|
|
1090
|
+
stat('Runs', String(t.runs), t.failed + ' failed (' + healthPct(t.failed, t.finished) + ')') +
|
|
1091
|
+
stat('Approved', healthPct(t.approved, decided), decided ? t.changed + ' changed first' + DOT + t.denied + ' denied' : 'none asked') +
|
|
1092
|
+
stat('Questions', t.runs ? (t.questions / t.runs).toFixed(1) : '0', 'per run') +
|
|
1093
|
+
stat('Time', healthTime(t.medianMs), 'middle run, start to finish') +
|
|
1094
|
+
stat('Cost', healthCost(t.costPerRunUsd), t.costPerRunUsd == null ? 'no price for its model' : 'per run' + (t.pricedRuns < t.runs ? ', from ' + t.pricedRuns + ' of ' + t.runs + ' runs' : '')) +
|
|
1095
|
+
'</div>';
|
|
1096
|
+
var rows = h.versions.map(function (v) {
|
|
1097
|
+
var d = v.approved + v.denied;
|
|
1098
|
+
return '<tr><td>' + (v.version == null ? '<span class="hint">before versions</span>' : 'v' + v.version) + '</td><td>' + v.runs + '</td><td>' + healthPct(v.failed, v.finished) + '</td><td>' + healthPct(v.approved, d) + '</td><td>' + healthPct(v.changed + v.denied, d) + '</td>' +
|
|
1099
|
+
'<td>' + (v.runs ? (v.questions / v.runs).toFixed(1) : '0') + '</td><td>' + (v.feedback ? healthPct(v.unedited, v.feedback) : String.fromCharCode(8212)) + '</td><td>' + healthTime(v.medianMs) + '</td><td>' + healthCost(v.costPerRunUsd) + '</td></tr>';
|
|
1100
|
+
}).join('');
|
|
1101
|
+
return alerts + stats + healthChartHtml(h.daily) +
|
|
1102
|
+
'<div class="wf-health-table"><table><thead><tr><th>Brief</th><th>Runs</th><th>Failed</th><th>Approved</th><th>Changed or denied</th><th>Questions per run</th><th>Used unedited</th><th>Time</th><th>Cost per run</th></tr></thead><tbody>' + rows + '</tbody></table></div>';
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
// The Changes tab: every change to this workflow's settings, and every
|
|
1106
|
+
// decision, answer and feedback in its runs, newest first, with who.
|
|
1107
|
+
function loadWorkflowChanges(card) {
|
|
1108
|
+
var box = card.querySelector('.wf-changes');
|
|
1109
|
+
if (!box || box.getAttribute('data-loaded') === '1') return;
|
|
1110
|
+
box.setAttribute('data-loaded', '1');
|
|
1111
|
+
var agent = pageParams.get('agent');
|
|
1112
|
+
fetch('/audit?agent=' + encodeURIComponent(agent) + '&workflow=' + encodeURIComponent(card.dataset.workflow) + '&limit=200', { headers: { accept: 'application/json' } })
|
|
1113
|
+
.then(function (r) { return r.ok ? r.json() : r.json().then(function (b) { throw new Error(b.error || 'HTTP ' + r.status); }); })
|
|
1114
|
+
.then(function (data) { box.innerHTML = workflowChangesHtml(data.events || []); })
|
|
1115
|
+
.catch(function (err) { box.setAttribute('data-loaded', '0'); box.innerHTML = '<p class="error">Could not load the changes: ' + escapeHtml(err.message) + '</p>'; });
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
function changeText(e) {
|
|
1119
|
+
var d = e.data || {};
|
|
1120
|
+
if (e.kind === 'change') return escapeHtml(d.label || 'Changed a setting');
|
|
1121
|
+
if (e.kind === 'decision') return (d.approved ? (d.edited ? 'Approved as changed ' : 'Approved ') : 'Denied ') + '<code>' + escapeHtml(d.tool || '') + '</code>' + (d.reason ? ': ' + String.fromCharCode(8220) + escapeHtml(d.reason) + String.fromCharCode(8221) : '');
|
|
1122
|
+
if (e.kind === 'answer') return 'Answered ' + String.fromCharCode(8220) + escapeHtml(String(d.answer || '').slice(0, 200)) + String.fromCharCode(8221);
|
|
1123
|
+
if (e.kind === 'feedback') return 'Feedback: ' + escapeHtml([d.verdict, d.edit ? (d.edit === 'none' ? 'used unedited' : d.edit + ' edits') : '', d.note].filter(Boolean).join(', ') || 'given');
|
|
1124
|
+
return escapeHtml(e.kind);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function workflowChangesHtml(events) {
|
|
1128
|
+
if (!events.length) return '<p class="hint" style="margin:0">Nothing yet. Edits to this workflow' + RSQ + 's settings, and every approval, answer and feedback in its runs, will be listed here with who and when.</p>';
|
|
1129
|
+
return '<ol class="wf-change-list">' + events.map(function (e) {
|
|
1130
|
+
var when = new Date(e.at).toLocaleString(undefined, { month: 'short', day: 'numeric', year: 'numeric', hour: '2-digit', minute: '2-digit' });
|
|
1131
|
+
var kind = e.kind === 'change' ? 'Setting' : e.kind === 'decision' ? 'Decision' : e.kind === 'answer' ? 'Answer' : 'Feedback';
|
|
1132
|
+
return '<li><span class="wf-change-kind ' + escapeHtml(e.kind) + '">' + kind + '</span><span class="wf-change-text">' + changeText(e) + '</span>' +
|
|
1133
|
+
'<span class="hint">' + (e.by ? escapeHtml(e.by) + DOT : '') + escapeHtml(when) +
|
|
1134
|
+
(e.run_id ? DOT + '<a href="/inbox?case=' + encodeURIComponent(e.run_id) + '">case</a>' : '') + '</span></li>';
|
|
1135
|
+
}).join('') + '</ol>';
|
|
1028
1136
|
}
|
|
1029
1137
|
|
|
1030
1138
|
// ---- A workflow in three parts: its contract (what the system holds it
|
|
@@ -1282,7 +1390,9 @@ ${renderMarkdownScript}
|
|
|
1282
1390
|
(last && last.result ? '<div class="workflow-run-entry-label">Latest result' + (last.tools && last.tools.length ? ' <span class="hint">(called ' + escapeHtml(last.tools.join(', ')) + ')</span>' : '') + '</div><div class="workflow-steps-text">' + escapeHtml(last.result) + '</div>' : '') +
|
|
1283
1391
|
'</details></li>';
|
|
1284
1392
|
}).join('');
|
|
1285
|
-
|
|
1393
|
+
// On the workflow's page: its health, filled by loadWorkflowHealth.
|
|
1394
|
+
return (workflowPageId ? '<section class="wf-health"><h4 class="wf-sub">Health, last 30 days</h4><p class="hint" style="margin:0">Loading' + String.fromCharCode(8230) + '</p></section>' : '') +
|
|
1395
|
+
tiles + feedbackHint + critSection +
|
|
1286
1396
|
'<h4 class="wf-sub">Eval cases</h4>' +
|
|
1287
1397
|
'<div class="wf-evals-bar"><button type="button" class="wf-evals-run"' + (!evals.cases.length || running ? ' disabled' : '') + '>' + (running ? 'Running ' + running.done + ' of ' + running.total + String.fromCharCode(8230) : 'Run evals') + '</button>' +
|
|
1288
1398
|
'<span class="hint">' + (round ? 'Last run ' + escapeHtml(new Date(round.at).toLocaleString()) + (round.briefVersion ? DOT + 'brief v' + round.briefVersion : '') + DOT + 'model ' + escapeHtml(round.model) + DOT + 'judged by ' + escapeHtml(round.judge) : 'A test run: tools that need approval aren' + RSQ + 't run, and nobody is asked anything.') + '</span></div>' +
|
|
@@ -1364,12 +1474,13 @@ ${renderMarkdownScript}
|
|
|
1364
1474
|
'</div>' +
|
|
1365
1475
|
'</header>' +
|
|
1366
1476
|
'<div class="wf-row-body wf-page-body">' +
|
|
1367
|
-
'<div class="wf-tabs" role="tablist">' + tabBtn('brief', 'Brief') + tabBtn('evidence', 'Evidence' + (runs ? ' <span class="wf-tab-count">' + w.recentRuns.length + '</span>' : '')) + tabBtn('triggers', 'Triggers') + tabBtn('messages', 'Messages') + tabBtn('contract', 'Contract') + '</div>' +
|
|
1477
|
+
'<div class="wf-tabs" role="tablist">' + tabBtn('brief', 'Brief') + tabBtn('evidence', 'Evidence' + (runs ? ' <span class="wf-tab-count">' + w.recentRuns.length + '</span>' : '')) + tabBtn('triggers', 'Triggers') + tabBtn('messages', 'Messages') + tabBtn('contract', 'Contract') + tabBtn('changes', 'Changes') + '</div>' +
|
|
1368
1478
|
panel('brief', workflowBriefHtml(w)) +
|
|
1369
1479
|
panel('evidence', workflowEvidenceHtml(w, runs)) +
|
|
1370
1480
|
panel('triggers', workflowTriggersHtml(w, name, params)) +
|
|
1371
1481
|
panel('messages', workflowMessagesHtml(w, name)) +
|
|
1372
1482
|
panel('contract', workflowContractHtml(w, name, params)) +
|
|
1483
|
+
panel('changes', '<div class="wf-changes"><span class="hint">Loading' + String.fromCharCode(8230) + '</span></div>') +
|
|
1373
1484
|
'<div class="hint workflow-result"></div>' +
|
|
1374
1485
|
'<div class="wf-row-foot"><span class="hint">ID <code>' + escapeHtml(w.id) + '</code>, used by the API, schedules and webhooks</span><button type="button" class="wf-remove workflow-forget" title="Its schedules and webhooks go; its instructions stay as a skill for Chat">Remove</button></div>' +
|
|
1375
1486
|
'</div>' +
|
|
@@ -2022,6 +2133,8 @@ ${renderMarkdownScript}
|
|
|
2022
2133
|
var tabs = card.querySelectorAll('.wf-tab');
|
|
2023
2134
|
for (var t = 0; t < tabs.length; t++) tabs[t].addEventListener('click', function (ev) { showWorkflowTab(card, ev.currentTarget.dataset.tab); });
|
|
2024
2135
|
loadBriefVersions(card, base);
|
|
2136
|
+
loadWorkflowHealth(card, base);
|
|
2137
|
+
if (workflowTabs[id] === 'changes') loadWorkflowChanges(card);
|
|
2025
2138
|
card.querySelector('.workflow-edit').addEventListener('click', function () { openWorkflowEditor(name, card); });
|
|
2026
2139
|
// Opens the workflow's page on its Triggers tab.
|
|
2027
2140
|
var triggersBtn = card.querySelector('.workflow-triggers-open');
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface Change {
|
|
2
|
+
/** In words: "Edited the workflow", "Changed permissions". */
|
|
3
|
+
label: string;
|
|
4
|
+
agent?: string;
|
|
5
|
+
workflowId?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The change a request makes, or undefined when it doesn't change a
|
|
8
|
+
* setting. */
|
|
9
|
+
export declare function changeOf(method: string, path: string): Change | undefined;
|
|
10
|
+
/** A body as kept in the log: secret-looking fields blanked, long text
|
|
11
|
+
* cut. Secrets' bodies are dropped whole. */
|
|
12
|
+
export declare function keptBody(path: string, body: unknown): unknown;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The workspace's change log: every setting changed in the console or over
|
|
2
|
+
// the API, with who changed it, kept as an audit event of kind "change"
|
|
3
|
+
// (core/audit-store.ts). adapters/http.ts calls changeOf for each request
|
|
4
|
+
// that changes something and records it once the answer is a success.
|
|
5
|
+
//
|
|
6
|
+
// What's a change is decided by path: agents, their workflows, triggers,
|
|
7
|
+
// schedules, permissions, tools, apps, messaging, secrets, and the
|
|
8
|
+
// workspace's settings. Doing work (running, previewing, chatting,
|
|
9
|
+
// deciding, feedback) isn't: decisions and feedback are events of their
|
|
10
|
+
// own. The request's body is kept with anything secret blanked, and the
|
|
11
|
+
// brief's own before and after are its versions.
|
|
12
|
+
// Doing, not changing.
|
|
13
|
+
const NOT_CHANGES = [
|
|
14
|
+
/^\/agents\/[^/]+\/messages(\/stream)?$/,
|
|
15
|
+
/\/(feedback|run|preview|test|evals\/run|criteria\/draft|telegram-webhook|slack-channels|search|install-deps|refresh)$/,
|
|
16
|
+
];
|
|
17
|
+
const LABELS = [
|
|
18
|
+
[/^\/agents$/, 'Added an agent'],
|
|
19
|
+
[/^\/agents\/[^/]+$/, (method) => (method === 'DELETE' ? 'Removed the agent' : 'Changed the agent')],
|
|
20
|
+
[/^\/agents\/[^/]+\/workflows$/, 'Created a workflow'],
|
|
21
|
+
[/^\/agents\/[^/]+\/workflows\/[^/]+$/, (method) => (method === 'DELETE' ? 'Removed the workflow' : 'Edited the workflow')],
|
|
22
|
+
[/^\/agents\/[^/]+\/workflows\/[^/]+\/versions\/(\d+)\/restore$/, (_method, m) => `Restored brief version ${m[1]}`],
|
|
23
|
+
[/^\/agents\/[^/]+\/workflows\/[^/]+\/messages$/, 'Changed where messages go'],
|
|
24
|
+
[/^\/agents\/[^/]+\/workflows\/[^/]+\/triggers/, 'Changed webhook triggers'],
|
|
25
|
+
[/^\/agents\/[^/]+\/workflows\/[^/]+\/evals\/criteria/, 'Changed the checklist'],
|
|
26
|
+
[/^\/agents\/[^/]+\/workflows\/[^/]+\/evals/, 'Changed eval cases'],
|
|
27
|
+
[/^\/agents\/[^/]+\/schedules/, 'Changed schedules'],
|
|
28
|
+
[/^\/schedules\//, 'Changed a schedule'],
|
|
29
|
+
[/^\/agents\/[^/]+\/actauth/, 'Changed permissions'],
|
|
30
|
+
[/^\/agents\/[^/]+\/tools\/http/, 'Changed HTTP tools'],
|
|
31
|
+
[/^\/agents\/[^/]+\/gateway-tools/, 'Changed app tools'],
|
|
32
|
+
[/^\/agents\/[^/]+\/apps\//, 'Changed apps'],
|
|
33
|
+
[/^\/agents\/[^/]+\/skills\//, 'Changed skills'],
|
|
34
|
+
[/^\/agents\/[^/]+\/abilities/, 'Changed abilities'],
|
|
35
|
+
[/^\/agents\/[^/]+\/notifier/, 'Changed the messaging app'],
|
|
36
|
+
[/^\/agents\/[^/]+\/env/, 'Changed agent secrets'],
|
|
37
|
+
[/^\/config\/policies$/, 'Changed shared policies'],
|
|
38
|
+
[/^\/config\/models/, 'Changed models'],
|
|
39
|
+
[/^\/config\/time-zone$/, 'Changed the time zone'],
|
|
40
|
+
[/^\/config\/apps/, 'Changed apps'],
|
|
41
|
+
[/^\/config\/gateways/, 'Changed the app gateway'],
|
|
42
|
+
[/^\/config\/upgrade$/, 'Upgraded LoopEngine'],
|
|
43
|
+
[/^\/abilities\//, 'Changed workspace abilities'],
|
|
44
|
+
];
|
|
45
|
+
/** The change a request makes, or undefined when it doesn't change a
|
|
46
|
+
* setting. */
|
|
47
|
+
export function changeOf(method, path) {
|
|
48
|
+
if (method !== 'POST' && method !== 'PUT' && method !== 'PATCH' && method !== 'DELETE')
|
|
49
|
+
return undefined;
|
|
50
|
+
if (NOT_CHANGES.some((pattern) => pattern.test(path)))
|
|
51
|
+
return undefined;
|
|
52
|
+
for (const [pattern, label] of LABELS) {
|
|
53
|
+
const m = path.match(pattern);
|
|
54
|
+
if (!m)
|
|
55
|
+
continue;
|
|
56
|
+
const agent = path.match(/^\/agents\/([^/]+)/)?.[1];
|
|
57
|
+
const workflowId = path.match(/^\/agents\/[^/]+\/workflows\/([^/]+)/)?.[1];
|
|
58
|
+
return {
|
|
59
|
+
label: typeof label === 'string' ? label : label(method, m),
|
|
60
|
+
...(agent ? { agent: decodeURIComponent(agent) } : {}),
|
|
61
|
+
...(workflowId ? { workflowId } : {}),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
const SECRET_KEY = /secret|token|password|passwd|api[_-]?key|authorization|credential|private|^value$|^key$/i;
|
|
67
|
+
const MAX_TEXT = 4000;
|
|
68
|
+
/** A body as kept in the log: secret-looking fields blanked, long text
|
|
69
|
+
* cut. Secrets' bodies are dropped whole. */
|
|
70
|
+
export function keptBody(path, body) {
|
|
71
|
+
if (/\/env(\/|$)/.test(path))
|
|
72
|
+
return undefined;
|
|
73
|
+
return redact(body, 0);
|
|
74
|
+
}
|
|
75
|
+
function redact(value, depth) {
|
|
76
|
+
if (depth > 6)
|
|
77
|
+
return '…';
|
|
78
|
+
if (typeof value === 'string')
|
|
79
|
+
return value.length > MAX_TEXT ? value.slice(0, MAX_TEXT) + '…' : value;
|
|
80
|
+
if (Array.isArray(value))
|
|
81
|
+
return value.slice(0, 100).map((v) => redact(v, depth + 1));
|
|
82
|
+
if (value && typeof value === 'object') {
|
|
83
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, SECRET_KEY.test(k) && v ? '(hidden)' : redact(v, depth + 1)]));
|
|
84
|
+
}
|
|
85
|
+
return value;
|
|
86
|
+
}
|
|
@@ -101,8 +101,28 @@ export declare function setDefaultModelsFile(path: string | null): void;
|
|
|
101
101
|
*/
|
|
102
102
|
export declare function readModelsFile(): {
|
|
103
103
|
models: Partial<Record<ModelProviderInfo['provider'], string[]>>;
|
|
104
|
+
prices: ModelPrices;
|
|
104
105
|
error?: string;
|
|
105
106
|
};
|
|
107
|
+
/** A model's price, in US dollars per million tokens. */
|
|
108
|
+
export interface ModelPrice {
|
|
109
|
+
input: number;
|
|
110
|
+
output: number;
|
|
111
|
+
/** Input read from the provider's prompt cache, where it's cheaper. */
|
|
112
|
+
cachedInput?: number;
|
|
113
|
+
}
|
|
114
|
+
/** provider -> model -> price, from models.yaml's `prices` section:
|
|
115
|
+
*
|
|
116
|
+
* prices:
|
|
117
|
+
* openai:
|
|
118
|
+
* gpt-6.2-sol: { input: 5, output: 40, cached_input: 0.5 }
|
|
119
|
+
*
|
|
120
|
+
* The workspace's file overrides the shipped one model by model. */
|
|
121
|
+
export type ModelPrices = Record<string, Record<string, ModelPrice>>;
|
|
122
|
+
/** The price of a provider's model, or undefined when none is listed. */
|
|
123
|
+
export declare function modelPrice(provider: string | undefined, model: string | undefined): ModelPrice | undefined;
|
|
124
|
+
/** What a call cost in US dollars, or undefined without a price. */
|
|
125
|
+
export declare function callCost(provider: string | undefined, model: string | undefined, inputTokens: number, outputTokens: number): number | undefined;
|
|
106
126
|
/**
|
|
107
127
|
* The models a provider offers, for the model dropdown in the New agent
|
|
108
128
|
* and Model forms. A provider listed in models.yaml, the workspace's or
|