@sixb/server 0.2.0 → 0.2.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/index.js +140 -25
- package/dist/index.js.map +6 -6
- package/dist/routes/agent-approvals.d.ts +11 -1
- package/dist/routes/agent-approvals.d.ts.map +1 -1
- package/dist/routes/agent-children.d.ts +2 -2
- package/dist/routes/agent-computers.d.ts +114 -1
- package/dist/routes/agent-computers.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +104 -12
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/observed-agent-threads.d.ts +14 -4
- package/dist/routes/observed-agent-threads.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +5 -5
- package/dist/routes/projections.d.ts +25 -25
- package/dist/routes/syncs.d.ts +4 -4
- package/dist/routes/workflows.d.ts +11 -11
- package/dist/schemas/activity.d.ts +8 -8
- package/dist/schemas/agents.d.ts +447 -42
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +29 -29
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/pipelines.d.ts +16 -16
- package/dist/schemas/projections.d.ts +146 -146
- package/dist/schemas/syncs.d.ts +12 -12
- package/dist/schemas/workflows.d.ts +52 -52
- package/package.json +5 -5
- package/src/routes/agent-computers.ts +149 -13
- package/src/routes/agents.ts +52 -7
- package/src/schemas/agents.ts +60 -1
- package/src/schemas/ai-accounting.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1511,7 +1511,8 @@ var ModelKindSchema = z8.enum([
|
|
|
1511
1511
|
"decision",
|
|
1512
1512
|
"transcription",
|
|
1513
1513
|
"speech",
|
|
1514
|
-
"reranking"
|
|
1514
|
+
"reranking",
|
|
1515
|
+
"web-search"
|
|
1515
1516
|
]);
|
|
1516
1517
|
var AiAccountingRangeQuerySchema = z8.object({
|
|
1517
1518
|
from: IsoDateSchema,
|
|
@@ -1840,6 +1841,15 @@ var AgentThreadComputerInputSchema = z9.object({
|
|
|
1840
1841
|
name: plainText(z9.string().trim().min(1).max(120)),
|
|
1841
1842
|
folder: plainText(z9.string().min(1).max(4096))
|
|
1842
1843
|
}).strict();
|
|
1844
|
+
var AgentBackgroundCommandSchema = z9.object({
|
|
1845
|
+
threadId: z9.string().min(1).max(200),
|
|
1846
|
+
id: z9.string().min(1).max(200),
|
|
1847
|
+
command: z9.string().max(1000),
|
|
1848
|
+
status: z9.enum(["running", "exited", "stopped"]),
|
|
1849
|
+
exitCode: z9.number().int().optional(),
|
|
1850
|
+
startedAt: z9.string().min(1).max(200),
|
|
1851
|
+
endedAt: z9.string().max(200).optional()
|
|
1852
|
+
}).strict();
|
|
1843
1853
|
var CreateAgentThreadBodySchema = z9.object({
|
|
1844
1854
|
title: z9.string().trim().min(1).optional(),
|
|
1845
1855
|
threadId: z9.string().trim().min(1).optional(),
|
|
@@ -1881,6 +1891,7 @@ var AgentThreadSchema = z9.object({
|
|
|
1881
1891
|
folder: z9.string(),
|
|
1882
1892
|
online: z9.boolean()
|
|
1883
1893
|
}).optional(),
|
|
1894
|
+
backgroundCommands: z9.array(AgentBackgroundCommandSchema.extend({ stopping: z9.boolean().optional() })).optional(),
|
|
1884
1895
|
movedAt: z9.string().optional(),
|
|
1885
1896
|
status: AgentThreadStatusSchema,
|
|
1886
1897
|
activeRunId: z9.string().nullable(),
|
|
@@ -1903,10 +1914,29 @@ var MoveAgentThreadToComputerBodySchema = z9.object({ computer: AgentThreadCompu
|
|
|
1903
1914
|
var AgentComputerSessionParamsSchema = z9.object({
|
|
1904
1915
|
sessionId: z9.string().trim().min(1).max(200)
|
|
1905
1916
|
});
|
|
1906
|
-
var HoldAgentComputerSessionBodySchema = z9.object({
|
|
1917
|
+
var HoldAgentComputerSessionBodySchema = z9.object({
|
|
1918
|
+
computer: AgentThreadComputerInputSchema,
|
|
1919
|
+
backgroundCommands: z9.array(AgentBackgroundCommandSchema).max(64).optional()
|
|
1920
|
+
}).strict();
|
|
1921
|
+
var AgentBackgroundCommandRefSchema = z9.object({
|
|
1922
|
+
threadId: z9.string(),
|
|
1923
|
+
id: z9.string(),
|
|
1924
|
+
startedAt: z9.string()
|
|
1925
|
+
});
|
|
1907
1926
|
var HoldAgentComputerSessionResponseSchema = z9.object({
|
|
1908
1927
|
expiresAt: z9.string(),
|
|
1909
|
-
waiting: z9.array(z9.string())
|
|
1928
|
+
waiting: z9.array(z9.string()),
|
|
1929
|
+
stop: z9.array(AgentBackgroundCommandRefSchema).optional()
|
|
1930
|
+
});
|
|
1931
|
+
var AgentBackgroundCommandParamsSchema = z9.object({
|
|
1932
|
+
threadId: z9.string().trim().min(1),
|
|
1933
|
+
commandId: z9.string().trim().min(1).max(200)
|
|
1934
|
+
});
|
|
1935
|
+
var StopAgentBackgroundCommandBodySchema = z9.object({
|
|
1936
|
+
startedAt: z9.string().trim().min(1).max(200)
|
|
1937
|
+
}).strict();
|
|
1938
|
+
var StopAgentBackgroundCommandResponseSchema = z9.object({
|
|
1939
|
+
command: AgentBackgroundCommandSchema.extend({ stopping: z9.boolean().optional() })
|
|
1910
1940
|
});
|
|
1911
1941
|
var AddAgentThreadParticipantsBodySchema = z9.object({
|
|
1912
1942
|
users: z9.array(z9.union([
|
|
@@ -4358,7 +4388,7 @@ async function serializeThreads(host, threads, viewer) {
|
|
|
4358
4388
|
title: thread.title,
|
|
4359
4389
|
sandboxParams: thread.sandboxParams,
|
|
4360
4390
|
runsOn: thread.runsOn,
|
|
4361
|
-
|
|
4391
|
+
...placeOf(thread),
|
|
4362
4392
|
movedAt: thread.movedAt ? toIsoString(thread.movedAt) : undefined,
|
|
4363
4393
|
sandboxState: thread.sandboxState && {
|
|
4364
4394
|
name: thread.sandboxState.name,
|
|
@@ -4380,20 +4410,30 @@ async function serializeThread(host, thread, viewer) {
|
|
|
4380
4410
|
return serialized;
|
|
4381
4411
|
}
|
|
4382
4412
|
async function computerPlaces(host, threads, viewer) {
|
|
4383
|
-
const owned = (thread) => thread.computer !== undefined && principalsEqual(thread.ownerPrincipal, viewer);
|
|
4413
|
+
const owned = (thread) => (thread.computer !== undefined || thread.movedAt !== undefined) && principalsEqual(thread.ownerPrincipal, viewer);
|
|
4384
4414
|
const live = host.storage.agents && threads.some(owned) ? await host.storage.agents.computers.listLive({
|
|
4385
4415
|
projectId: host.id,
|
|
4386
4416
|
ownerPrincipal: viewer,
|
|
4387
4417
|
now: new Date
|
|
4388
4418
|
}) : [];
|
|
4389
4419
|
return (thread) => {
|
|
4420
|
+
if (!owned(thread))
|
|
4421
|
+
return {};
|
|
4422
|
+
const backgroundCommands = live.flatMap((session) => (session.backgroundCommands ?? []).filter((command) => command.threadId === thread.id).map((command) => {
|
|
4423
|
+
const stopping = command.status === "running" && (session.stopRequests ?? []).some((ref) => sameBackgroundCommand(command, ref));
|
|
4424
|
+
return stopping ? { ...command, stopping } : command;
|
|
4425
|
+
}));
|
|
4390
4426
|
const computer = thread.computer;
|
|
4391
|
-
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4427
|
+
const online = computer !== undefined && live.some((session) => sameComputerPlace(session.computer, computer));
|
|
4428
|
+
return {
|
|
4429
|
+
...computer ? { computer: { ...computer, online } } : {},
|
|
4430
|
+
...backgroundCommands.length > 0 ? { backgroundCommands } : {}
|
|
4431
|
+
};
|
|
4395
4432
|
};
|
|
4396
4433
|
}
|
|
4434
|
+
function sameBackgroundCommand(command, ref) {
|
|
4435
|
+
return command.threadId === ref.threadId && command.id === ref.id && command.startedAt === ref.startedAt;
|
|
4436
|
+
}
|
|
4397
4437
|
function serializeMessage(message, annotations = [], checkpoint) {
|
|
4398
4438
|
return AgentMessageSchema.parse({
|
|
4399
4439
|
id: message.id,
|
|
@@ -5583,11 +5623,16 @@ function registerAgentChildRoutes(app, host) {
|
|
|
5583
5623
|
}
|
|
5584
5624
|
|
|
5585
5625
|
// src/routes/agent-computers.ts
|
|
5626
|
+
import {
|
|
5627
|
+
AgentRequestError as AgentRequestError2,
|
|
5628
|
+
principalsEqual as principalsEqual2,
|
|
5629
|
+
stableJsonStringify
|
|
5630
|
+
} from "@sixb/core";
|
|
5586
5631
|
import { sameComputerPlace as sameComputerPlace2 } from "@sixb/core/internal/agent-run-storage-provider";
|
|
5587
5632
|
import { publishAgentComputerActivity } from "@sixb/core/internal/agents/streams";
|
|
5588
5633
|
import { z as z15 } from "zod";
|
|
5589
5634
|
var SESSION_MS = 60000;
|
|
5590
|
-
var MAX_SESSIONS =
|
|
5635
|
+
var MAX_SESSIONS = 200;
|
|
5591
5636
|
async function computerClaiming(sessions, run, body) {
|
|
5592
5637
|
const claimed = AgentThreadComputerInputSchema.safeParse(body?.computer);
|
|
5593
5638
|
if (!claimed.success) {
|
|
@@ -5691,7 +5736,7 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5691
5736
|
const agents = host.storage.agents;
|
|
5692
5737
|
if (!agents)
|
|
5693
5738
|
return unconfiguredStorageResponse(set, "Agent storage");
|
|
5694
|
-
const { computer } = HoldAgentComputerSessionBodySchema.parse(body);
|
|
5739
|
+
const { computer, backgroundCommands = [] } = HoldAgentComputerSessionBodySchema.parse(body);
|
|
5695
5740
|
const ownerPrincipal = requestActor(sixb);
|
|
5696
5741
|
const now = new Date;
|
|
5697
5742
|
const before = await agents.computers.listLive({
|
|
@@ -5702,7 +5747,7 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5702
5747
|
if (before.length >= MAX_SESSIONS && !before.some((session) => session.id === params.sessionId)) {
|
|
5703
5748
|
set.status = 429;
|
|
5704
5749
|
return {
|
|
5705
|
-
error: `[SixbServer] You have ${MAX_SESSIONS}
|
|
5750
|
+
error: `[SixbServer] You have ${MAX_SESSIONS} folders connected: forget one to connect another.`
|
|
5706
5751
|
};
|
|
5707
5752
|
}
|
|
5708
5753
|
const expiresAt = new Date(now.getTime() + SESSION_MS);
|
|
@@ -5711,14 +5756,19 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5711
5756
|
id: params.sessionId,
|
|
5712
5757
|
ownerPrincipal,
|
|
5713
5758
|
computer,
|
|
5714
|
-
expiresAt
|
|
5759
|
+
expiresAt,
|
|
5760
|
+
...backgroundCommands.length > 0 ? { backgroundCommands } : {}
|
|
5715
5761
|
});
|
|
5716
|
-
|
|
5762
|
+
const held = before.find((session) => session.id === params.sessionId);
|
|
5763
|
+
const reported = !sameCommands(held?.backgroundCommands ?? [], backgroundCommands);
|
|
5764
|
+
if (reported || !before.some((session) => sameComputerPlace2(session.computer, computer))) {
|
|
5717
5765
|
await announce(host, ownerPrincipal, computer, true);
|
|
5718
5766
|
}
|
|
5767
|
+
const stop = (held?.stopRequests ?? []).filter((ref) => backgroundCommands.some((command) => command.status === "running" && sameBackgroundCommand(command, ref)));
|
|
5719
5768
|
return HoldAgentComputerSessionResponseSchema.parse({
|
|
5720
5769
|
expiresAt: expiresAt.toISOString(),
|
|
5721
|
-
waiting: await waitingTurns(host, agents, ownerPrincipal, computer)
|
|
5770
|
+
waiting: await waitingTurns(host, agents, ownerPrincipal, computer),
|
|
5771
|
+
...stop.length > 0 ? { stop } : {}
|
|
5722
5772
|
});
|
|
5723
5773
|
} catch (error) {
|
|
5724
5774
|
return handleAgentRouteError(error, set);
|
|
@@ -5734,11 +5784,71 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5734
5784
|
},
|
|
5735
5785
|
detail: {
|
|
5736
5786
|
summary: "Open or renew a computer session",
|
|
5737
|
-
description: "`sixb` holds one while it is open: your threads on this computer, in this folder, read as online, and you can continue them from anywhere. It lapses a minute after its last renewal.
|
|
5787
|
+
description: "`sixb` holds one while it is open: your threads on this computer, in this folder, read as online, and you can continue them from anywhere. It lapses a minute after its last renewal. It reports the background commands it runs for your threads; the answer lists the turns waiting for it, and the commands someone asked to stop.",
|
|
5738
5788
|
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5739
5789
|
operationId: "holdAgentComputerSession",
|
|
5740
5790
|
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5741
5791
|
}
|
|
5792
|
+
}).post("/api/agent-threads/:threadId/background-commands/:commandId/stop", async (context) => {
|
|
5793
|
+
const { params, body, set } = context;
|
|
5794
|
+
const sixb = requireRequestSixb(context);
|
|
5795
|
+
try {
|
|
5796
|
+
const agents = host.storage.agents;
|
|
5797
|
+
if (!agents)
|
|
5798
|
+
return unconfiguredStorageResponse(set, "Agent storage");
|
|
5799
|
+
const { startedAt } = StopAgentBackgroundCommandBodySchema.parse(body);
|
|
5800
|
+
const thread = await sixb.agent.threads.getById(params.threadId);
|
|
5801
|
+
if (!thread) {
|
|
5802
|
+
throw new AgentRequestError2("thread_not_found", "[SixbServer] Agent thread not found.");
|
|
5803
|
+
}
|
|
5804
|
+
const ownerPrincipal = requestActor(sixb);
|
|
5805
|
+
if (!principalsEqual2(thread.ownerPrincipal, ownerPrincipal)) {
|
|
5806
|
+
throw new AgentRequestError2("not_thread_owner", `[SixbServer] Only the owner of Agent thread '${thread.id}' stops its background commands, which run on their computer.`);
|
|
5807
|
+
}
|
|
5808
|
+
const ref = { threadId: thread.id, id: params.commandId, startedAt };
|
|
5809
|
+
const live = await agents.computers.listLive({
|
|
5810
|
+
projectId: host.id,
|
|
5811
|
+
ownerPrincipal,
|
|
5812
|
+
now: new Date
|
|
5813
|
+
});
|
|
5814
|
+
const running = live.flatMap((session) => (session.backgroundCommands ?? []).map((command) => ({ session, command }))).find(({ command }) => command.status === "running" && sameBackgroundCommand(command, ref));
|
|
5815
|
+
const asked = running && await agents.computers.requestStop({
|
|
5816
|
+
projectId: host.id,
|
|
5817
|
+
id: running.session.id,
|
|
5818
|
+
ownerPrincipal,
|
|
5819
|
+
command: ref
|
|
5820
|
+
});
|
|
5821
|
+
if (!running || !asked) {
|
|
5822
|
+
set.status = 404;
|
|
5823
|
+
return {
|
|
5824
|
+
error: `[SixbServer] Background command '${params.commandId}' does not run on an open sixb: it ended, or sixb closed.`
|
|
5825
|
+
};
|
|
5826
|
+
}
|
|
5827
|
+
await announce(host, ownerPrincipal, running.session.computer, true);
|
|
5828
|
+
set.status = 202;
|
|
5829
|
+
return StopAgentBackgroundCommandResponseSchema.parse({
|
|
5830
|
+
command: { ...running.command, stopping: true }
|
|
5831
|
+
});
|
|
5832
|
+
} catch (error) {
|
|
5833
|
+
return handleAgentRouteError(error, set);
|
|
5834
|
+
}
|
|
5835
|
+
}, {
|
|
5836
|
+
params: AgentBackgroundCommandParamsSchema,
|
|
5837
|
+
body: StopAgentBackgroundCommandBodySchema,
|
|
5838
|
+
response: {
|
|
5839
|
+
202: StopAgentBackgroundCommandResponseSchema,
|
|
5840
|
+
400: AgentRequestErrorResponseSchema,
|
|
5841
|
+
403: AgentRequestErrorResponseSchema,
|
|
5842
|
+
404: AgentRequestErrorResponseSchema,
|
|
5843
|
+
501: ErrorResponseSchema
|
|
5844
|
+
},
|
|
5845
|
+
detail: {
|
|
5846
|
+
summary: "Stop a background command on your computer",
|
|
5847
|
+
description: "A command the agent ran in the background on your computer keeps running after its turn. `sixb` there stops it, and everything it started, at its next renewal, which this asks for at once. The thread's owner alone stops it.",
|
|
5848
|
+
tags: [OPENAPI_TAGS.agentThreads.name],
|
|
5849
|
+
operationId: "stopAgentBackgroundCommand",
|
|
5850
|
+
security: SIXB_SESSION_MUTATION_SECURITY_REQUIREMENT
|
|
5851
|
+
}
|
|
5742
5852
|
}).delete("/api/agent-computers/sessions/:sessionId", async (context) => {
|
|
5743
5853
|
const { params, set } = context;
|
|
5744
5854
|
const sixb = requireRequestSixb(context);
|
|
@@ -5773,6 +5883,9 @@ function registerAgentComputerRoutes(app, host) {
|
|
|
5773
5883
|
}
|
|
5774
5884
|
});
|
|
5775
5885
|
}
|
|
5886
|
+
function sameCommands(before, now) {
|
|
5887
|
+
return stableJsonStringify(before) === stableJsonStringify(now);
|
|
5888
|
+
}
|
|
5776
5889
|
async function waitingTurns(host, agents, ownerPrincipal, computer) {
|
|
5777
5890
|
const { threads } = await agents.threads.list({
|
|
5778
5891
|
projectId: host.id,
|
|
@@ -5803,12 +5916,14 @@ async function announceOffline(host, agents, ended) {
|
|
|
5803
5916
|
const { ownerPrincipal } = first;
|
|
5804
5917
|
const live = await agents.computers.listLive({ projectId: host.id, ownerPrincipal, now });
|
|
5805
5918
|
const announced = [];
|
|
5806
|
-
for (const { computer } of [first, ...rest]) {
|
|
5807
|
-
|
|
5808
|
-
|
|
5919
|
+
for (const { computer, backgroundCommands = [] } of [first, ...rest]) {
|
|
5920
|
+
if (announced.some((other) => sameComputerPlace2(other, computer)))
|
|
5921
|
+
continue;
|
|
5922
|
+
const online = live.some((other) => sameComputerPlace2(other.computer, computer));
|
|
5923
|
+
if (online && backgroundCommands.length === 0)
|
|
5809
5924
|
continue;
|
|
5810
5925
|
announced.push(computer);
|
|
5811
|
-
await announce(host, ownerPrincipal, computer,
|
|
5926
|
+
await announce(host, ownerPrincipal, computer, online);
|
|
5812
5927
|
}
|
|
5813
5928
|
}
|
|
5814
5929
|
}
|
|
@@ -6038,7 +6153,7 @@ function registerAgentMemoryRoutes(app) {
|
|
|
6038
6153
|
}
|
|
6039
6154
|
|
|
6040
6155
|
// src/routes/agent-runners.ts
|
|
6041
|
-
import { principalsEqual as
|
|
6156
|
+
import { principalsEqual as principalsEqual3, SYSTEM_PRINCIPAL as SYSTEM_PRINCIPAL2 } from "@sixb/core";
|
|
6042
6157
|
import {
|
|
6043
6158
|
AgentRunRefusedError,
|
|
6044
6159
|
afterAgentRunFinished,
|
|
@@ -6128,7 +6243,7 @@ function registerAgentRunnerRoutes(app, host) {
|
|
|
6128
6243
|
const visible = await sixb.agent.runs.getById(runId);
|
|
6129
6244
|
const run = visible ? await sessions.storage.agents.runs.getById({ projectId: host.id, id: runId }) : null;
|
|
6130
6245
|
const execution = run && await sessions.storage.executions.getById({ projectId: host.id, id: run.executionId });
|
|
6131
|
-
if (run?.kind !== "conversation" || !execution || !
|
|
6246
|
+
if (run?.kind !== "conversation" || !execution || !principalsEqual3(execution.requestedBy ?? SYSTEM_PRINCIPAL2, requestActor(sixb))) {
|
|
6132
6247
|
return answer({
|
|
6133
6248
|
error: {
|
|
6134
6249
|
kind: "AgentRunRefusedError",
|
|
@@ -18192,7 +18307,7 @@ function isWebhookResponse(value) {
|
|
|
18192
18307
|
}
|
|
18193
18308
|
|
|
18194
18309
|
// src/routes/ws/agents.ts
|
|
18195
|
-
import { principalsEqual as
|
|
18310
|
+
import { principalsEqual as principalsEqual4 } from "@sixb/core";
|
|
18196
18311
|
import {
|
|
18197
18312
|
AGENT_ACTIVITY_STREAM_ID,
|
|
18198
18313
|
isAgentActivityEvent
|
|
@@ -18297,7 +18412,7 @@ async function canAccessAgentRunStream(sixb, runId) {
|
|
|
18297
18412
|
}
|
|
18298
18413
|
async function canAccessAgentThreadActivity(sixb, event) {
|
|
18299
18414
|
if (event.type === "agent.computer.activity" || event.type === "agent.thread.moved") {
|
|
18300
|
-
return
|
|
18415
|
+
return principalsEqual4(event.ownerPrincipal, requestActor(sixb));
|
|
18301
18416
|
}
|
|
18302
18417
|
const run = await sixb.agent.runs.getById(event.runId);
|
|
18303
18418
|
return run?.projectId === event.projectId && run.threadId === event.threadId;
|
|
@@ -19612,4 +19727,4 @@ export {
|
|
|
19612
19727
|
requestTimingOptionsFromEnv
|
|
19613
19728
|
};
|
|
19614
19729
|
|
|
19615
|
-
//# debugId=
|
|
19730
|
+
//# debugId=BFDF3ADA46380F7264756E2164756E21
|