@sema-agent/server 1.316.0 → 1.317.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.
Files changed (50) hide show
  1. package/README.md +9 -0
  2. package/README.zh-CN.md +7 -0
  3. package/dist/config-types.d.ts +1 -1
  4. package/dist/config.d.ts +14 -0
  5. package/dist/config.js +148 -45
  6. package/dist/elicitation.js +2 -2
  7. package/dist/http/route-ctx.d.ts +51 -2
  8. package/dist/http/routes/approvals-assistant.d.ts +11 -0
  9. package/dist/http/routes/approvals-assistant.js +530 -0
  10. package/dist/http/routes/attachments.js +7 -7
  11. package/dist/http/routes/fleet.d.ts +4 -0
  12. package/dist/http/routes/fleet.js +147 -0
  13. package/dist/http/routes/images.js +29 -29
  14. package/dist/http/routes/leader.d.ts +4 -0
  15. package/dist/http/routes/leader.js +48 -0
  16. package/dist/http/routes/memory-policy.js +10 -10
  17. package/dist/http/routes/notify-wake.d.ts +4 -0
  18. package/dist/http/routes/notify-wake.js +133 -0
  19. package/dist/http/routes/observability.js +5 -5
  20. package/dist/http/routes/runs.d.ts +19 -0
  21. package/dist/http/routes/runs.js +967 -0
  22. package/dist/http/routes/session-sync.js +28 -28
  23. package/dist/http/routes/sessions-list.js +8 -8
  24. package/dist/http/routes/sessions.js +47 -47
  25. package/dist/http/routes/side-query.d.ts +4 -0
  26. package/dist/http/routes/side-query.js +88 -0
  27. package/dist/http/routes/tasks.d.ts +4 -0
  28. package/dist/http/routes/tasks.js +632 -0
  29. package/dist/http/routes/trace-usage.d.ts +4 -0
  30. package/dist/http/routes/trace-usage.js +239 -0
  31. package/dist/http/routes/workflows.d.ts +5 -0
  32. package/dist/http/routes/workflows.js +337 -0
  33. package/dist/http/run-meta.d.ts +11 -0
  34. package/dist/http/run-meta.js +16 -0
  35. package/dist/http/send.d.ts +1 -0
  36. package/dist/http/send.js +15 -0
  37. package/dist/http/server.d.ts +6 -5
  38. package/dist/http/server.js +241 -3166
  39. package/dist/http/sse-log.js +2 -2
  40. package/dist/http/wire-types.d.ts +6 -0
  41. package/dist/leader/endpoint.js +4 -4
  42. package/dist/main.js +5 -5
  43. package/dist/plugins/remote-env-host.js +4 -3
  44. package/dist/question.js +2 -2
  45. package/dist/run-local.js +1 -1
  46. package/dist/tool-approval.js +2 -2
  47. package/dist/trace/ledger-sink.js +1 -1
  48. package/dist/trace/project.d.ts +1 -0
  49. package/dist/trace/project.js +3 -0
  50. package/package.json +1 -1
@@ -0,0 +1,88 @@
1
+ import { isThinkingLevel } from "@sema-agent/core";
2
+ import { HttpError } from "../../security.js";
3
+ import { cacheFamilyOfMirror } from "../../budget.js";
4
+ import { redactSecrets } from "../../trace/redact.js";
5
+ import { sendJson, sendError, httpErrorCode, msg } from "../send.js";
6
+ import { gatedPrincipal } from "../principal-gate.js";
7
+ export async function handleSideQuery(req, res, url, ctx) {
8
+ const miss = { fell: false };
9
+ await handleSideQueryBody(req, res, url, ctx, miss);
10
+ return !miss.fell;
11
+ }
12
+ async function handleSideQueryBody(req, res, url, ctx, miss) {
13
+ const { deps } = ctx;
14
+ const { readJson, rateLimited, quotaExceeded, leaseDenied } = ctx.helpers;
15
+ if (req.method === "POST" && url === "/v1/side-query") {
16
+ const ac = new AbortController();
17
+ const onClose = () => ac.abort();
18
+ res.on("close", onClose);
19
+ try {
20
+ if (rateLimited(req, res) || quotaExceeded(req, res) || (await leaseDenied(req, res)))
21
+ return;
22
+ const principal = gatedPrincipal(req, deps.config);
23
+ if (deps.config.requirePrincipal && !principal) {
24
+ sendError(res, 401, "auth.principal_required", `missing principal header '${deps.config.principalHeader}'`);
25
+ return;
26
+ }
27
+ let body;
28
+ try {
29
+ const raw = await readJson(req);
30
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw))
31
+ throw new HttpError(400, "body must be a JSON object (SideQuerySpec shape)");
32
+ body = raw;
33
+ }
34
+ catch (e) {
35
+ const he = e instanceof HttpError ? e : new HttpError(400, msg(e));
36
+ sendError(res, he.status, httpErrorCode(he.status, he.code), he.message);
37
+ return;
38
+ }
39
+ if (!Array.isArray(body.messages) || body.messages.length === 0) {
40
+ sendError(res, 400, "request.body_shape", "messages must be a non-empty array (SideQueryMessage[])");
41
+ return;
42
+ }
43
+ if (body.thinking !== undefined && !isThinkingLevel(body.thinking)) {
44
+ sendError(res, 400, "request.field_invalid", "invalid thinking level");
45
+ return;
46
+ }
47
+ if (ac.signal.aborted)
48
+ return;
49
+ const spec = {
50
+ messages: body.messages,
51
+ ...(typeof body.model === "string" ? { model: body.model } : {}),
52
+ ...(typeof body.modelRole === "string" ? { modelRole: body.modelRole } : {}),
53
+ ...(isThinkingLevel(body.thinking) ? { thinking: body.thinking } : {}),
54
+ ...(typeof body.systemPrompt === "string" ? { systemPrompt: body.systemPrompt } : {}),
55
+ ...(Array.isArray(body.tools) ? { tools: body.tools } : {}),
56
+ ...(typeof body.maxOutputTokens === "number" && Number.isFinite(body.maxOutputTokens) && body.maxOutputTokens > 0 ? { maxOutputTokens: Math.floor(body.maxOutputTokens) } : {}),
57
+ signal: ac.signal,
58
+ };
59
+ try {
60
+ const catalogSnapshot = Object.values(deps.runner.agentCatalog?.models ?? {}).map((m) => ({ id: m?.id, api: m?.api, params: m?.params?.promptCacheFamily ? { promptCacheFamily: m.params.promptCacheFamily } : undefined }));
61
+ const result = await deps.runner.sideQuery(spec);
62
+ const rr = result;
63
+ const modelId = typeof rr.model === "string" ? rr.model : "unknown";
64
+ const byId = catalogSnapshot.filter((m) => m.id === modelId);
65
+ const families = new Set(byId.map((m) => cacheFamilyOfMirror(m)));
66
+ const family = families.size === 1 ? [...families][0] : undefined;
67
+ deps.sideQueryAccounting?.(principal, { model: modelId, ...(family ? { family } : {}), usage: rr.usage });
68
+ deps.metrics?.inc?.("side_query_total", { result: "ok" });
69
+ if (!res.writableEnded)
70
+ sendJson(res, 200, result);
71
+ }
72
+ catch (e) {
73
+ deps.metrics?.inc?.("side_query_total", { result: "error" });
74
+ if (!res.writableEnded && !ac.signal.aborted) {
75
+ const m = msg(e);
76
+ const isValidation = /^Unknown model ref |^No model for role |requires a non-empty messages array/.test(m);
77
+ sendError(res, isValidation ? 400 : 500, isValidation ? "request.field_invalid" : "internal.error", redactSecrets(m));
78
+ }
79
+ }
80
+ }
81
+ finally {
82
+ res.off("close", onClose);
83
+ }
84
+ return;
85
+ }
86
+ miss.fell = true;
87
+ }
88
+ //# sourceMappingURL=side-query.js.map
@@ -0,0 +1,4 @@
1
+ import type { IncomingMessage, ServerResponse } from "node:http";
2
+ import type { RouteCtx } from "../route-ctx.js";
3
+ export declare function handleTasks(req: IncomingMessage, res: ServerResponse, url: string, ctx: RouteCtx): Promise<boolean>;
4
+ //# sourceMappingURL=tasks.d.ts.map