@chatpanel/events 0.77.0 → 0.78.1
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 +1 -1
- package/package.json +1 -1
- package/team-tool.js +5 -5
- package/team.js +84 -0
package/index.js
CHANGED
|
@@ -192,7 +192,7 @@ 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, slugTeamName } 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';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/events",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.1",
|
|
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",
|
package/team-tool.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// receive the host's toolset narrowed to their grants, and the host builds that from the
|
|
12
12
|
// same providers this tool is a member of.
|
|
13
13
|
|
|
14
|
-
import { validateTeam, normalizeTeam, describeRole,
|
|
14
|
+
import { validateTeam, normalizeTeam, describeRole, slugTeamName } from './team.js';
|
|
15
15
|
import { dryRunTeam } from './team-run.js';
|
|
16
16
|
|
|
17
17
|
export const TEAM_TOOL_NAME = 'team';
|
|
@@ -31,7 +31,7 @@ export function teamToolSpec(teams) {
|
|
|
31
31
|
+ 'Actions: {"action":"run","name":"<team>","request":"<what to do>"} runs one (streams; may take a while); '
|
|
32
32
|
+ '{"action":"dry_run","name":"<team>","request":"…"} shows roles, models, tools and budget without running; '
|
|
33
33
|
+ '{"action":"save","team":{…}} proposes a NEW team after a task that would benefit from several roles — the user approves it on a card. '
|
|
34
|
-
+ 'A team: {"name":"research","description":"…","roles":[{"id":"researcher","prompt":"…","prefer":"balanced","grants":["data","web"]},{"id":"writer","prompt":"…","prefer":"strong","grants":["none"]}],"merge":"judge","judge":"writer","budget":{"tokens":40000,"ms":300000}}. '
|
|
34
|
+
+ 'A team: {"name":"research" (a short identifier: letters, digits, - _; used as /research),"description":"…","roles":[{"id":"researcher","prompt":"…","prefer":"balanced","grants":["data","web"]},{"id":"writer","prompt":"…","prefer":"strong","grants":["none"]}],"merge":"judge","judge":"writer","budget":{"tokens":40000,"ms":300000}}. '
|
|
35
35
|
+ 'grants: none | data | web | history | mcp | mcp:<server>. merge: judge | converge | concat | first. A budget is required.',
|
|
36
36
|
parameters: {
|
|
37
37
|
type: 'object',
|
|
@@ -78,10 +78,10 @@ export function teamToolProvider({ teams = [], run = null, appoint = null, confi
|
|
|
78
78
|
const action = String(input?.action || '');
|
|
79
79
|
|
|
80
80
|
if (action === 'save') {
|
|
81
|
-
|
|
81
|
+
// A name in prose ("Research Team") becomes the /command it will be run by.
|
|
82
|
+
const team = input?.team && typeof input.team === 'object' ? { ...input.team, name: slugTeamName(input.team.name) } : input?.team;
|
|
82
83
|
const v = validateTeam(team);
|
|
83
|
-
if (!v.ok) return json({ error: 'The team is not valid.', problems: v.errors, hint: 'A team needs a name, roles with prompts and grants, and a budget.' });
|
|
84
|
-
if (!TEAM_NAME_RE.test(team.name)) return json({ error: 'name must be a short identifier.' });
|
|
84
|
+
if (!v.ok) return json({ error: 'The team is not valid.', problems: v.errors, hint: 'A team needs a name (letters, digits, - _), roles with prompts and grants, and a budget such as {"tokens":40000,"ms":300000}.' });
|
|
85
85
|
if (byName.has(team.name)) return json({ error: `A team named "${team.name}" already exists. Pick another name.` });
|
|
86
86
|
if (!confirmSave || !saveTeam) return json({ error: 'Saving a team needs the user\'s approval, which this surface cannot ask for. Describe the team and suggest saving it from the side panel or the desktop.' });
|
|
87
87
|
const norm = normalizeTeam(team);
|
package/team.js
CHANGED
|
@@ -121,3 +121,87 @@ 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
|
+
/**
|
|
156
|
+
* A name as typed → the identifier a `/command` needs: "Research Team" → "research-team".
|
|
157
|
+
* Used by the tool's save and by the form, so a model that names a team in prose is not
|
|
158
|
+
* bounced for it; what cannot be shaped (nothing left) still fails validation.
|
|
159
|
+
*/
|
|
160
|
+
export function slugTeamName(name) {
|
|
161
|
+
return String(name || '').trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^[^a-z]+/, '').replace(/-+$/, '').slice(0, 64);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Fresh copies — a starter is a template, never the stored record. */
|
|
165
|
+
export function starterTeams() {
|
|
166
|
+
return STARTER_TEAMS.map((t) => ({ ...t, roles: t.roles.map((r) => ({ ...r, grants: [...r.grants] })), budget: { ...t.budget } }));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** A blank team for the editor: one role, the smallest budget that is still a budget. */
|
|
170
|
+
export function blankTeam() {
|
|
171
|
+
return { name: '', description: '', plan: 'fixed', merge: 'concat', judge: null, roles: [{ id: 'role1', prompt: '', prefer: 'balanced', grants: ['none'] }], budget: { tokens: 20000, ms: 300000 } };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The editor's form → a team, or the errors. Grants come as text ("web, data, mcp:srv"),
|
|
176
|
+
* the budget as numbers that may be blank; a blank judge under `merge: judge` is the last
|
|
177
|
+
* role, which is the writer in every starter.
|
|
178
|
+
*/
|
|
179
|
+
export function teamFromForm(form) {
|
|
180
|
+
const roles = (Array.isArray(form.roles) ? form.roles : []).map((r) => ({
|
|
181
|
+
id: String(r.id || '').trim(),
|
|
182
|
+
name: String(r.name || '').trim() || undefined,
|
|
183
|
+
prompt: String(r.prompt || ''),
|
|
184
|
+
prefer: r.prefer || 'balanced',
|
|
185
|
+
...(r.model ? { model: String(r.model) } : {}),
|
|
186
|
+
grants: String(Array.isArray(r.grants) ? r.grants.join(',') : r.grants || 'none').split(/[,\s]+/).map((g) => g.trim()).filter(Boolean),
|
|
187
|
+
}));
|
|
188
|
+
const budget = {};
|
|
189
|
+
for (const k of ['tokens', 'calls', 'ms', 'usd']) {
|
|
190
|
+
const v = Number(form.budget?.[k]);
|
|
191
|
+
if (form.budget?.[k] !== '' && form.budget?.[k] != null && Number.isFinite(v) && v > 0) budget[k] = v;
|
|
192
|
+
}
|
|
193
|
+
const merge = form.merge || 'concat';
|
|
194
|
+
const team = {
|
|
195
|
+
name: slugTeamName(form.name),
|
|
196
|
+
description: String(form.description || '').trim(),
|
|
197
|
+
plan: form.plan || 'fixed',
|
|
198
|
+
merge,
|
|
199
|
+
judge: merge === 'judge' ? (form.judge || roles[roles.length - 1]?.id || null) : null,
|
|
200
|
+
roles,
|
|
201
|
+
budget,
|
|
202
|
+
enabled: form.enabled !== false,
|
|
203
|
+
...(form.createdAt ? { createdAt: form.createdAt } : {}),
|
|
204
|
+
};
|
|
205
|
+
const v = validateTeam(team);
|
|
206
|
+
return v.ok ? { ok: true, team: normalizeTeam(team) } : { ok: false, errors: v.errors };
|
|
207
|
+
}
|