loopengine 0.4.1 → 0.4.3
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 +9 -7
- package/dist/index.js +8 -6
- 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
|
@@ -6,7 +6,9 @@ export type { AgentConfig, AgentModelConfig, ToolSchema, ToolDefinition, ToolCon
|
|
|
6
6
|
export { createAgentEnv, agentDirFor, envScopeOf, type EnvScope } from '#core/agent-env.js';
|
|
7
7
|
export { FileSecretStore, setSecretStore, getSecretStore, type SecretStore } from '#core/secret-store.js';
|
|
8
8
|
export { signProxyIdentity, verifyProxyIdentity, TRUSTED_PROXY_IDENTITY_HEADER, type ProxyIdentity } from '#core/trusted-proxy.js';
|
|
9
|
-
export { setUsageSink, recordUsage, type UsageEvent, type UsageSink } from '#core/usage.js';
|
|
9
|
+
export { setUsageSink, recordUsage, sessionUsage, usageBySession, type UsageEvent, type UsageSink, type UsageRow } from '#core/usage.js';
|
|
10
|
+
export { changeOf, keptBody, type Change } from '#web/change-log.js';
|
|
11
|
+
export { workflowHealth, healthAlerts, type WorkflowHealth, type HealthNumbers, type HealthVersion, type HealthDay, type HealthAlert, type HealthMeasure } from '#web/workflow-health.js';
|
|
10
12
|
export { setRunObserver, reportRun, usedTool, type RunEvent, type RunEventSource, type RunObserver } from '#core/run-events.js';
|
|
11
13
|
export { readNotifierFile, writeNotifierFile, removeNotifierFile, validateNotifierFile, notifierConfigFromFile, NotifierFileError, NOTIFIER_SECRET_VARS, type NotifierFile, type MessagingApprover } from '#core/notifier-file.js';
|
|
12
14
|
export { listDeliveries, recordDelivery, type NotifierDelivery } from '#core/notifier-deliveries.js';
|
|
@@ -29,7 +31,7 @@ export { createTelegramConnector, parseTelegramUpdate, verifyTelegramRequest, te
|
|
|
29
31
|
export type * from './core/loop-events.js';
|
|
30
32
|
export { streamMessage, streamMessageWithCallbacks, sendMessage, approveCall, denyCall, answerQuestion, getSessionHistory, } from './core/client.js';
|
|
31
33
|
export type { RequestOptions, SendMessageResult, PendingApprovalResult, PendingQuestionResult, PendingResult, MessageResult, StreamMessageCallbacks, } from './core/client.js';
|
|
32
|
-
export { FileSessionStore, RedisSessionStore, createSessionStore } from './core/session-store.js';
|
|
34
|
+
export { FileSessionStore, RedisSessionStore, SqliteSessionStore, createSessionStore } from './core/session-store.js';
|
|
33
35
|
export type { SessionStore, SessionResult, RedisSessionStoreOptions } from './core/session-store.js';
|
|
34
36
|
export { SessionKnit, FileStorage, MemoryStorage, reconstructChain } from './core/sessionknit.js';
|
|
35
37
|
export type { Storage, SessionEntry, ResumeResult, SessionKnitOptions, ReconstructResult } from './core/sessionknit.js';
|
|
@@ -62,7 +64,7 @@ export { Compactor, TruncatingSummarizer } from './core/compaction.js';
|
|
|
62
64
|
export type { Summarizer, RecoverResult, RecoverAction } from './core/compaction.js';
|
|
63
65
|
export { LLMSummarizer } from './core/llm-summarizer.js';
|
|
64
66
|
export type { LLMSummarizerOptions } from './core/llm-summarizer.js';
|
|
65
|
-
export { createCheckpointStore } from './core/durable-approvals.js';
|
|
67
|
+
export { createCheckpointStore, SqliteCheckpointStore } from './core/durable-approvals.js';
|
|
66
68
|
export type { TurnCheckpoint, CheckpointStore, OutstandingItem } from './core/durable-approvals.js';
|
|
67
69
|
export { addGatewayTool, agentDir, inferAgentNameFromToolUrl, disconnectComposioAccount, describeGatewayTools, listComposioConnections, listComposioTools, loadGatewayToolsFromDir, removeGatewayTool, removeGatewayToolSlug, GatewayToolExistsError, GatewayToolNotFoundError, } from './core/gateway-tools.js';
|
|
68
70
|
export type { GatewayToolEntry, GatewayToolDecision } from './core/gateway-tools.js';
|
|
@@ -92,8 +94,8 @@ export { WORKFLOW_EXAMPLES, workflowExample, type WorkflowExample } from './core
|
|
|
92
94
|
export { WORKFLOW_EXAMPLE_MESSAGES, type WorkflowExampleMessage } from './core/system-agents/workflow-example-messages.js';
|
|
93
95
|
export { createTrigger, updateTrigger, rotateTrigger, listTriggers, findTriggerByToken, publicTrigger, checkTriggerSettings, verifySenderSignature, parsePayload, valueAt, deliveryId, passesFilter, paramsFromPayload, checkRunDelivery, fillChatNotice, resultToChat, recordDelivery as recordTriggerDelivery, FileTriggerStore, getTriggerStore, setTriggerStore, TriggerError, type WorkflowTrigger, type PublicTrigger, type TriggerSettings, type TriggerVerify, type TriggerFilter, type TriggerSender, type SignatureAlgorithm, type TriggerDelivery, type TriggerOutcome, type TriggerStore } from './core/workflow-triggers.js';
|
|
94
96
|
export { checkCallbackUrl, callbackSecret, signCallback, deliverCallback, runCallbackPayload, isPrivateAddress, CallbackUrlError, type CallbackDelivery, type CallbackPending, type RunCallbackEvent } from './core/run-callbacks.js';
|
|
95
|
-
export { auditDb, openAuditDb, setAuditDb, recordEvent, runEvents, noteVersion, listVersions, getVersion, briefContent, briefFromContent, retentionDays, type Version, type VersionKind, type AuditEvent, type AuditEventKind } from './core/audit-store.js';
|
|
96
|
-
export { WorkflowRunner, FileRunStore, SqliteRunStore, getRunStore, setRunStore, listRuns, getRun, isUnderWay, RunError, type WorkflowRun, type WorkflowRunStatus, type RunVersions, type RunDecision, type RunStore, type ExecuteRun, type RunOutcome, type StartRunInput } from './core/workflow-runs.js';
|
|
97
|
+
export { auditDb, openAuditDb, setAuditDb, recordEvent, runEvents, listEvents, readMeta, writeMeta, type EventFilter, noteVersion, listVersions, getVersion, briefContent, briefFromContent, retentionDays, type Version, type VersionKind, type AuditEvent, type AuditEventKind } from './core/audit-store.js';
|
|
98
|
+
export { WorkflowRunner, FileRunStore, SqliteRunStore, getRunStore, setRunStore, listRuns, runsSince, getRun, isUnderWay, RunError, type WorkflowRun, type WorkflowRunStatus, type RunVersions, type RunDecision, type RunStore, type ExecuteRun, type RunOutcome, type StartRunInput } from './core/workflow-runs.js';
|
|
97
99
|
export { readWorkflows, readWorkflow, setWorkflowFields, setWorkflowDelivery, clearWorkflowFields, validateParams, workflowRunMessage, workflowPreviewMessage, migrateWorkflowsFile, WorkflowParamsError, readWorkspacePolicies, writeWorkspacePolicies, type Workflow, type WorkflowFields, type WorkflowParameter, type WorkflowModel, type WorkflowDelivery, type RunMessageExtras } from './core/workflows.js';
|
|
98
100
|
export { EvidenceError, workflowScores, runFeedbackFrom, readEvals, addEvalCase, updateEvalCase, removeEvalCase, setEvalCriteria, effectiveCriteria, codeCheck, judgeCriteria, checkCase, roundSummary, draftCriteria, startEvalRound, EVAL_CRITERIA_PROMPT, DRAFT_CRITERIA_PROMPT, REFERENCE_CRITERION, type WorkflowScores, type EvalCase, type EvalCaseResult, type EvalCheck, type EvalCriterion, type CriterionKind, type EvalRound, type WorkflowEvals, type EvalRunDeps } from './web/workflow-evidence.js';
|
|
99
101
|
export { globalConfigPageHtml } from './web/global-config-page.js';
|
|
@@ -120,10 +122,10 @@ export { startMcpSignIn, finishMcpSignIn, mcpSignInSupport, mcpOAuthEnvName, par
|
|
|
120
122
|
export { abilityDetails } from './web/ability-details-admin.js';
|
|
121
123
|
export { WorkspaceAbilityError, listWorkspaceAbilities, addWorkspaceAbility, removeWorkspaceAbility, workspaceAbilitiesDir, type WorkspaceAbility } from './core/workspace-abilities.js';
|
|
122
124
|
export { installWorkspaceAbility, installUploadedAbility, MAX_UPLOAD_BYTES, type AbilityUpload } from './web/workspace-abilities-admin.js';
|
|
123
|
-
export { describeModelProviders, describeGateways, setModelProviderKey, clearModelProviderKey, listProviderModels, ModelKeyError, describeTimeZone, setWorkspaceTimeZone, TimeZoneError } from './web/global-config.js';
|
|
125
|
+
export { callCost, modelPrice, describeModelProviders, describeGateways, setModelProviderKey, clearModelProviderKey, listProviderModels, ModelKeyError, describeTimeZone, setWorkspaceTimeZone, TimeZoneError } from './web/global-config.js';
|
|
124
126
|
export { loopengineVersion } from './core/version.js';
|
|
125
127
|
export { describeUpgrade, runUpgrade, UpgradeError } from './web/upgrade-admin.js';
|
|
126
|
-
export type { ModelProviderInfo, AgentModelUsage, ModelsView, ProviderModelsView, GatewayProviderInfo, GatewaysView, TimeZoneView } from './web/global-config.js';
|
|
128
|
+
export type { ModelPrice, ModelPrices, ModelProviderInfo, AgentModelUsage, ModelsView, ProviderModelsView, GatewayProviderInfo, GatewaysView, TimeZoneView } from './web/global-config.js';
|
|
127
129
|
export { workspaceTimeZone, serverTimeZone, isValidTimeZone, TIME_ZONE_ENV } from '#core/time-zone.js';
|
|
128
130
|
export { createTrackedApprover, listApprovals, decideApproval, findApproval } from './web/web-approver.js';
|
|
129
131
|
export { scaffoldAgent, scaffoldSubagent, AgentNameError, AgentExistsError, AgentNotFoundError, AgentModelError } from './bin/cli.js';
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,9 @@ export { storageSigners } from '#core/storage-signers/index.js';
|
|
|
8
8
|
export { createAgentEnv, agentDirFor, envScopeOf } from '#core/agent-env.js';
|
|
9
9
|
export { FileSecretStore, setSecretStore, getSecretStore } from '#core/secret-store.js';
|
|
10
10
|
export { signProxyIdentity, verifyProxyIdentity, TRUSTED_PROXY_IDENTITY_HEADER } from '#core/trusted-proxy.js';
|
|
11
|
-
export { setUsageSink, recordUsage } from '#core/usage.js';
|
|
11
|
+
export { setUsageSink, recordUsage, sessionUsage, usageBySession } from '#core/usage.js';
|
|
12
|
+
export { changeOf, keptBody } from '#web/change-log.js';
|
|
13
|
+
export { workflowHealth, healthAlerts } from '#web/workflow-health.js';
|
|
12
14
|
export { setRunObserver, reportRun, usedTool } from '#core/run-events.js';
|
|
13
15
|
export { readNotifierFile, writeNotifierFile, removeNotifierFile, validateNotifierFile, notifierConfigFromFile, NotifierFileError, NOTIFIER_SECRET_VARS } from '#core/notifier-file.js';
|
|
14
16
|
export { listDeliveries, recordDelivery } from '#core/notifier-deliveries.js';
|
|
@@ -34,7 +36,7 @@ export { createTelegramConnector, parseTelegramUpdate, verifyTelegramRequest, te
|
|
|
34
36
|
// is re-exported through this single entry point too, and client.ts is no
|
|
35
37
|
// exception.
|
|
36
38
|
export { streamMessage, streamMessageWithCallbacks, sendMessage, approveCall, denyCall, answerQuestion, getSessionHistory, } from './core/client.js';
|
|
37
|
-
export { FileSessionStore, RedisSessionStore, createSessionStore } from './core/session-store.js';
|
|
39
|
+
export { FileSessionStore, RedisSessionStore, SqliteSessionStore, createSessionStore } from './core/session-store.js';
|
|
38
40
|
export { SessionKnit, FileStorage, MemoryStorage, reconstructChain } from './core/sessionknit.js';
|
|
39
41
|
export { SkillGarden, parseSkillFile, discoverSkillFiles, estimateTokens as estimateSkillIndexTokens, buildBudgetedIndex, substituteArguments, substituteParameters, matchesActivationPaths, } from './core/skillgarden/index.js';
|
|
40
42
|
export { VectorIndex, embed, cosineSimilarity } from './core/vector-index.js';
|
|
@@ -59,7 +61,7 @@ export { agentAsTool } from './core/agent-as-tool.js';
|
|
|
59
61
|
export { resumeAgent, loadRules, loadDefaultTools, loadSubagentAsTools, systemTools, systemSkillsDir } from './core/run-agent.js';
|
|
60
62
|
export { Compactor, TruncatingSummarizer } from './core/compaction.js';
|
|
61
63
|
export { LLMSummarizer } from './core/llm-summarizer.js';
|
|
62
|
-
export { createCheckpointStore } from './core/durable-approvals.js';
|
|
64
|
+
export { createCheckpointStore, SqliteCheckpointStore } from './core/durable-approvals.js';
|
|
63
65
|
export { addGatewayTool, agentDir, inferAgentNameFromToolUrl, disconnectComposioAccount, describeGatewayTools, listComposioConnections, listComposioTools, loadGatewayToolsFromDir, removeGatewayTool, removeGatewayToolSlug, GatewayToolExistsError, GatewayToolNotFoundError, } from './core/gateway-tools.js';
|
|
64
66
|
export { connectComposioSource } from './core/mcpplug.js';
|
|
65
67
|
export { ToolLane, buildLanes, runLanes } from './core/toollane.js';
|
|
@@ -85,8 +87,8 @@ export { WORKFLOW_EXAMPLES, workflowExample } from './core/system-agents/workflo
|
|
|
85
87
|
export { WORKFLOW_EXAMPLE_MESSAGES } from './core/system-agents/workflow-example-messages.js';
|
|
86
88
|
export { createTrigger, updateTrigger, rotateTrigger, listTriggers, findTriggerByToken, publicTrigger, checkTriggerSettings, verifySenderSignature, parsePayload, valueAt, deliveryId, passesFilter, paramsFromPayload, checkRunDelivery, fillChatNotice, resultToChat, recordDelivery as recordTriggerDelivery, FileTriggerStore, getTriggerStore, setTriggerStore, TriggerError } from './core/workflow-triggers.js';
|
|
87
89
|
export { checkCallbackUrl, callbackSecret, signCallback, deliverCallback, runCallbackPayload, isPrivateAddress, CallbackUrlError } from './core/run-callbacks.js';
|
|
88
|
-
export { auditDb, openAuditDb, setAuditDb, recordEvent, runEvents, noteVersion, listVersions, getVersion, briefContent, briefFromContent, retentionDays } from './core/audit-store.js';
|
|
89
|
-
export { WorkflowRunner, FileRunStore, SqliteRunStore, getRunStore, setRunStore, listRuns, getRun, isUnderWay, RunError } from './core/workflow-runs.js';
|
|
90
|
+
export { auditDb, openAuditDb, setAuditDb, recordEvent, runEvents, listEvents, readMeta, writeMeta, noteVersion, listVersions, getVersion, briefContent, briefFromContent, retentionDays } from './core/audit-store.js';
|
|
91
|
+
export { WorkflowRunner, FileRunStore, SqliteRunStore, getRunStore, setRunStore, listRuns, runsSince, getRun, isUnderWay, RunError } from './core/workflow-runs.js';
|
|
90
92
|
export { readWorkflows, readWorkflow, setWorkflowFields, setWorkflowDelivery, clearWorkflowFields, validateParams, workflowRunMessage, workflowPreviewMessage, migrateWorkflowsFile, WorkflowParamsError, readWorkspacePolicies, writeWorkspacePolicies } from './core/workflows.js';
|
|
91
93
|
export { EvidenceError, workflowScores, runFeedbackFrom, readEvals, addEvalCase, updateEvalCase, removeEvalCase, setEvalCriteria, effectiveCriteria, codeCheck, judgeCriteria, checkCase, roundSummary, draftCriteria, startEvalRound, EVAL_CRITERIA_PROMPT, DRAFT_CRITERIA_PROMPT, REFERENCE_CRITERION } from './web/workflow-evidence.js';
|
|
92
94
|
export { globalConfigPageHtml } from './web/global-config-page.js';
|
|
@@ -110,7 +112,7 @@ export { startMcpSignIn, finishMcpSignIn, mcpSignInSupport, mcpOAuthEnvName, par
|
|
|
110
112
|
export { abilityDetails } from './web/ability-details-admin.js';
|
|
111
113
|
export { WorkspaceAbilityError, listWorkspaceAbilities, addWorkspaceAbility, removeWorkspaceAbility, workspaceAbilitiesDir } from './core/workspace-abilities.js';
|
|
112
114
|
export { installWorkspaceAbility, installUploadedAbility, MAX_UPLOAD_BYTES } from './web/workspace-abilities-admin.js';
|
|
113
|
-
export { describeModelProviders, describeGateways, setModelProviderKey, clearModelProviderKey, listProviderModels, ModelKeyError, describeTimeZone, setWorkspaceTimeZone, TimeZoneError } from './web/global-config.js';
|
|
115
|
+
export { callCost, modelPrice, describeModelProviders, describeGateways, setModelProviderKey, clearModelProviderKey, listProviderModels, ModelKeyError, describeTimeZone, setWorkspaceTimeZone, TimeZoneError } from './web/global-config.js';
|
|
114
116
|
export { loopengineVersion } from './core/version.js';
|
|
115
117
|
export { describeUpgrade, runUpgrade, UpgradeError } from './web/upgrade-admin.js';
|
|
116
118
|
export { workspaceTimeZone, serverTimeZone, isValidTimeZone, TIME_ZONE_ENV } from '#core/time-zone.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;
|