@sema-agent/server 1.312.0 → 1.314.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 (45) hide show
  1. package/dist/auth-bridge.d.ts +3 -2
  2. package/dist/bench/s1/live-deps.js +2 -2
  3. package/dist/budget.d.ts +4 -76
  4. package/dist/budget.js +4 -83
  5. package/dist/capabilities/sandbox-file-send.d.ts +2 -1
  6. package/dist/config-types.d.ts +1 -1
  7. package/dist/elicitation.d.ts +5 -3
  8. package/dist/elicitation.js +3 -2
  9. package/dist/fleet/fleet-bus.d.ts +1 -0
  10. package/dist/fleet/fleet-bus.js +1 -0
  11. package/dist/fleet-lease.d.ts +1 -1
  12. package/dist/fleet-lease.js +1 -1
  13. package/dist/hooks/hook-llm.d.ts +5 -4
  14. package/dist/hooks/hook-runner.d.ts +1 -1
  15. package/dist/hooks/hook-runner.js +1 -1
  16. package/dist/http/server.js +67 -85
  17. package/dist/key-resolver.d.ts +1 -1
  18. package/dist/key-resolver.js +1 -1
  19. package/dist/leader/grader-env-factory.d.ts +1 -1
  20. package/dist/leader/grader-env-factory.js +2 -2
  21. package/dist/leader/wire.d.ts +1 -1
  22. package/dist/leader/wire.js +1 -1
  23. package/dist/main.js +26 -26
  24. package/dist/memory-scope.d.ts +18 -0
  25. package/dist/memory-scope.js +38 -0
  26. package/dist/observability/cost-taxonomy.d.ts +34 -0
  27. package/dist/observability/cost-taxonomy.js +26 -0
  28. package/dist/observability/prompt-manifest.d.ts +75 -0
  29. package/dist/observability/prompt-manifest.js +82 -0
  30. package/dist/plugins/mailbox-store-sql.d.ts +2 -2
  31. package/dist/plugins/mailbox-store-sql.js +8 -4
  32. package/dist/plugins/web-search.d.ts +4 -3
  33. package/dist/question.d.ts +2 -1
  34. package/dist/question.js +3 -2
  35. package/dist/run-local.js +2 -2
  36. package/dist/runtime-caps-resolver.d.ts +7 -7
  37. package/dist/runtime-caps-resolver.js +3 -3
  38. package/dist/security.d.ts +2 -16
  39. package/dist/security.js +3 -37
  40. package/dist/tool-approval.d.ts +2 -1
  41. package/dist/tool-approval.js +3 -2
  42. package/dist/trace/core-keyset-guard.d.ts +2 -2
  43. package/dist/trace/project.d.ts +1 -0
  44. package/dist/trace/project.js +1 -0
  45. package/package.json +2 -2
@@ -23,7 +23,8 @@ export type VerifyOutcome = {
23
23
  ok: false;
24
24
  error: AuthBridgeErrorCode;
25
25
  };
26
- export declare function createRegistryJwtVerifier(opts: RegistryJwtVerifierOptions): {
26
+ export interface RegistryJwtVerifier {
27
27
  verify: (bearer: string) => Promise<VerifyOutcome>;
28
- };
28
+ }
29
+ export declare function createRegistryJwtVerifier(opts: RegistryJwtVerifierOptions): RegistryJwtVerifier;
29
30
  //# sourceMappingURL=auth-bridge.d.ts.map
@@ -4,7 +4,7 @@ import { createBrain } from "../../brain.js";
4
4
  import { buildPricing } from "../../budget.js";
5
5
  import { RemoteContainerExecutionEnv } from "../../plugins/remote-env-e2b.js";
6
6
  import { createDurableAskPolicy } from "../../approval.js";
7
- import { buildLeaderRunner } from "../../leader/wire.js";
7
+ import { createLeaderRunner } from "../../leader/wire.js";
8
8
  import { runOracle as runStandaloneOracle } from "./oracle.js";
9
9
  import { makeRepairOracle } from "./repair-oracle-adapter.js";
10
10
  import { assertDistinctEnvs } from "./runner-ctx.js";
@@ -358,7 +358,7 @@ async function runLeaderForTrap(rt, brain, models, roles, pricing, trap, cellId,
358
358
  process.env.LEADER_ENABLED = "true";
359
359
  process.env.LEADER_WORKER_BUDGET_USD = String((rt.maxCostUsd ?? 1.0) / 2);
360
360
  process.env.LEADER_CONFLICT_ROUNDS = process.env.LEADER_CONFLICT_ROUNDS ?? "2";
361
- const run = buildLeaderRunner({
361
+ const run = createLeaderRunner({
362
362
  brain, models, roles, pricing, e2bApiKey: rt.e2bApiKey, workspace: W,
363
363
  ...(process.env.S1_DEBUG_GIT ? { logger: { warn: (m, x) => console.error(`[S1_DEBUG_LEADER warn] ${m}`, x ? JSON.stringify(x).slice(0, 300) : ""), info: (m, x) => console.error(`[S1_DEBUG_LEADER info] ${m}`, x ? JSON.stringify(x).slice(0, 200) : "") } } : {}),
364
364
  });
package/dist/budget.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { Metrics } from "./observability/metrics.js";
3
3
  import type { QuotaTracker } from "./observability/cost-quota.js";
4
4
  import type { FleetUsageAccumulator } from "./fleet-client.js";
5
5
  import type { FleetLeaseManager } from "./fleet-lease.js";
6
+ import { type PromptManifestTracker } from "./observability/prompt-manifest.js";
6
7
  export declare function buildPricing(models: Record<string, Model>): Record<string, ModelPricing>;
7
8
  export declare function cardinalityGuard(cap: number, onOverflow: () => void): (value: string) => string;
8
9
  export interface ModelUsageDelta {
@@ -20,88 +21,15 @@ export declare class ModelUsageTracker {
20
21
  drain(taskId: string): Record<string, ModelUsageDelta> | undefined;
21
22
  clear(taskId: string): void;
22
23
  }
23
- export interface PromptManifestRecord {
24
- constitution: string;
25
- blocks: Array<{
26
- id: string;
27
- chars: number;
28
- hash: string;
29
- }>;
30
- sections?: Array<{
31
- id: string;
32
- slot: string;
33
- carrier: string;
34
- cadence: string;
35
- cacheClass: string;
36
- chars: number;
37
- hash: string;
38
- contentHash?: string;
39
- }>;
40
- tools?: Array<{
41
- wireName: string;
42
- aliases: string[];
43
- contractId: string;
44
- implementationRevision: string;
45
- cardId: string;
46
- shapeDigest: string;
47
- wireSchemaDigest: string;
48
- }>;
49
- totalChars: number;
50
- }
51
- export declare function promptManifestRecordOf(e: {
52
- constitution: string;
53
- blocks: Array<{
54
- id: string;
55
- chars: number;
56
- hash: string;
57
- }>;
58
- sections?: Array<{
59
- id: string;
60
- slot: string;
61
- carrier: string;
62
- cadence: string;
63
- cacheClass: string;
64
- chars: number;
65
- hash: string;
66
- contentHash?: string;
67
- }>;
68
- tools?: Array<{
69
- wireName: string;
70
- aliases: string[];
71
- contractId: string;
72
- implementationRevision: string;
73
- cardId: string;
74
- shapeDigest: string;
75
- wireSchemaDigest: string;
76
- }>;
77
- totalChars: number;
78
- }): PromptManifestRecord;
79
- export declare function configAssembledRecordOf(e: {
80
- catalogVersion?: unknown;
81
- fields?: unknown;
82
- overrideReasons?: unknown;
83
- ts?: unknown;
84
- }): Record<string, unknown> | undefined;
85
- export declare class PromptManifestTracker {
86
- private readonly byTask;
87
- private readonly configByTask;
88
- private readonly active;
89
- private leaseCounter;
90
- register(taskId: string): number;
91
- record(taskId: string, m: PromptManifestRecord): void;
92
- recordConfig(taskId: string, rec: Record<string, unknown>): void;
93
- drainConfig(taskId: string): Array<Record<string, unknown>> | undefined;
94
- drain(taskId: string): PromptManifestRecord[] | undefined;
95
- clear(taskId: string, lease: number): void;
96
- }
97
- export declare function buildTracer(metrics: Pick<Metrics, "inc" | "observe">, costQuota?: QuotaTracker, modelUsage?: ModelUsageTracker, fleetUsage?: FleetUsageAccumulator, fleetLease?: FleetLeaseManager, quotaWeightFor?: (model: string) => number, promptManifests?: PromptManifestTracker): TracerHook;
24
+ export { type PromptManifestRecord, promptManifestRecordOf, configAssembledRecordOf, PromptManifestTracker, } from "./observability/prompt-manifest.js";
25
+ export declare function createTracer(metrics: Pick<Metrics, "inc" | "observe">, costQuota?: QuotaTracker, modelUsage?: ModelUsageTracker, fleetUsage?: FleetUsageAccumulator, fleetLease?: FleetLeaseManager, quotaWeightFor?: (model: string) => number, promptManifests?: PromptManifestTracker): TracerHook;
98
26
  export declare function cacheFamilyOfMirror(model: {
99
27
  api?: string;
100
28
  params?: {
101
29
  promptCacheFamily?: string;
102
30
  };
103
31
  } | undefined): "input-includes-cached" | "input-excludes-cached" | undefined;
104
- export declare function buildSideQueryAccountant(metrics: Pick<Metrics, "inc">, costQuota?: QuotaTracker, fleetUsage?: FleetUsageAccumulator, fleetLease?: FleetLeaseManager, quotaWeightFor?: (model: string) => number): (principal: string | undefined, r: {
32
+ export declare function createSideQueryAccountant(metrics: Pick<Metrics, "inc">, costQuota?: QuotaTracker, fleetUsage?: FleetUsageAccumulator, fleetLease?: FleetLeaseManager, quotaWeightFor?: (model: string) => number): (principal: string | undefined, r: {
105
33
  model: string;
106
34
  family?: "input-includes-cached" | "input-excludes-cached";
107
35
  usage?: {
package/dist/budget.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { modelCostToPricing } from "@sema-agent/core";
2
2
  import { currentPrincipal } from "./observability/principal-context.js";
3
+ import { promptManifestRecordOf, configAssembledRecordOf } from "./observability/prompt-manifest.js";
3
4
  export function buildPricing(models) {
4
5
  const pricing = {};
5
6
  for (const m of Object.values(models))
@@ -61,88 +62,8 @@ export class ModelUsageTracker {
61
62
  }
62
63
  clear(taskId) { this.byTask.delete(taskId); this.active.delete(taskId); }
63
64
  }
64
- export function promptManifestRecordOf(e) {
65
- return {
66
- constitution: String(e.constitution),
67
- blocks: (Array.isArray(e.blocks) ? e.blocks : []).map((b) => ({ id: String(b.id), chars: b.chars, hash: String(b.hash) })),
68
- ...(Array.isArray(e.sections)
69
- ? { sections: e.sections.map((s) => ({ id: String(s.id), slot: String(s.slot), carrier: String(s.carrier), cadence: String(s.cadence), cacheClass: String(s.cacheClass), chars: s.chars, hash: String(s.hash), ...(typeof s.contentHash === "string" ? { contentHash: s.contentHash } : {}) })) }
70
- : {}),
71
- ...(Array.isArray(e.tools)
72
- ? { tools: e.tools.map((t) => ({ wireName: String(t.wireName), aliases: (Array.isArray(t.aliases) ? t.aliases : []).map(String), contractId: String(t.contractId), implementationRevision: String(t.implementationRevision), cardId: String(t.cardId), shapeDigest: String(t.shapeDigest), wireSchemaDigest: String(t.wireSchemaDigest) })) }
73
- : {}),
74
- totalChars: e.totalChars,
75
- };
76
- }
77
- export function configAssembledRecordOf(e) {
78
- const rec = {
79
- catalogVersion: e.catalogVersion,
80
- fields: e.fields,
81
- ...(e.overrideReasons !== undefined ? { overrideReasons: e.overrideReasons } : {}),
82
- ts: e.ts,
83
- };
84
- try {
85
- if (JSON.stringify(rec).length > 32_768)
86
- return undefined;
87
- }
88
- catch {
89
- return undefined;
90
- }
91
- return rec;
92
- }
93
- export class PromptManifestTracker {
94
- byTask = new Map();
95
- configByTask = new Map();
96
- active = new Map();
97
- leaseCounter = 0;
98
- register(taskId) {
99
- if (!taskId)
100
- return 0;
101
- const lease = ++this.leaseCounter;
102
- this.active.set(taskId, lease);
103
- return lease;
104
- }
105
- record(taskId, m) {
106
- if (!taskId || !this.active.has(taskId))
107
- return;
108
- const q = this.byTask.get(taskId);
109
- if (q)
110
- q.push(m);
111
- else
112
- this.byTask.set(taskId, [m]);
113
- }
114
- recordConfig(taskId, rec) {
115
- if (!taskId || !this.active.has(taskId))
116
- return;
117
- const q = this.configByTask.get(taskId);
118
- if (q)
119
- q.push(rec);
120
- else
121
- this.configByTask.set(taskId, [rec]);
122
- }
123
- drainConfig(taskId) {
124
- const q = this.configByTask.get(taskId);
125
- if (!q || q.length === 0)
126
- return undefined;
127
- this.configByTask.delete(taskId);
128
- return q;
129
- }
130
- drain(taskId) {
131
- const q = this.byTask.get(taskId);
132
- if (!q || q.length === 0)
133
- return undefined;
134
- this.byTask.delete(taskId);
135
- return q;
136
- }
137
- clear(taskId, lease) {
138
- if (this.active.get(taskId) !== lease)
139
- return;
140
- this.byTask.delete(taskId);
141
- this.active.delete(taskId);
142
- this.configByTask.delete(taskId);
143
- }
144
- }
145
- export function buildTracer(metrics, costQuota, modelUsage, fleetUsage, fleetLease, quotaWeightFor, promptManifests) {
65
+ export { promptManifestRecordOf, configAssembledRecordOf, PromptManifestTracker, } from "./observability/prompt-manifest.js";
66
+ export function createTracer(metrics, costQuota, modelUsage, fleetUsage, fleetLease, quotaWeightFor, promptManifests) {
146
67
  const toolName = cardinalityGuard(256, () => metrics.inc("metric_label_overflow_total", { label: "tool_name" }));
147
68
  const modelId = cardinalityGuard(256, () => metrics.inc("metric_label_overflow_total", { label: "model" }));
148
69
  const providerName = cardinalityGuard(64, () => metrics.inc("metric_label_overflow_total", { label: "provider" }));
@@ -200,7 +121,7 @@ export function cacheFamilyOfMirror(model) {
200
121
  return "input-includes-cached";
201
122
  return model.api === "anthropic-messages" || model.api === "bedrock-converse-stream" ? "input-excludes-cached" : "input-includes-cached";
202
123
  }
203
- export function buildSideQueryAccountant(metrics, costQuota, fleetUsage, fleetLease, quotaWeightFor) {
124
+ export function createSideQueryAccountant(metrics, costQuota, fleetUsage, fleetLease, quotaWeightFor) {
204
125
  return (principal, r) => {
205
126
  const input = typeof r.usage?.input === "number" ? r.usage.input : 0;
206
127
  const output = typeof r.usage?.output === "number" ? r.usage.output : 0;
@@ -16,8 +16,9 @@ export interface SandboxFileSendDeps {
16
16
  prepare: (filename: string | undefined, scope?: string) => PreparedDirectUpload;
17
17
  maxBytes: number;
18
18
  }
19
- export declare function createSandboxFileSend(deps: SandboxFileSendDeps): (path: string, ctx: {
19
+ export type SandboxFileSend = (path: string, ctx: {
20
20
  taskId?: string;
21
21
  principal?: string;
22
22
  }) => Promise<IssuedFileLink>;
23
+ export declare function createSandboxFileSend(deps: SandboxFileSendDeps): SandboxFileSend;
23
24
  //# sourceMappingURL=sandbox-file-send.d.ts.map
@@ -2,7 +2,7 @@ import type { SealedKeyPoison } from "./sealed-key.js";
2
2
  import type { McpServerSpec, Model, ModelRoles } from "@sema-agent/core";
3
3
  import type { ApprovalHmacKey, PrincipalJwtKey } from "./auth-keys.js";
4
4
  import type { ElicitationThrottle } from "./elicitation.js";
5
- import type { InfraCostRates } from "./finance/cost-taxonomy.js";
5
+ import type { InfraCostRates } from "./observability/cost-taxonomy.js";
6
6
  import type { Autonomy, CommandRule } from "./runtime-governance.js";
7
7
  export interface ScopedMcpServer {
8
8
  scenarios: string[];
@@ -8,12 +8,13 @@ export interface ElicitationFrame {
8
8
  mode?: "form";
9
9
  action?: McpElicitResponse["action"];
10
10
  }
11
- export interface ElicitRunContext {
11
+ export interface ElicitationRunContext {
12
12
  taskId: string;
13
13
  owner: string | null;
14
14
  emit: (frame: ElicitationFrame) => void | Promise<void>;
15
15
  abortSignal?: AbortSignal;
16
16
  }
17
+ export type ElicitRunContext = ElicitationRunContext;
17
18
  export interface ElicitationThrottle {
18
19
  maxConcurrentPerRun: number;
19
20
  maxTotalPerRun: number;
@@ -21,13 +22,14 @@ export interface ElicitationThrottle {
21
22
  ttlMs: number;
22
23
  }
23
24
  export declare const DEFAULT_ELICITATION_THROTTLE: ElicitationThrottle;
24
- export declare function parseElicitResponse(body: unknown): {
25
+ export declare function parseElicitationResponse(body: unknown): {
25
26
  ok: true;
26
27
  value: McpElicitResponse;
27
28
  } | {
28
29
  ok: false;
29
30
  error: string;
30
31
  };
32
+ export declare const parseElicitResponse: typeof parseElicitationResponse;
31
33
  export declare class ElicitationCoordinator {
32
34
  private readonly als;
33
35
  private readonly pending;
@@ -35,7 +37,7 @@ export declare class ElicitationCoordinator {
35
37
  private readonly throttle;
36
38
  private readonly now;
37
39
  constructor(throttle?: ElicitationThrottle, now?: () => number);
38
- runWithContext<T>(ctx: ElicitRunContext, fn: () => Promise<T>): Promise<T>;
40
+ runWithContext<T>(ctx: ElicitationRunContext, fn: () => Promise<T>): Promise<T>;
39
41
  elicit: (req: McpElicitRequest, signal?: AbortSignal) => Promise<McpElicitResponse>;
40
42
  respond(id: string, principal: string | undefined, body: unknown): {
41
43
  status: number;
@@ -9,7 +9,7 @@ export const DEFAULT_ELICITATION_THROTTLE = {
9
9
  minIntervalMsPerServer: 1_000,
10
10
  ttlMs: 5 * 60_000,
11
11
  };
12
- export function parseElicitResponse(body) {
12
+ export function parseElicitationResponse(body) {
13
13
  if (body === null || typeof body !== "object" || Array.isArray(body))
14
14
  return { ok: false, error: "body must be an object" };
15
15
  const b = body;
@@ -32,6 +32,7 @@ export function parseElicitResponse(body) {
32
32
  }
33
33
  return { ok: true, value: { action: b.action } };
34
34
  }
35
+ export const parseElicitResponse = parseElicitationResponse;
35
36
  function boundSchema(schema) {
36
37
  if (schema === undefined)
37
38
  return undefined;
@@ -126,7 +127,7 @@ export class ElicitationCoordinator {
126
127
  return answer;
127
128
  };
128
129
  respond(id, principal, body) {
129
- const parsed = parseElicitResponse(body);
130
+ const parsed = parseElicitationResponse(body);
130
131
  if (!parsed.ok)
131
132
  return { status: 400, body: { error: parsed.error } };
132
133
  const entry = this.pending.get(id);
@@ -118,6 +118,7 @@ export interface BgNotification {
118
118
  costMicroUsd?: number;
119
119
  };
120
120
  transcriptId?: string;
121
+ completionId?: string;
121
122
  rootSessionId?: string;
122
123
  ownerScope?: string;
123
124
  ownerSessionId?: string;
@@ -391,6 +391,7 @@ export function fleetBackgroundChildPublisher(bus, log) {
391
391
  ...(e.summary ? { summary: redactSecrets(e.summary) } : {}),
392
392
  scope: (m.sessionScoped || e.sessionScoped) ? "session" : "task",
393
393
  ...(m.parentTaskId ? { parentTaskId: m.parentTaskId } : m.resolvedParentId ? { parentTaskId: m.resolvedParentId } : {}),
394
+ ...(e.completionId ? { completionId: e.completionId } : {}),
394
395
  ...(e.stoppedBy ? { stoppedBy: e.stoppedBy } : {}),
395
396
  ...(e.resumable !== undefined ? { resumable: e.resumable } : {}),
396
397
  ...(e.recentSteps !== undefined
@@ -65,7 +65,7 @@ export declare class FleetLeaseManager {
65
65
  private issueOrRenew;
66
66
  private issueOrRenewInner;
67
67
  }
68
- export declare function buildFleetLeaseFromEnv(cfg: {
68
+ export declare function createFleetLeaseFromEnv(cfg: {
69
69
  configCenter?: {
70
70
  baseUrl: string;
71
71
  token: string;
@@ -115,7 +115,7 @@ export class FleetLeaseManager {
115
115
  }
116
116
  }
117
117
  }
118
- export function buildFleetLeaseFromEnv(cfg, opts) {
118
+ export function createFleetLeaseFromEnv(cfg, opts) {
119
119
  const cc = cfg.configCenter;
120
120
  if (!cc?.baseUrl || !cc.token || !cc.worker)
121
121
  return undefined;
@@ -11,6 +11,10 @@ export type HookModelPick = {
11
11
  ok: false;
12
12
  error: string;
13
13
  };
14
+ export interface HookLlm {
15
+ hookModelFor: (requested?: string) => HookModelPick;
16
+ hookLlm: HookLlmCall;
17
+ }
14
18
  export declare function createHookLlm(deps: {
15
19
  config: ServiceConfig;
16
20
  getKeyResolver: () => ((model: Model) => Promise<{
@@ -20,8 +24,5 @@ export declare function createHookLlm(deps: {
20
24
  inc: (name: string, labels?: Record<string, string>) => void;
21
25
  };
22
26
  fetchImpl?: typeof fetch;
23
- }): {
24
- hookModelFor: (requested?: string) => HookModelPick;
25
- hookLlm: HookLlmCall;
26
- };
27
+ }): HookLlm;
27
28
  //# sourceMappingURL=hook-llm.d.ts.map
@@ -49,6 +49,6 @@ export interface LlmHookExtra {
49
49
  system: string;
50
50
  transcript: string;
51
51
  }
52
- export declare function buildTaskHooks(config: HooksConfig, ctx: HookRunnerContext): Hooks | undefined;
52
+ export declare function createTaskHooks(config: HooksConfig, ctx: HookRunnerContext): Hooks | undefined;
53
53
  export declare function composeHooks(deployment: Hooks | undefined, task: Hooks): Hooks;
54
54
  //# sourceMappingURL=hook-runner.d.ts.map
@@ -494,7 +494,7 @@ async function runObserveOnlyEvent(event, groups, matchValue, payload, ctx, once
494
494
  }
495
495
  }
496
496
  }
497
- export function buildTaskHooks(config, ctx) {
497
+ export function createTaskHooks(config, ctx) {
498
498
  const configured = Object.keys(config).filter((e) => (config[e]?.length ?? 0) > 0);
499
499
  const dark = configured.filter((e) => HOOK_EVENT_OWNER[e] === "engine" && !LIT_EVENTS.includes(e));
500
500
  if (dark.length > 0) {