@nylorun/core 0.6.0-beta → 0.7.0-beta

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/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @nylorun/core
2
2
 
3
+ ## 0.7.0-beta
4
+
5
+ ### Minor Changes
6
+
7
+ - a322696: **Derived principals** (optional Host feature `derived-principals`): a client that holds the admin key no longer needs to store an application key.
8
+
9
+ - `admin.createTenant({ name, principals: ["babai"] })` registers each named principal by the hash of its derived key, and `admin.deriveTenantKey(tenantId, principalId)` (or `deriveTenantKey(adminKey, tenantId, principalId)`) recomputes the key when needed.
10
+ - `POST /v1/admin/tenants` accepts `derivedPrincipals: [{ id, credentialHash }]`. Ids match `^[a-z][a-z0-9-]{0,31}$` and `studio` is reserved; duplicate ids or credentials answer `400`. A retried create must name the same principals.
11
+ - `createTenant` with `principals` throws `incompatible_host` before sending anything to a Host without the feature.
12
+
13
+ - 844bff3: **Act for a person: `Nylorun-Subject` and `Nylorun-Scopes`.** An app server that holds the Tenant key can name the person each request is for, and the Runtime enforces it (optional Host feature `subject-headers`).
14
+
15
+ - `client.as(subject, { scopes })` in `@nylorun/agents` sends both headers on every call, event streams included. Scopes: `agents:read`, `agents:write`, `sessions:own`, `vaults:own`, `tenant:settings`; default `["sessions:own"]`.
16
+ - The Runtime limits a subject to the routes its scopes allow (`403 scope_required`) and to its own sessions and vaults: another owner's session, vault or sandbox is the same `404` as a missing one, including `PUT` on its session id (was `409`). Reset, config seed, executors, actions and the sandbox tool routes are open to no subject. Only application keys may send the headers.
17
+ - The AG-UI handler calls the Runtime as each person and requires `subject-headers`; new optional `scopes` option. The host's `session()` parameters can no longer replace a session's id, agent or owner.
18
+ - Core exports `SUBJECT_HEADER`, `SCOPES_HEADER`, `SUBJECT_SCOPES` and `parseSubjectHeaders`. Postgres Tenant schemas migrate to version 2 (an indexed session owner column).
19
+
20
+ Requests without `Nylorun-Subject` are unchanged.
21
+
22
+ - a322696: **The session log now carries what a chat UI shows** (optional Host feature `transcript-events`).
23
+
24
+ - `message.assistant` for each completed model step: `{ invocationId, text, toolCalls: [{ callId, name, input }], agent? }`.
25
+ - `tool.completed` for an MCP or sandbox tool: `{ invocationId, callId, capabilityId, toolName, output }`, or `error: { code, message }` for a tool error.
26
+ - Tool `action.pending` and `action.completed` events, and `delegation.started` / `delegation.completed`, carry the model's `callId` (and `invocationId` on actions).
27
+ - Events are written in the transaction that completes the effect, so a replay writes none.
28
+ - `@nylorun/core/contracts` adds payload schemas and `parseTranscriptEvent(event)`; `LiveEvent.payload` stays `unknown`.
29
+
30
+ Fix: a tool with both `approval` and an `output` schema now pauses for approval. The Runtime validated its `interaction-required` result against the output schema and failed the tool with `tool.invalid-output`; `denied`, `interaction-required` and `deferred` results are no longer validated.
31
+
3
32
  ## 0.6.0-beta
4
33
 
5
34
  ### Minor Changes
@@ -6,8 +6,13 @@ export type ProtocolFeature = (typeof PROTOCOL_FEATURES)[number];
6
6
  * Host features no client requires: a client that uses one checks the Host's `/health`
7
7
  * for it first. `tenant-fixture-model`: `PUT /v1/tenant/config/seed` accepts
8
8
  * `fixtureModel: true` (the Tenant's model calls use the Runtime's fixture model).
9
+ * `transcript-events`: the log carries `message.assistant` and `tool.completed`, and
10
+ * tool `action.*` events carry `callId` and `invocationId`. `derived-principals`:
11
+ * `POST /v1/admin/tenants` accepts `derivedPrincipals`. `subject-headers`: an application
12
+ * principal may act for a subject with `Nylorun-Subject` and `Nylorun-Scopes`, and the Runtime
13
+ * enforces the scopes and the subject's ownership of sessions and vaults.
9
14
  */
10
- export declare const OPTIONAL_HOST_FEATURES: readonly ["tenant-fixture-model"];
15
+ export declare const OPTIONAL_HOST_FEATURES: readonly ["tenant-fixture-model", "transcript-events", "derived-principals", "subject-headers"];
11
16
  export type OptionalHostFeature = (typeof OPTIONAL_HOST_FEATURES)[number];
12
17
  export interface ProtocolRange {
13
18
  min: number;
@@ -18,10 +23,16 @@ export declare const HOST_PROTOCOL: ProtocolRange;
18
23
  export declare const DEFINITION_SCHEMA_VERSION = 2;
19
24
  export declare const TENANT_HEADER = "Nylorun-Tenant";
20
25
  export declare const PROTOCOL_HEADER = "Nylorun-Protocol";
21
- export declare const ERROR_CODES: readonly ["not_found", "protocol_unsupported", "host_rejected", "origin_rejected", "unsupported_media_type", "tenant_conflict", "active_work", "connection_missing", "incompatible_host"];
26
+ /** The subject an application principal acts for (Host feature `subject-headers`). */
27
+ export declare const SUBJECT_HEADER = "Nylorun-Subject";
28
+ /** The space-separated scopes of that subject; required with `Nylorun-Subject`. */
29
+ export declare const SCOPES_HEADER = "Nylorun-Scopes";
30
+ export declare const ERROR_CODES: readonly ["not_found", "protocol_unsupported", "host_rejected", "origin_rejected", "unsupported_media_type", "tenant_conflict", "active_work", "connection_missing", "incompatible_host", "subject_invalid", "scope_required"];
22
31
  export type ErrorCode = (typeof ERROR_CODES)[number];
23
32
  export declare const TENANT_ID_PATTERN: RegExp;
24
33
  export declare const PRINCIPAL_ID_PATTERN: RegExp;
34
+ /** A derived principal's id names its client, e.g. `babai`; `studio` is reserved. */
35
+ export declare const DERIVED_PRINCIPAL_ID_PATTERN: RegExp;
25
36
  export declare function isTenantId(value: unknown): value is string;
26
37
  export declare function isPrincipalId(value: unknown): value is string;
27
38
  /**
@@ -9,8 +9,18 @@ export const PROTOCOL_FEATURES = [
9
9
  * Host features no client requires: a client that uses one checks the Host's `/health`
10
10
  * for it first. `tenant-fixture-model`: `PUT /v1/tenant/config/seed` accepts
11
11
  * `fixtureModel: true` (the Tenant's model calls use the Runtime's fixture model).
12
+ * `transcript-events`: the log carries `message.assistant` and `tool.completed`, and
13
+ * tool `action.*` events carry `callId` and `invocationId`. `derived-principals`:
14
+ * `POST /v1/admin/tenants` accepts `derivedPrincipals`. `subject-headers`: an application
15
+ * principal may act for a subject with `Nylorun-Subject` and `Nylorun-Scopes`, and the Runtime
16
+ * enforces the scopes and the subject's ownership of sessions and vaults.
12
17
  */
13
- export const OPTIONAL_HOST_FEATURES = ["tenant-fixture-model"];
18
+ export const OPTIONAL_HOST_FEATURES = [
19
+ "tenant-fixture-model",
20
+ "transcript-events",
21
+ "derived-principals",
22
+ "subject-headers",
23
+ ];
14
24
  export const HOST_PROTOCOL = {
15
25
  min: 2,
16
26
  max: 2,
@@ -19,6 +29,10 @@ export const HOST_PROTOCOL = {
19
29
  export const DEFINITION_SCHEMA_VERSION = 2;
20
30
  export const TENANT_HEADER = "Nylorun-Tenant";
21
31
  export const PROTOCOL_HEADER = "Nylorun-Protocol";
32
+ /** The subject an application principal acts for (Host feature `subject-headers`). */
33
+ export const SUBJECT_HEADER = "Nylorun-Subject";
34
+ /** The space-separated scopes of that subject; required with `Nylorun-Subject`. */
35
+ export const SCOPES_HEADER = "Nylorun-Scopes";
22
36
  export const ERROR_CODES = [
23
37
  "not_found",
24
38
  "protocol_unsupported",
@@ -29,11 +43,15 @@ export const ERROR_CODES = [
29
43
  "active_work",
30
44
  "connection_missing",
31
45
  "incompatible_host",
46
+ "subject_invalid",
47
+ "scope_required",
32
48
  ];
33
49
  /** Crockford Base32 alphabet (lowercase); excludes i, l, o, u. */
34
50
  const CROCKFORD = "0123456789abcdefghjkmnpqrstvwxyz";
35
51
  export const TENANT_ID_PATTERN = /^tn_[0-9a-hjkmnp-tv-z]{26}$/;
36
52
  export const PRINCIPAL_ID_PATTERN = /^pr_[0-9a-hjkmnp-tv-z]{26}$/;
53
+ /** A derived principal's id names its client, e.g. `babai`; `studio` is reserved. */
54
+ export const DERIVED_PRINCIPAL_ID_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
37
55
  export function isTenantId(value) {
38
56
  return typeof value === "string" && TENANT_ID_PATTERN.test(value);
39
57
  }
@@ -314,6 +314,8 @@ export declare const RejectedResponseSchema: z.ZodObject<{
314
314
  not_found: "not_found";
315
315
  origin_rejected: "origin_rejected";
316
316
  protocol_unsupported: "protocol_unsupported";
317
+ scope_required: "scope_required";
318
+ subject_invalid: "subject_invalid";
317
319
  tenant_conflict: "tenant_conflict";
318
320
  unsupported_media_type: "unsupported_media_type";
319
321
  }>;
@@ -492,6 +494,228 @@ export declare const ActionSchema: z.ZodUnion<readonly [z.ZodObject<{
492
494
  key: z.ZodString;
493
495
  }, z.core.$strict>]>;
494
496
  export type Action = z.infer<typeof ActionSchema>;
497
+ /** `message.assistant`: one completed model step. `invocationId` is the model call's. */
498
+ export declare const AssistantMessagePayloadSchema: z.ZodObject<{
499
+ agent: z.ZodOptional<z.ZodObject<{
500
+ id: z.ZodString;
501
+ path: z.ZodString;
502
+ delegationId: z.ZodOptional<z.ZodString>;
503
+ }, z.core.$loose>>;
504
+ invocationId: z.ZodString;
505
+ text: z.ZodString;
506
+ toolCalls: z.ZodArray<z.ZodObject<{
507
+ callId: z.ZodString;
508
+ name: z.ZodString;
509
+ input: z.ZodUnknown;
510
+ }, z.core.$loose>>;
511
+ }, z.core.$loose>;
512
+ /** `tool.completed`: an MCP or sandbox tool the Runtime ran. `error` for a tool error. */
513
+ export declare const ToolCompletedPayloadSchema: z.ZodObject<{
514
+ agent: z.ZodOptional<z.ZodObject<{
515
+ id: z.ZodString;
516
+ path: z.ZodString;
517
+ delegationId: z.ZodOptional<z.ZodString>;
518
+ }, z.core.$loose>>;
519
+ callId: z.ZodString;
520
+ invocationId: z.ZodString;
521
+ capabilityId: z.ZodString;
522
+ toolName: z.ZodString;
523
+ output: z.ZodOptional<z.ZodUnknown>;
524
+ error: z.ZodOptional<z.ZodObject<{
525
+ code: z.ZodString;
526
+ message: z.ZodString;
527
+ }, z.core.$loose>>;
528
+ }, z.core.$loose>;
529
+ export declare const ActionPendingPayloadSchema: z.ZodObject<{
530
+ agent: z.ZodOptional<z.ZodObject<{
531
+ id: z.ZodString;
532
+ path: z.ZodString;
533
+ delegationId: z.ZodOptional<z.ZodString>;
534
+ }, z.core.$loose>>;
535
+ actionId: z.ZodString;
536
+ kind: z.ZodString;
537
+ toolName: z.ZodOptional<z.ZodString>;
538
+ callId: z.ZodOptional<z.ZodString>;
539
+ invocationId: z.ZodOptional<z.ZodString>;
540
+ input: z.ZodUnknown;
541
+ }, z.core.$loose>;
542
+ export declare const ActionCompletedPayloadSchema: z.ZodObject<{
543
+ agent: z.ZodOptional<z.ZodObject<{
544
+ id: z.ZodString;
545
+ path: z.ZodString;
546
+ delegationId: z.ZodOptional<z.ZodString>;
547
+ }, z.core.$loose>>;
548
+ actionId: z.ZodString;
549
+ kind: z.ZodString;
550
+ toolName: z.ZodOptional<z.ZodString>;
551
+ callId: z.ZodOptional<z.ZodString>;
552
+ invocationId: z.ZodOptional<z.ZodString>;
553
+ result: z.ZodUnknown;
554
+ }, z.core.$loose>;
555
+ export declare const ActionUncertainPayloadSchema: z.ZodObject<{
556
+ agent: z.ZodOptional<z.ZodObject<{
557
+ id: z.ZodString;
558
+ path: z.ZodString;
559
+ delegationId: z.ZodOptional<z.ZodString>;
560
+ }, z.core.$loose>>;
561
+ actionId: z.ZodString;
562
+ }, z.core.$loose>;
563
+ export declare const EffectUncertainPayloadSchema: z.ZodObject<{
564
+ effectId: z.ZodString;
565
+ message: z.ZodOptional<z.ZodString>;
566
+ }, z.core.$loose>;
567
+ export declare const TurnCompletedPayloadSchema: z.ZodObject<{
568
+ output: z.ZodUnknown;
569
+ }, z.core.$loose>;
570
+ export declare const TurnPausedPayloadSchema: z.ZodObject<{
571
+ interactions: z.ZodArray<z.ZodObject<{
572
+ invocationId: z.ZodString;
573
+ interaction: z.ZodObject<{
574
+ id: z.ZodString;
575
+ kind: z.ZodString;
576
+ }, z.core.$loose>;
577
+ status: z.ZodOptional<z.ZodString>;
578
+ }, z.core.$loose>>;
579
+ }, z.core.$loose>;
580
+ /** Either `{ error: { code, message } }` or, when a segment threw, `{ message }`. */
581
+ export declare const TurnFailedPayloadSchema: z.ZodObject<{
582
+ error: z.ZodOptional<z.ZodObject<{
583
+ code: z.ZodOptional<z.ZodString>;
584
+ message: z.ZodOptional<z.ZodString>;
585
+ }, z.core.$loose>>;
586
+ message: z.ZodOptional<z.ZodString>;
587
+ }, z.core.$loose>;
588
+ export declare const TurnCancelledPayloadSchema: z.ZodObject<{
589
+ reason: z.ZodOptional<z.ZodString>;
590
+ }, z.core.$loose>;
591
+ /** Lifecycle of an agent used as a tool. `agent.delegationId` is the parent call's invocation. */
592
+ export declare const DelegationPayloadSchema: z.ZodObject<{
593
+ agent: z.ZodObject<{
594
+ id: z.ZodString;
595
+ path: z.ZodString;
596
+ delegationId: z.ZodOptional<z.ZodString>;
597
+ }, z.core.$loose>;
598
+ callId: z.ZodOptional<z.ZodString>;
599
+ }, z.core.$loose>;
600
+ declare const TRANSCRIPT_PAYLOADS: {
601
+ readonly "message.assistant": z.ZodObject<{
602
+ agent: z.ZodOptional<z.ZodObject<{
603
+ id: z.ZodString;
604
+ path: z.ZodString;
605
+ delegationId: z.ZodOptional<z.ZodString>;
606
+ }, z.core.$loose>>;
607
+ invocationId: z.ZodString;
608
+ text: z.ZodString;
609
+ toolCalls: z.ZodArray<z.ZodObject<{
610
+ callId: z.ZodString;
611
+ name: z.ZodString;
612
+ input: z.ZodUnknown;
613
+ }, z.core.$loose>>;
614
+ }, z.core.$loose>;
615
+ readonly "tool.completed": z.ZodObject<{
616
+ agent: z.ZodOptional<z.ZodObject<{
617
+ id: z.ZodString;
618
+ path: z.ZodString;
619
+ delegationId: z.ZodOptional<z.ZodString>;
620
+ }, z.core.$loose>>;
621
+ callId: z.ZodString;
622
+ invocationId: z.ZodString;
623
+ capabilityId: z.ZodString;
624
+ toolName: z.ZodString;
625
+ output: z.ZodOptional<z.ZodUnknown>;
626
+ error: z.ZodOptional<z.ZodObject<{
627
+ code: z.ZodString;
628
+ message: z.ZodString;
629
+ }, z.core.$loose>>;
630
+ }, z.core.$loose>;
631
+ readonly "action.pending": z.ZodObject<{
632
+ agent: z.ZodOptional<z.ZodObject<{
633
+ id: z.ZodString;
634
+ path: z.ZodString;
635
+ delegationId: z.ZodOptional<z.ZodString>;
636
+ }, z.core.$loose>>;
637
+ actionId: z.ZodString;
638
+ kind: z.ZodString;
639
+ toolName: z.ZodOptional<z.ZodString>;
640
+ callId: z.ZodOptional<z.ZodString>;
641
+ invocationId: z.ZodOptional<z.ZodString>;
642
+ input: z.ZodUnknown;
643
+ }, z.core.$loose>;
644
+ readonly "action.completed": z.ZodObject<{
645
+ agent: z.ZodOptional<z.ZodObject<{
646
+ id: z.ZodString;
647
+ path: z.ZodString;
648
+ delegationId: z.ZodOptional<z.ZodString>;
649
+ }, z.core.$loose>>;
650
+ actionId: z.ZodString;
651
+ kind: z.ZodString;
652
+ toolName: z.ZodOptional<z.ZodString>;
653
+ callId: z.ZodOptional<z.ZodString>;
654
+ invocationId: z.ZodOptional<z.ZodString>;
655
+ result: z.ZodUnknown;
656
+ }, z.core.$loose>;
657
+ readonly "action.uncertain": z.ZodObject<{
658
+ agent: z.ZodOptional<z.ZodObject<{
659
+ id: z.ZodString;
660
+ path: z.ZodString;
661
+ delegationId: z.ZodOptional<z.ZodString>;
662
+ }, z.core.$loose>>;
663
+ actionId: z.ZodString;
664
+ }, z.core.$loose>;
665
+ readonly "effect.uncertain": z.ZodObject<{
666
+ effectId: z.ZodString;
667
+ message: z.ZodOptional<z.ZodString>;
668
+ }, z.core.$loose>;
669
+ readonly "turn.completed": z.ZodObject<{
670
+ output: z.ZodUnknown;
671
+ }, z.core.$loose>;
672
+ readonly "turn.paused": z.ZodObject<{
673
+ interactions: z.ZodArray<z.ZodObject<{
674
+ invocationId: z.ZodString;
675
+ interaction: z.ZodObject<{
676
+ id: z.ZodString;
677
+ kind: z.ZodString;
678
+ }, z.core.$loose>;
679
+ status: z.ZodOptional<z.ZodString>;
680
+ }, z.core.$loose>>;
681
+ }, z.core.$loose>;
682
+ readonly "turn.failed": z.ZodObject<{
683
+ error: z.ZodOptional<z.ZodObject<{
684
+ code: z.ZodOptional<z.ZodString>;
685
+ message: z.ZodOptional<z.ZodString>;
686
+ }, z.core.$loose>>;
687
+ message: z.ZodOptional<z.ZodString>;
688
+ }, z.core.$loose>;
689
+ readonly "turn.cancelled": z.ZodObject<{
690
+ reason: z.ZodOptional<z.ZodString>;
691
+ }, z.core.$loose>;
692
+ readonly "delegation.started": z.ZodObject<{
693
+ agent: z.ZodObject<{
694
+ id: z.ZodString;
695
+ path: z.ZodString;
696
+ delegationId: z.ZodOptional<z.ZodString>;
697
+ }, z.core.$loose>;
698
+ callId: z.ZodOptional<z.ZodString>;
699
+ }, z.core.$loose>;
700
+ readonly "delegation.completed": z.ZodObject<{
701
+ agent: z.ZodObject<{
702
+ id: z.ZodString;
703
+ path: z.ZodString;
704
+ delegationId: z.ZodOptional<z.ZodString>;
705
+ }, z.core.$loose>;
706
+ callId: z.ZodOptional<z.ZodString>;
707
+ }, z.core.$loose>;
708
+ };
709
+ export type TranscriptEventType = keyof typeof TRANSCRIPT_PAYLOADS;
710
+ export declare const TRANSCRIPT_EVENT_TYPES: readonly TranscriptEventType[];
711
+ export type TranscriptEvent = {
712
+ [K in TranscriptEventType]: Omit<LiveEvent, "type" | "payload"> & {
713
+ type: K;
714
+ payload: z.infer<(typeof TRANSCRIPT_PAYLOADS)[K]>;
715
+ };
716
+ }[TranscriptEventType];
717
+ /** Types a transcript event's payload; `undefined` for other types or a malformed payload. */
718
+ export declare function parseTranscriptEvent(event: LiveEvent): TranscriptEvent | undefined;
495
719
  export declare const ActionClaimRequestSchema: z.ZodObject<{
496
720
  requestId: z.ZodString;
497
721
  implementationVersion: z.ZodString;
@@ -758,6 +982,10 @@ export declare const CreateTenantRequestSchema: z.ZodObject<{
758
982
  credentialHash: z.ZodString;
759
983
  idempotencyKey: z.ZodString;
760
984
  studioCredentialHash: z.ZodOptional<z.ZodString>;
985
+ derivedPrincipals: z.ZodOptional<z.ZodArray<z.ZodObject<{
986
+ id: z.ZodString;
987
+ credentialHash: z.ZodString;
988
+ }, z.core.$strict>>>;
761
989
  }, z.core.$strict>;
762
990
  export type CreateTenantRequest = z.infer<typeof CreateTenantRequestSchema>;
763
991
  export declare const AdminTenantSchema: z.ZodObject<{
@@ -1043,3 +1271,22 @@ export declare const ResetTenantRequestSchema: z.ZodObject<{
1043
1271
  }>;
1044
1272
  }, z.core.$strict>;
1045
1273
  export type ResetTenantRequest = z.infer<typeof ResetTenantRequestSchema>;
1274
+ /**
1275
+ * Acting for a subject (Host feature `subject-headers`): what an application principal may
1276
+ * narrow a request to. `sessions:own` and `vaults:own` reach only the subject's own sessions
1277
+ * and vaults; the others reach Tenant-wide resources.
1278
+ */
1279
+ export declare const SUBJECT_SCOPES: readonly ["agents:read", "agents:write", "sessions:own", "vaults:own", "tenant:settings"];
1280
+ export type SubjectScope = (typeof SUBJECT_SCOPES)[number];
1281
+ /**
1282
+ * Validates `Nylorun-Subject` and `Nylorun-Scopes`. Returns the subject and its scopes, or a
1283
+ * message naming what is wrong. Scopes are required: the Runtime never grants a default.
1284
+ */
1285
+ export declare function parseSubjectHeaders(subject: string, scopes: string | undefined): {
1286
+ ok: true;
1287
+ subject: string;
1288
+ scopes: ReadonlySet<SubjectScope>;
1289
+ } | {
1290
+ ok: false;
1291
+ message: string;
1292
+ };
package/dist/contracts.js CHANGED
@@ -5,6 +5,7 @@ import { hookListIssue } from "./definition/hooks.js";
5
5
  import { DELEGATE_INPUT_SCHEMA } from "./definition/delegate.js";
6
6
  import { canonical } from "./utils/canonical.js";
7
7
  export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
8
+ import { DERIVED_PRINCIPAL_ID_PATTERN } from "./compatibility.js";
8
9
  import { ERROR_CODES } from "./compatibility.js";
9
10
  export const RequestIdSchema = z.string().min(1);
10
11
  export const IdempotencyKeySchema = z.string().min(1).max(256);
@@ -667,6 +668,126 @@ export const ActionSchema = z.union([
667
668
  fnActionSchema,
668
669
  verifyActionSchema,
669
670
  ]);
671
+ /**
672
+ * Transcript events (Host feature `transcript-events`): the log entries a chat UI
673
+ * renders. `LiveEvent.payload` stays `unknown` on the wire; `parseTranscriptEvent`
674
+ * types the ones a client reads. Objects pass unknown fields through, so a newer
675
+ * Host can add fields without breaking older clients.
676
+ */
677
+ const eventAgent = { agent: AgentRefSchema.passthrough().optional() };
678
+ const toolIds = {
679
+ /** The model's tool call id. */
680
+ callId: z.string().min(1),
681
+ /** The harness invocation of the call; interactions refer to it. */
682
+ invocationId: z.string().min(1),
683
+ };
684
+ /** `message.assistant`: one completed model step. `invocationId` is the model call's. */
685
+ export const AssistantMessagePayloadSchema = z
686
+ .object({
687
+ invocationId: z.string().min(1),
688
+ text: z.string(),
689
+ toolCalls: z.array(z
690
+ .object({
691
+ callId: z.string().min(1),
692
+ name: z.string().min(1),
693
+ input: z.unknown(),
694
+ })
695
+ .passthrough()),
696
+ ...eventAgent,
697
+ })
698
+ .passthrough();
699
+ /** `tool.completed`: an MCP or sandbox tool the Runtime ran. `error` for a tool error. */
700
+ export const ToolCompletedPayloadSchema = z
701
+ .object({
702
+ ...toolIds,
703
+ capabilityId: z.string().min(1),
704
+ toolName: z.string().min(1),
705
+ output: z.unknown().optional(),
706
+ error: z.object({ code: z.string(), message: z.string() }).passthrough().optional(),
707
+ ...eventAgent,
708
+ })
709
+ .passthrough();
710
+ /** `action.pending` and `action.completed`; tool actions carry `callId` and `invocationId`. */
711
+ const actionEventBase = {
712
+ actionId: z.string().min(1),
713
+ kind: z.string(),
714
+ toolName: z.string().optional(),
715
+ callId: z.string().optional(),
716
+ invocationId: z.string().optional(),
717
+ ...eventAgent,
718
+ };
719
+ export const ActionPendingPayloadSchema = z
720
+ .object({ ...actionEventBase, input: z.unknown() })
721
+ .passthrough();
722
+ export const ActionCompletedPayloadSchema = z
723
+ .object({ ...actionEventBase, result: z.unknown() })
724
+ .passthrough();
725
+ export const ActionUncertainPayloadSchema = z
726
+ .object({ actionId: z.string().min(1), ...eventAgent })
727
+ .passthrough();
728
+ export const EffectUncertainPayloadSchema = z
729
+ .object({ effectId: z.string().min(1), message: z.string().optional() })
730
+ .passthrough();
731
+ export const TurnCompletedPayloadSchema = z
732
+ .object({ output: z.unknown() })
733
+ .passthrough();
734
+ export const TurnPausedPayloadSchema = z
735
+ .object({
736
+ interactions: z.array(z
737
+ .object({
738
+ invocationId: z.string().min(1),
739
+ interaction: z
740
+ .object({ id: z.string().min(1), kind: z.string() })
741
+ .passthrough(),
742
+ status: z.string().optional(),
743
+ })
744
+ .passthrough()),
745
+ })
746
+ .passthrough();
747
+ /** Either `{ error: { code, message } }` or, when a segment threw, `{ message }`. */
748
+ export const TurnFailedPayloadSchema = z
749
+ .object({
750
+ error: z
751
+ .object({ code: z.string().optional(), message: z.string().optional() })
752
+ .passthrough()
753
+ .optional(),
754
+ message: z.string().optional(),
755
+ })
756
+ .passthrough();
757
+ export const TurnCancelledPayloadSchema = z
758
+ .object({ reason: z.string().optional() })
759
+ .passthrough();
760
+ /** Lifecycle of an agent used as a tool. `agent.delegationId` is the parent call's invocation. */
761
+ export const DelegationPayloadSchema = z
762
+ .object({
763
+ agent: AgentRefSchema.passthrough(),
764
+ callId: z.string().optional(),
765
+ })
766
+ .passthrough();
767
+ const TRANSCRIPT_PAYLOADS = {
768
+ "message.assistant": AssistantMessagePayloadSchema,
769
+ "tool.completed": ToolCompletedPayloadSchema,
770
+ "action.pending": ActionPendingPayloadSchema,
771
+ "action.completed": ActionCompletedPayloadSchema,
772
+ "action.uncertain": ActionUncertainPayloadSchema,
773
+ "effect.uncertain": EffectUncertainPayloadSchema,
774
+ "turn.completed": TurnCompletedPayloadSchema,
775
+ "turn.paused": TurnPausedPayloadSchema,
776
+ "turn.failed": TurnFailedPayloadSchema,
777
+ "turn.cancelled": TurnCancelledPayloadSchema,
778
+ "delegation.started": DelegationPayloadSchema,
779
+ "delegation.completed": DelegationPayloadSchema,
780
+ };
781
+ export const TRANSCRIPT_EVENT_TYPES = Object.keys(TRANSCRIPT_PAYLOADS);
782
+ /** Types a transcript event's payload; `undefined` for other types or a malformed payload. */
783
+ export function parseTranscriptEvent(event) {
784
+ if (!Object.hasOwn(TRANSCRIPT_PAYLOADS, event.type))
785
+ return undefined;
786
+ const parsed = TRANSCRIPT_PAYLOADS[event.type].safeParse(event.payload);
787
+ return parsed.success
788
+ ? { ...event, payload: parsed.data }
789
+ : undefined;
790
+ }
670
791
  export const ActionClaimRequestSchema = z
671
792
  .object({
672
793
  requestId: RequestIdSchema,
@@ -775,8 +896,46 @@ export const CreateTenantRequestSchema = z
775
896
  .string()
776
897
  .regex(/^[0-9a-f]{64}$/)
777
898
  .optional(),
899
+ /**
900
+ * SHA-256 of each derived principal's key (feature `derived-principals`): application
901
+ * principals whose keys the admin key derives, so their clients store no key.
902
+ */
903
+ derivedPrincipals: z
904
+ .array(z
905
+ .object({
906
+ id: z
907
+ .string()
908
+ .regex(DERIVED_PRINCIPAL_ID_PATTERN)
909
+ .refine((id) => id !== "studio", "principal id `studio` is reserved"),
910
+ credentialHash: z.string().regex(/^[0-9a-f]{64}$/),
911
+ })
912
+ .strict())
913
+ .max(16)
914
+ .optional(),
778
915
  })
779
- .strict();
916
+ .strict()
917
+ .superRefine((body, ctx) => {
918
+ const ids = new Set([body.principalId]);
919
+ const hashes = new Set([body.credentialHash]);
920
+ if (body.studioCredentialHash)
921
+ hashes.add(body.studioCredentialHash);
922
+ for (const [index, principal] of (body.derivedPrincipals ?? []).entries()) {
923
+ if (ids.has(principal.id))
924
+ ctx.addIssue({
925
+ code: "custom",
926
+ path: ["derivedPrincipals", index, "id"],
927
+ message: `Principal id ${principal.id} is used twice`,
928
+ });
929
+ if (hashes.has(principal.credentialHash))
930
+ ctx.addIssue({
931
+ code: "custom",
932
+ path: ["derivedPrincipals", index, "credentialHash"],
933
+ message: "Every principal needs its own credential",
934
+ });
935
+ ids.add(principal.id);
936
+ hashes.add(principal.credentialHash);
937
+ }
938
+ });
780
939
  export const AdminTenantSchema = z
781
940
  .object({
782
941
  id: z.string().min(1),
@@ -991,3 +1150,46 @@ export const ResetTenantRequestSchema = z
991
1150
  activeWork: z.enum(["drain", "cancel"]),
992
1151
  })
993
1152
  .strict();
1153
+ /**
1154
+ * Acting for a subject (Host feature `subject-headers`): what an application principal may
1155
+ * narrow a request to. `sessions:own` and `vaults:own` reach only the subject's own sessions
1156
+ * and vaults; the others reach Tenant-wide resources.
1157
+ */
1158
+ export const SUBJECT_SCOPES = [
1159
+ "agents:read",
1160
+ "agents:write",
1161
+ "sessions:own",
1162
+ "vaults:own",
1163
+ "tenant:settings",
1164
+ ];
1165
+ /** 1–200 visible ASCII characters; spaces only inside. */
1166
+ const SUBJECT_PATTERN = /^[\x21-\x7e](?:[\x20-\x7e]{0,198}[\x21-\x7e])?$/;
1167
+ /** Owner ids the Runtime uses itself: the host model's vault is owned by `host`. */
1168
+ const RESERVED_SUBJECTS = new Set(["host"]);
1169
+ /**
1170
+ * Validates `Nylorun-Subject` and `Nylorun-Scopes`. Returns the subject and its scopes, or a
1171
+ * message naming what is wrong. Scopes are required: the Runtime never grants a default.
1172
+ */
1173
+ export function parseSubjectHeaders(subject, scopes) {
1174
+ if (!SUBJECT_PATTERN.test(subject))
1175
+ return {
1176
+ ok: false,
1177
+ message: "Nylorun-Subject must be 1-200 visible ASCII characters",
1178
+ };
1179
+ if (RESERVED_SUBJECTS.has(subject))
1180
+ return { ok: false, message: `Subject ${subject} is reserved` };
1181
+ const names = (scopes ?? "").split(" ").filter(Boolean);
1182
+ if (names.length === 0)
1183
+ return {
1184
+ ok: false,
1185
+ message: "Nylorun-Scopes is required with Nylorun-Subject",
1186
+ };
1187
+ const unknown = names.filter((name) => !SUBJECT_SCOPES.includes(name));
1188
+ if (unknown.length > 0)
1189
+ return { ok: false, message: `Unknown scope ${unknown.join(", ")}` };
1190
+ return {
1191
+ ok: true,
1192
+ subject,
1193
+ scopes: new Set(names),
1194
+ };
1195
+ }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@nylorun/core",
3
- "version": "0.6.0-beta",
3
+ "version": "0.7.0-beta",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "description": "Shared agent definitions and wire contracts",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/nylorun/harness.git",
9
+ "url": "git+https://github.com/nylorun/agents.git",
10
10
  "directory": "core"
11
11
  },
12
12
  "files": [