@chatpanel/events 0.76.0 → 0.78.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +2 -1
- package/package.json +3 -1
- package/team-trail.js +37 -0
- package/team.js +75 -0
package/index.js
CHANGED
|
@@ -192,11 +192,12 @@ export { recipeToolProvider, recipeToolSpec, describeRecipeForApproval, RECIPE_T
|
|
|
192
192
|
// Agent teams (F8): a team is data, a run is a turn of turns under a budget, members talk
|
|
193
193
|
// through a typed board, nothing lands without a person.
|
|
194
194
|
export { createBudget, validateBudget, normalizeBudget, usageOf, BudgetError, BUDGET_DIMENSIONS } from './budget.js';
|
|
195
|
-
export { defineTeam, validateTeam, normalizeTeam, normalizeGrants, grantAllows, describeRole, TeamError, ROLE_MODES, MERGE_POLICIES, PLAN_MODES, GRANTABLE } from './team.js';
|
|
195
|
+
export { defineTeam, validateTeam, normalizeTeam, normalizeGrants, grantAllows, describeRole, TeamError, ROLE_MODES, MERGE_POLICIES, PLAN_MODES, GRANTABLE, STARTER_TEAMS, starterTeams, blankTeam, teamFromForm } from './team.js';
|
|
196
196
|
export { fixedPlan, parsePlan, plannerPrompt, waves, breakCycles, TEAM_PLAN_SCHEMA } from './team-plan.js';
|
|
197
197
|
export { createBoard, parseFindings, boardText, findingsInstruction, toBriefClaims, FINDINGS_SCHEMA, FINDING_KINDS } from './team-board.js';
|
|
198
198
|
export { runTeam, dryRunTeam, TeamRunError, RUN_STATUSES } from './team-run.js';
|
|
199
199
|
export { teamToolProvider, teamToolSpec, describeTeamForApproval, TEAM_TOOL_NAME } from './team-tool.js';
|
|
200
|
+
export { teamLine, teamLanes } from './team-trail.js';
|
|
200
201
|
export { mcpDispatchProvider, MCP_TOOL_NAME } from './mcp-dispatch.js';
|
|
201
202
|
export { createManifest, ManifestError, SOURCES } from './manifest.js';
|
|
202
203
|
export { createKernel, meetDecisions, KernelError, REQUIRED_PLUGINS, ALLOW_ALL } from './kernel.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "The canonical ChatPanel event-log and capability contracts \u2014 typed durable facts, clock-free deterministic linearization, schema upcasting, and the invariants the replay harness asserts. Pure, dependency-free ESM shared by the ChatPanel extension, gateway and bridge.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
"./team-plan.js": "./team-plan.js",
|
|
94
94
|
"./team-run.js": "./team-run.js",
|
|
95
95
|
"./team-tool.js": "./team-tool.js",
|
|
96
|
+
"./team-trail.js": "./team-trail.js",
|
|
96
97
|
"./team.js": "./team.js",
|
|
97
98
|
"./text-search.js": "./text-search.js",
|
|
98
99
|
"./theme.js": "./theme.js",
|
|
@@ -207,6 +208,7 @@
|
|
|
207
208
|
"team-plan.js",
|
|
208
209
|
"team-run.js",
|
|
209
210
|
"team-tool.js",
|
|
211
|
+
"team-trail.js",
|
|
210
212
|
"team.js",
|
|
211
213
|
"text-search.js",
|
|
212
214
|
"theme.js",
|
package/team-trail.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// A team run as a trail reads it: one line per event in the trail's own vocabulary, and
|
|
2
|
+
// the run's lanes — one per task — folded from the same events. Both clients draw a run
|
|
3
|
+
// from these; neither decides for itself what "task.done" means in words. The event
|
|
4
|
+
// vocabulary is team-run.js's `emit`; the lanes are what a pane, a card or a phone renders.
|
|
5
|
+
|
|
6
|
+
/** One trail line per team event, in the trail's own vocabulary. */
|
|
7
|
+
export function teamLine(ev) {
|
|
8
|
+
const role = ev.role ? `${ev.role}` : 'team';
|
|
9
|
+
switch (ev.type) {
|
|
10
|
+
case 'run.started': return { type: 'status', text: `team ${ev.team}: ${(ev.roles || []).join(', ')}` };
|
|
11
|
+
case 'plan.ready': return { type: 'status', text: `plan: ${(ev.tasks || []).length} task${(ev.tasks || []).length === 1 ? '' : 's'} (${ev.by})` };
|
|
12
|
+
case 'task.started': return { type: 'tool', name: role, text: `${role} · ${ev.title || ev.taskId}` };
|
|
13
|
+
case 'task.tool': return { type: 'tool', name: ev.name, text: `${role} ran ${ev.name}${ev.text ? ` — ${ev.text}` : ''}` };
|
|
14
|
+
case 'task.finding': return { type: 'status', text: `${role}: ${String(ev.finding?.text || '').slice(0, 140)}` };
|
|
15
|
+
case 'task.done': return { type: 'status', text: `${role} done · ${ev.findings || 0} finding${ev.findings === 1 ? '' : 's'}` };
|
|
16
|
+
case 'task.failed': return { type: 'error', text: `${role} ${ev.status || 'failed'}${ev.error ? ` — ${ev.error}` : ''}` };
|
|
17
|
+
case 'run.merging': return { type: 'status', text: `merging (${ev.policy})` };
|
|
18
|
+
case 'run.done': return { type: 'status', text: `team ${ev.status}${ev.usage?.spent?.tokens ? ` · ${ev.usage.spent.tokens} tokens` : ''}` };
|
|
19
|
+
default: return null;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The run's lanes — one per task — folded from its events, for the pane. */
|
|
24
|
+
export function teamLanes(prev, ev) {
|
|
25
|
+
const lanes = prev ? { ...prev, tasks: { ...prev.tasks } } : { runId: ev.runId, team: '', status: 'running', tasks: {}, findings: 0 };
|
|
26
|
+
switch (ev.type) {
|
|
27
|
+
case 'run.started': lanes.team = ev.team; lanes.roles = ev.roles; break;
|
|
28
|
+
case 'plan.ready': for (const t of ev.tasks || []) lanes.tasks[t.id] = { id: t.id, role: t.role, title: t.title, status: 'pending', findings: 0 }; break;
|
|
29
|
+
case 'task.started': lanes.tasks[ev.taskId] = { ...(lanes.tasks[ev.taskId] || { id: ev.taskId, role: ev.role, title: ev.title }), status: 'running' }; break;
|
|
30
|
+
case 'task.delta': if (lanes.tasks[ev.taskId]) lanes.tasks[ev.taskId] = { ...lanes.tasks[ev.taskId], text: ev.text }; break;
|
|
31
|
+
case 'task.finding': lanes.findings += 1; if (lanes.tasks[ev.taskId]) lanes.tasks[ev.taskId] = { ...lanes.tasks[ev.taskId], findings: (lanes.tasks[ev.taskId].findings || 0) + 1 }; break;
|
|
32
|
+
case 'task.done': case 'task.failed': if (lanes.tasks[ev.taskId]) lanes.tasks[ev.taskId] = { ...lanes.tasks[ev.taskId], status: ev.status || 'ok', ms: ev.ms }; break;
|
|
33
|
+
case 'run.done': lanes.status = ev.status; lanes.usage = ev.usage; break;
|
|
34
|
+
default: break;
|
|
35
|
+
}
|
|
36
|
+
return lanes;
|
|
37
|
+
}
|
package/team.js
CHANGED
|
@@ -121,3 +121,78 @@ export function describeRole(r) {
|
|
|
121
121
|
const grants = (r.grants || ['none']).join(', ');
|
|
122
122
|
return `${r.name || r.id} — ${who}${r.mode && r.mode !== 'model' ? ` (${r.mode})` : ''} · tools: ${grants}`;
|
|
123
123
|
}
|
|
124
|
+
|
|
125
|
+
// ── Starters and the editor's form ───────────────────────────────────────────────────────
|
|
126
|
+
//
|
|
127
|
+
// A team is usually proposed in conversation, but a person's first team should not depend
|
|
128
|
+
// on a model deciding to propose one. Both clients' Settings → Teams offer these as "Add
|
|
129
|
+
// starter" and edit them on the same form as a blank team; `teamFromForm` is the one shaping
|
|
130
|
+
// of that form into a team, so a field's meaning does not differ between clients.
|
|
131
|
+
|
|
132
|
+
export const STARTER_TEAMS = Object.freeze([
|
|
133
|
+
{
|
|
134
|
+
name: 'research',
|
|
135
|
+
description: 'Research a question from the web and your own notes, then write it up.',
|
|
136
|
+
plan: 'fixed', merge: 'judge', judge: 'writer',
|
|
137
|
+
roles: [
|
|
138
|
+
{ id: 'researcher', prompt: 'Research the request thoroughly. Search the web and the user\'s own history. Report each fact as a finding with where it came from; note disagreements between sources.', prefer: 'balanced', grants: ['web', 'data'] },
|
|
139
|
+
{ id: 'writer', prompt: 'Write the answer the user asked for from the board\'s findings, citing them. Say plainly what was not found.', prefer: 'strong', grants: ['none'] },
|
|
140
|
+
],
|
|
141
|
+
budget: { tokens: 40000, ms: 300000 },
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: 'review',
|
|
145
|
+
description: 'Two independent reads of a draft, reconciled into one set of comments.',
|
|
146
|
+
plan: 'fixed', merge: 'converge',
|
|
147
|
+
roles: [
|
|
148
|
+
{ id: 'editor', prompt: 'Read the draft as an editor: structure, clarity, what is missing. One finding per issue, with the passage it refers to.', prefer: 'strong', grants: ['none'] },
|
|
149
|
+
{ id: 'checker', prompt: 'Read the draft as a fact-checker: every claim that could be wrong, with what you checked against. Use the user\'s history and the web.', prefer: 'balanced', grants: ['data', 'web'] },
|
|
150
|
+
],
|
|
151
|
+
budget: { tokens: 30000, ms: 240000 },
|
|
152
|
+
},
|
|
153
|
+
]);
|
|
154
|
+
|
|
155
|
+
/** Fresh copies — a starter is a template, never the stored record. */
|
|
156
|
+
export function starterTeams() {
|
|
157
|
+
return STARTER_TEAMS.map((t) => ({ ...t, roles: t.roles.map((r) => ({ ...r, grants: [...r.grants] })), budget: { ...t.budget } }));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** A blank team for the editor: one role, the smallest budget that is still a budget. */
|
|
161
|
+
export function blankTeam() {
|
|
162
|
+
return { name: '', description: '', plan: 'fixed', merge: 'concat', judge: null, roles: [{ id: 'role1', prompt: '', prefer: 'balanced', grants: ['none'] }], budget: { tokens: 20000, ms: 300000 } };
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* The editor's form → a team, or the errors. Grants come as text ("web, data, mcp:srv"),
|
|
167
|
+
* the budget as numbers that may be blank; a blank judge under `merge: judge` is the last
|
|
168
|
+
* role, which is the writer in every starter.
|
|
169
|
+
*/
|
|
170
|
+
export function teamFromForm(form) {
|
|
171
|
+
const roles = (Array.isArray(form.roles) ? form.roles : []).map((r) => ({
|
|
172
|
+
id: String(r.id || '').trim(),
|
|
173
|
+
name: String(r.name || '').trim() || undefined,
|
|
174
|
+
prompt: String(r.prompt || ''),
|
|
175
|
+
prefer: r.prefer || 'balanced',
|
|
176
|
+
...(r.model ? { model: String(r.model) } : {}),
|
|
177
|
+
grants: String(Array.isArray(r.grants) ? r.grants.join(',') : r.grants || 'none').split(/[,\s]+/).map((g) => g.trim()).filter(Boolean),
|
|
178
|
+
}));
|
|
179
|
+
const budget = {};
|
|
180
|
+
for (const k of ['tokens', 'calls', 'ms', 'usd']) {
|
|
181
|
+
const v = Number(form.budget?.[k]);
|
|
182
|
+
if (form.budget?.[k] !== '' && form.budget?.[k] != null && Number.isFinite(v) && v > 0) budget[k] = v;
|
|
183
|
+
}
|
|
184
|
+
const merge = form.merge || 'concat';
|
|
185
|
+
const team = {
|
|
186
|
+
name: String(form.name || '').trim(),
|
|
187
|
+
description: String(form.description || '').trim(),
|
|
188
|
+
plan: form.plan || 'fixed',
|
|
189
|
+
merge,
|
|
190
|
+
judge: merge === 'judge' ? (form.judge || roles[roles.length - 1]?.id || null) : null,
|
|
191
|
+
roles,
|
|
192
|
+
budget,
|
|
193
|
+
enabled: form.enabled !== false,
|
|
194
|
+
...(form.createdAt ? { createdAt: form.createdAt } : {}),
|
|
195
|
+
};
|
|
196
|
+
const v = validateTeam(team);
|
|
197
|
+
return v.ok ? { ok: true, team: normalizeTeam(team) } : { ok: false, errors: v.errors };
|
|
198
|
+
}
|