multiuser: token identity, invites + bootstrap, owner-gated runs, fork, user packages; spectator spa; utc house rule
This commit is contained in:
+10
-8
@@ -27,7 +27,7 @@ function needSession(ctx, runId) {
|
||||
return s;
|
||||
}
|
||||
|
||||
export async function gmTurn(ctx, runId, line) {
|
||||
export async function gmTurn(ctx, runId, line, user) {
|
||||
const s = needSession(ctx, runId);
|
||||
if (s.pendingAsk) throw new HttpError(409, 'a question is pending — answer it first (POST /ask)');
|
||||
const paper = clerkJson(runId, 'paper'); // fresh per turn
|
||||
@@ -37,7 +37,7 @@ export async function gmTurn(ctx, runId, line) {
|
||||
s.conflict = null;
|
||||
}
|
||||
s.append({ t: 'msg', m: { role: 'user', content } });
|
||||
return runLoop(ctx, runId);
|
||||
return runLoop(ctx, runId, user);
|
||||
}
|
||||
|
||||
// the opening beat: turn-0 sent as the first GM turn, separate from
|
||||
@@ -45,7 +45,7 @@ export async function gmTurn(ctx, runId, line) {
|
||||
// block was ingested as her opening paper at window-open — stripped
|
||||
// here, since the normal ride carries the current paper on every GM
|
||||
// turn, the beat included.
|
||||
export async function turn0(ctx, runId) {
|
||||
export async function turn0(ctx, runId, user) {
|
||||
const s = needSession(ctx, runId);
|
||||
if (s.pendingAsk) throw new HttpError(409, 'a question is pending — answer it first (POST /ask)');
|
||||
if (!s.fresh) throw new HttpError(409, 'turn-0 opens a fresh run only');
|
||||
@@ -57,10 +57,10 @@ export async function turn0(ctx, runId) {
|
||||
let text = expandVars(runId, fs.readFileSync(file, 'utf8')); // $NAME tokens resolve like every bundle file
|
||||
const sm = text.match(/<status>[\s\S]*?<\/status>/);
|
||||
if (sm) text = text.replace(sm[0], '');
|
||||
return gmTurn(ctx, runId, text.trim());
|
||||
return gmTurn(ctx, runId, text.trim(), user);
|
||||
}
|
||||
|
||||
export async function answerAsk(ctx, runId, answer) {
|
||||
export async function answerAsk(ctx, runId, answer, user) {
|
||||
const s = needSession(ctx, runId);
|
||||
if (!s.pendingAsk) throw new HttpError(409, 'no pending question');
|
||||
// execute the paused batch: the ask gets the answer, its siblings
|
||||
@@ -73,13 +73,12 @@ export async function answerAsk(ctx, runId, answer) {
|
||||
}
|
||||
}
|
||||
s.pendingAsk = null;
|
||||
return runLoop(ctx, runId);
|
||||
return runLoop(ctx, runId, user);
|
||||
}
|
||||
|
||||
async function runLoop(ctx, runId) {
|
||||
async function runLoop(ctx, runId, user) {
|
||||
const s = ctx.sessions.get(runId);
|
||||
const tools = toolList(runId);
|
||||
const model = s.pendingAsk ? null : resolveModel(ctx, runId);
|
||||
const out = { tools: [] };
|
||||
for (;;) {
|
||||
const view = renderView(s);
|
||||
@@ -87,6 +86,9 @@ async function runLoop(ctx, runId) {
|
||||
if (ctx.mock) {
|
||||
msg = mockModel(s, view);
|
||||
} else {
|
||||
const model = resolveModel(ctx, runId);
|
||||
// attribution (#22): every LLM call names the acting user
|
||||
console.log(`${new Date().toISOString().slice(11, 19)} llm ${model} u:${user?.id ?? '?'}`);
|
||||
const data = await ctx.provider.chat(model, view, tools, ctx.cfg.params ?? {});
|
||||
msg = data.choices[0].message;
|
||||
s.usage = data.usage
|
||||
|
||||
Reference in New Issue
Block a user