@nylorun/core 0.4.0-beta → 0.6.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 +57 -0
- package/README.md +1 -1
- package/dist/compatibility.d.ts +54 -1
- package/dist/compatibility.js +191 -1
- package/dist/contracts.d.ts +554 -19
- package/dist/contracts.js +463 -29
- package/dist/define.d.ts +4 -0
- package/dist/define.js +2 -0
- package/dist/definition/sandbox-tools.js +1 -1
- package/dist/definition/variant.d.ts +7 -0
- package/dist/definition/variant.js +87 -0
- package/dist/definition/workflow/build.d.ts +38 -0
- package/dist/definition/workflow/build.js +62 -0
- package/dist/definition/workflow/chain.d.ts +49 -0
- package/dist/definition/workflow/chain.js +41 -0
- package/dist/definition/workflow/diagnostics.d.ts +14 -0
- package/dist/definition/workflow/diagnostics.js +38 -0
- package/dist/definition/workflow/index.d.ts +18 -0
- package/dist/definition/workflow/index.js +10 -0
- package/dist/definition/workflow/loop.d.ts +54 -0
- package/dist/definition/workflow/loop.js +102 -0
- package/dist/definition/workflow/map.d.ts +17 -0
- package/dist/definition/workflow/map.js +46 -0
- package/dist/definition/workflow/parallel.d.ts +19 -0
- package/dist/definition/workflow/parallel.js +37 -0
- package/dist/definition/workflow/patch.d.ts +11 -0
- package/dist/definition/workflow/patch.js +45 -0
- package/dist/definition/workflow/runnable.d.ts +40 -0
- package/dist/definition/workflow/runnable.js +251 -0
- package/dist/definition/workflow/slot.d.ts +23 -0
- package/dist/definition/workflow/slot.js +16 -0
- package/dist/definition/workflow/switch.d.ts +26 -0
- package/dist/definition/workflow/switch.js +66 -0
- package/dist/definition/workflow/types.d.ts +25 -0
- package/dist/definition/workflow/types.js +7 -0
- package/dist/definition/workflow/verdict.d.ts +20 -0
- package/dist/definition/workflow/verdict.js +25 -0
- package/dist/index.d.ts +1 -0
- package/dist/types/observe.d.ts +64 -0
- package/dist/types/workflow.d.ts +106 -0
- package/dist/types/workflow.js +1 -0
- package/dist/utils/hash.d.ts +3 -2
- package/dist/utils/hash.js +4 -4
- package/package.json +2 -2
package/dist/contracts.js
CHANGED
|
@@ -4,10 +4,19 @@ import { SANDBOX_NETWORK_PRESETS, SANDBOX_TOOL_NAMES, isSandboxHostPattern, pars
|
|
|
4
4
|
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
|
-
export
|
|
7
|
+
export { PROTOCOL_VERSION, ERROR_CODES } from "./compatibility.js";
|
|
8
|
+
import { ERROR_CODES } from "./compatibility.js";
|
|
8
9
|
export const RequestIdSchema = z.string().min(1);
|
|
9
10
|
export const IdempotencyKeySchema = z.string().min(1).max(256);
|
|
10
11
|
const jsonObject = z.record(z.string(), z.unknown());
|
|
12
|
+
const jsonValue = z.lazy(() => z.union([
|
|
13
|
+
z.string(),
|
|
14
|
+
z.number(),
|
|
15
|
+
z.boolean(),
|
|
16
|
+
z.null(),
|
|
17
|
+
z.array(jsonValue),
|
|
18
|
+
z.record(z.string(), jsonValue),
|
|
19
|
+
]));
|
|
11
20
|
const mcpServerSchema = z.discriminatedUnion("type", [
|
|
12
21
|
z
|
|
13
22
|
.object({
|
|
@@ -227,10 +236,122 @@ function delegationIssues(manifest, issue) {
|
|
|
227
236
|
issue("An agent and the agents it uses as tools must declare identical sandboxes");
|
|
228
237
|
}
|
|
229
238
|
const absolutePath = z.string().min(1).refine((value) => value.startsWith("/") || /^[A-Za-z]:[\\/]/.test(value), { message: "plugin root must be an absolute path" });
|
|
239
|
+
const workflowFnRefSchema = z.object({ fn: z.literal(true) }).strict();
|
|
240
|
+
const workflowNodeSchema = z.lazy(() => z.union([
|
|
241
|
+
z.object({ agent: z.string().min(1) }).strict(),
|
|
242
|
+
z
|
|
243
|
+
.object({
|
|
244
|
+
tool: z
|
|
245
|
+
.object({
|
|
246
|
+
name: z.string().min(1),
|
|
247
|
+
description: z.string().optional(),
|
|
248
|
+
inputSchema: jsonObject.optional(),
|
|
249
|
+
outputSchema: jsonObject.optional(),
|
|
250
|
+
})
|
|
251
|
+
.strict(),
|
|
252
|
+
})
|
|
253
|
+
.strict(),
|
|
254
|
+
z
|
|
255
|
+
.object({
|
|
256
|
+
chain: z
|
|
257
|
+
.object({
|
|
258
|
+
id: z.string().min(1),
|
|
259
|
+
steps: z.array(workflowNodeSchema).min(1),
|
|
260
|
+
})
|
|
261
|
+
.strict(),
|
|
262
|
+
})
|
|
263
|
+
.strict(),
|
|
264
|
+
z
|
|
265
|
+
.object({
|
|
266
|
+
switch: z
|
|
267
|
+
.object({
|
|
268
|
+
id: z.string().min(1),
|
|
269
|
+
on: workflowFnRefSchema,
|
|
270
|
+
cases: z.record(z.string(), workflowNodeSchema),
|
|
271
|
+
default: workflowNodeSchema.optional(),
|
|
272
|
+
})
|
|
273
|
+
.strict(),
|
|
274
|
+
})
|
|
275
|
+
.strict(),
|
|
276
|
+
z
|
|
277
|
+
.object({
|
|
278
|
+
parallel: z
|
|
279
|
+
.object({
|
|
280
|
+
id: z.string().min(1),
|
|
281
|
+
branches: z.record(z.string(), workflowNodeSchema),
|
|
282
|
+
})
|
|
283
|
+
.strict(),
|
|
284
|
+
})
|
|
285
|
+
.strict(),
|
|
286
|
+
z
|
|
287
|
+
.object({
|
|
288
|
+
map: z
|
|
289
|
+
.object({
|
|
290
|
+
id: z.string().min(1),
|
|
291
|
+
over: workflowFnRefSchema,
|
|
292
|
+
each: workflowNodeSchema,
|
|
293
|
+
})
|
|
294
|
+
.strict(),
|
|
295
|
+
})
|
|
296
|
+
.strict(),
|
|
297
|
+
z
|
|
298
|
+
.object({
|
|
299
|
+
loop: z
|
|
300
|
+
.object({
|
|
301
|
+
id: z.string().min(1),
|
|
302
|
+
run: workflowNodeSchema,
|
|
303
|
+
verify: z.union([
|
|
304
|
+
workflowFnRefSchema,
|
|
305
|
+
z.object({ agent: z.string().min(1) }).strict(),
|
|
306
|
+
z
|
|
307
|
+
.object({
|
|
308
|
+
slot: z
|
|
309
|
+
.object({
|
|
310
|
+
id: z.string().min(1).optional(),
|
|
311
|
+
input: workflowFnRefSchema.optional(),
|
|
312
|
+
run: workflowNodeSchema,
|
|
313
|
+
})
|
|
314
|
+
.strict(),
|
|
315
|
+
})
|
|
316
|
+
.strict(),
|
|
317
|
+
]),
|
|
318
|
+
decide: workflowFnRefSchema,
|
|
319
|
+
})
|
|
320
|
+
.strict(),
|
|
321
|
+
})
|
|
322
|
+
.strict(),
|
|
323
|
+
z
|
|
324
|
+
.object({
|
|
325
|
+
slot: z
|
|
326
|
+
.object({
|
|
327
|
+
id: z.string().min(1).optional(),
|
|
328
|
+
input: workflowFnRefSchema.optional(),
|
|
329
|
+
run: workflowNodeSchema,
|
|
330
|
+
})
|
|
331
|
+
.strict(),
|
|
332
|
+
})
|
|
333
|
+
.strict(),
|
|
334
|
+
]));
|
|
335
|
+
/** Workflow definition document. `kind: "workflow"`; a missing `kind` is never a workflow. */
|
|
336
|
+
export const WorkflowManifestSchema = z
|
|
337
|
+
.object({
|
|
338
|
+
kind: z.literal("workflow"),
|
|
339
|
+
workflowSchemaVersion: z.literal(1),
|
|
340
|
+
id: z.string().min(1),
|
|
341
|
+
root: workflowNodeSchema,
|
|
342
|
+
sandbox: sandboxManifestSchema.optional(),
|
|
343
|
+
})
|
|
344
|
+
.strict();
|
|
345
|
+
/** Registry document: agent (no `kind`, or legacy) or workflow (`kind: "workflow"`). */
|
|
346
|
+
export const DefinitionDocumentSchema = z.union([
|
|
347
|
+
AgentManifestSchema,
|
|
348
|
+
WorkflowManifestSchema,
|
|
349
|
+
]);
|
|
230
350
|
export const PutAgentRequestSchema = z
|
|
231
351
|
.object({
|
|
232
352
|
requestId: RequestIdSchema,
|
|
233
|
-
|
|
353
|
+
/** Agent or workflow document. Registry `kind` is carried on the document. */
|
|
354
|
+
manifest: DefinitionDocumentSchema,
|
|
234
355
|
implementationVersion: z.string().min(1),
|
|
235
356
|
pluginRoots: z.record(z.string(), absolutePath).optional(),
|
|
236
357
|
})
|
|
@@ -249,6 +370,8 @@ export const PutSessionRequestSchema = z
|
|
|
249
370
|
info: jsonObject.optional(),
|
|
250
371
|
vaultIds: z.array(z.string().min(1)).optional(),
|
|
251
372
|
credentialSelections: z.array(CredentialSelectionSchema).optional(),
|
|
373
|
+
/** Share another session's sandbox (same owner, Tenant, and identical specs). */
|
|
374
|
+
sandbox: z.object({ session: z.string().min(1) }).strict().optional(),
|
|
252
375
|
})
|
|
253
376
|
.strict();
|
|
254
377
|
const vaultWriteBase = {
|
|
@@ -367,13 +490,27 @@ const commandBase = {
|
|
|
367
490
|
requestId: RequestIdSchema,
|
|
368
491
|
idempotencyKey: IdempotencyKeySchema,
|
|
369
492
|
};
|
|
370
|
-
|
|
371
|
-
.object({
|
|
493
|
+
const messageBase = {
|
|
372
494
|
...commandBase,
|
|
373
495
|
type: z.literal("message"),
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
496
|
+
/** Optional turn manifest (Loop patch); validated as a variant of the pinned agent. */
|
|
497
|
+
manifest: AgentManifestSchema.optional(),
|
|
498
|
+
};
|
|
499
|
+
/** Exactly one of `content` or `data`. Optional `manifest` for per-turn agent patches. */
|
|
500
|
+
export const MessageEventBodySchema = z.union([
|
|
501
|
+
z
|
|
502
|
+
.object({
|
|
503
|
+
...messageBase,
|
|
504
|
+
content: z.string().min(1),
|
|
505
|
+
})
|
|
506
|
+
.strict(),
|
|
507
|
+
z
|
|
508
|
+
.object({
|
|
509
|
+
...messageBase,
|
|
510
|
+
data: jsonValue,
|
|
511
|
+
})
|
|
512
|
+
.strict(),
|
|
513
|
+
]);
|
|
377
514
|
export const ActionOutcomeSchema = z
|
|
378
515
|
.object({
|
|
379
516
|
value: z.unknown(),
|
|
@@ -390,7 +527,7 @@ export const ActionResultCommandSchema = z
|
|
|
390
527
|
outcome: ActionOutcomeSchema,
|
|
391
528
|
})
|
|
392
529
|
.strict();
|
|
393
|
-
export const SessionCommandSchema = z.
|
|
530
|
+
export const SessionCommandSchema = z.union([
|
|
394
531
|
MessageEventBodySchema,
|
|
395
532
|
z
|
|
396
533
|
.object({
|
|
@@ -422,6 +559,7 @@ export const LiveEventSchema = z
|
|
|
422
559
|
.object({
|
|
423
560
|
eventId: z.string(),
|
|
424
561
|
sessionId: z.string(),
|
|
562
|
+
tenantId: z.string().min(1),
|
|
425
563
|
turnId: z.string().nullable(),
|
|
426
564
|
cursor: z.string(),
|
|
427
565
|
createdAt: z.string(),
|
|
@@ -441,8 +579,9 @@ export const AcceptedResponseSchema = z.object({
|
|
|
441
579
|
});
|
|
442
580
|
export const RejectedResponseSchema = z.object({
|
|
443
581
|
status: z.literal("rejected"),
|
|
444
|
-
code: z.
|
|
582
|
+
code: z.enum(ERROR_CODES),
|
|
445
583
|
message: z.string(),
|
|
584
|
+
details: z.unknown().optional(),
|
|
446
585
|
activeTurnId: z.string().optional(),
|
|
447
586
|
requestId: z.string().optional(),
|
|
448
587
|
});
|
|
@@ -477,20 +616,56 @@ export const ActionHookSchema = z
|
|
|
477
616
|
capabilityIds: z.array(z.string().min(1)).min(1),
|
|
478
617
|
})
|
|
479
618
|
.strict();
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
619
|
+
const agentToolActionSchema = z
|
|
620
|
+
.object({
|
|
621
|
+
...actionBase,
|
|
622
|
+
kind: z.literal("tool"),
|
|
623
|
+
capabilityId: z.string(),
|
|
624
|
+
toolName: z.string(),
|
|
625
|
+
inputSchema: jsonObject.optional(),
|
|
626
|
+
outputSchema: jsonObject.optional(),
|
|
627
|
+
})
|
|
628
|
+
.strict();
|
|
629
|
+
/** Tool node on a workflow: routed by path + key instead of capabilityId. */
|
|
630
|
+
const workflowToolActionSchema = z
|
|
631
|
+
.object({
|
|
632
|
+
...actionBase,
|
|
633
|
+
kind: z.literal("tool"),
|
|
634
|
+
path: z.string().min(1),
|
|
635
|
+
key: z.string().min(1),
|
|
636
|
+
inputSchema: jsonObject.optional(),
|
|
637
|
+
outputSchema: jsonObject.optional(),
|
|
638
|
+
})
|
|
639
|
+
.strict();
|
|
640
|
+
const hookActionSchema = z
|
|
641
|
+
.object({
|
|
642
|
+
...actionBase,
|
|
643
|
+
kind: z.literal("hook"),
|
|
644
|
+
hook: ActionHookSchema,
|
|
645
|
+
})
|
|
646
|
+
.strict();
|
|
647
|
+
const fnActionSchema = z
|
|
648
|
+
.object({
|
|
649
|
+
...actionBase,
|
|
650
|
+
kind: z.literal("fn"),
|
|
651
|
+
path: z.string().min(1),
|
|
652
|
+
key: z.string().min(1),
|
|
653
|
+
})
|
|
654
|
+
.strict();
|
|
655
|
+
const verifyActionSchema = z
|
|
656
|
+
.object({
|
|
657
|
+
...actionBase,
|
|
658
|
+
kind: z.literal("verify"),
|
|
659
|
+
path: z.string().min(1),
|
|
660
|
+
key: z.string().min(1),
|
|
661
|
+
})
|
|
662
|
+
.strict();
|
|
663
|
+
export const ActionSchema = z.union([
|
|
664
|
+
agentToolActionSchema,
|
|
665
|
+
workflowToolActionSchema,
|
|
666
|
+
hookActionSchema,
|
|
667
|
+
fnActionSchema,
|
|
668
|
+
verifyActionSchema,
|
|
494
669
|
]);
|
|
495
670
|
export const ActionClaimRequestSchema = z
|
|
496
671
|
.object({
|
|
@@ -532,6 +707,7 @@ export const RegisterExecutorsResponseSchema = z.object({
|
|
|
532
707
|
agentId: z.string(),
|
|
533
708
|
implementationVersion: z.string(),
|
|
534
709
|
rotated: z.boolean(),
|
|
710
|
+
replacedBy: z.literal("different-credential").optional(),
|
|
535
711
|
})),
|
|
536
712
|
});
|
|
537
713
|
export const ExecutorSummarySchema = z.object({
|
|
@@ -544,16 +720,274 @@ export const ExecutorSummarySchema = z.object({
|
|
|
544
720
|
export const ListExecutorsResponseSchema = z.object({
|
|
545
721
|
executors: z.array(ExecutorSummarySchema),
|
|
546
722
|
});
|
|
547
|
-
|
|
548
|
-
|
|
723
|
+
export const ProtocolRangeSchema = z
|
|
724
|
+
.object({
|
|
725
|
+
min: z.number().int(),
|
|
726
|
+
max: z.number().int(),
|
|
727
|
+
features: z.array(z.string()),
|
|
728
|
+
})
|
|
729
|
+
.strict();
|
|
730
|
+
export const HealthResponseSchema = z
|
|
731
|
+
.object({
|
|
549
732
|
status: z.literal("ok"),
|
|
550
733
|
service: z.string(),
|
|
551
|
-
version: z.string()
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
734
|
+
version: z.string(),
|
|
735
|
+
protocol: ProtocolRangeSchema,
|
|
736
|
+
coreVersion: z.string(),
|
|
737
|
+
hostId: z.string(),
|
|
738
|
+
pid: z.number().int(),
|
|
739
|
+
})
|
|
740
|
+
.strict();
|
|
555
741
|
export const ReadyResponseSchema = z.object({
|
|
556
742
|
status: z.enum(["ready", "not_ready"]),
|
|
557
743
|
service: z.string(),
|
|
558
744
|
checks: z.record(z.string(), z.boolean()),
|
|
559
745
|
});
|
|
746
|
+
export const ProtocolRejectedResponseSchema = z
|
|
747
|
+
.object({
|
|
748
|
+
status: z.literal("rejected"),
|
|
749
|
+
code: z.literal("protocol_unsupported"),
|
|
750
|
+
protocol: ProtocolRangeSchema,
|
|
751
|
+
})
|
|
752
|
+
.strict();
|
|
753
|
+
export const TenantEnvelopeSchema = z
|
|
754
|
+
.object({
|
|
755
|
+
id: z.string().min(1),
|
|
756
|
+
name: z.string().min(1),
|
|
757
|
+
createdAt: z.string().min(1),
|
|
758
|
+
updatedAt: z.string().min(1),
|
|
759
|
+
schemaVersion: z.number().int(),
|
|
760
|
+
})
|
|
761
|
+
.strict();
|
|
762
|
+
export const CreateTenantRequestSchema = z
|
|
763
|
+
.object({
|
|
764
|
+
tenantId: z.string().min(1),
|
|
765
|
+
name: z.string().min(1),
|
|
766
|
+
/** `studio` is reserved for the derived Studio principal. */
|
|
767
|
+
principalId: z
|
|
768
|
+
.string()
|
|
769
|
+
.min(1)
|
|
770
|
+
.refine((id) => id !== "studio", "principalId `studio` is reserved"),
|
|
771
|
+
credentialHash: z.string().regex(/^[0-9a-f]{64}$/),
|
|
772
|
+
idempotencyKey: IdempotencyKeySchema,
|
|
773
|
+
/** SHA-256 of the derived Studio key; registers principal `studio` (feature `studio-principal`). */
|
|
774
|
+
studioCredentialHash: z
|
|
775
|
+
.string()
|
|
776
|
+
.regex(/^[0-9a-f]{64}$/)
|
|
777
|
+
.optional(),
|
|
778
|
+
})
|
|
779
|
+
.strict();
|
|
780
|
+
export const AdminTenantSchema = z
|
|
781
|
+
.object({
|
|
782
|
+
id: z.string().min(1),
|
|
783
|
+
name: z.string().nullable(),
|
|
784
|
+
state: z.enum(["open", "quarantined"]),
|
|
785
|
+
envelope: TenantEnvelopeSchema.nullable(),
|
|
786
|
+
})
|
|
787
|
+
.strict();
|
|
788
|
+
export const QuarantineSchema = z
|
|
789
|
+
.object({
|
|
790
|
+
code: z.enum([
|
|
791
|
+
"kek-missing",
|
|
792
|
+
"corrupt",
|
|
793
|
+
"schema-too-new",
|
|
794
|
+
"migration-failed",
|
|
795
|
+
"envelope-invalid",
|
|
796
|
+
"open-timeout",
|
|
797
|
+
"open-failed",
|
|
798
|
+
]),
|
|
799
|
+
message: z.string(),
|
|
800
|
+
repair: z.string(),
|
|
801
|
+
})
|
|
802
|
+
.strict();
|
|
803
|
+
export const AdminTenantStatusSchema = AdminTenantSchema.extend({
|
|
804
|
+
quarantine: QuarantineSchema.optional(),
|
|
805
|
+
});
|
|
806
|
+
export const HostAggregateSchema = z
|
|
807
|
+
.object({
|
|
808
|
+
runningSessions: z.number().int().nonnegative(),
|
|
809
|
+
connectedExecutors: z.number().int().nonnegative(),
|
|
810
|
+
pendingActions: z.number().int().nonnegative(),
|
|
811
|
+
uncertainEffects: z.number().int().nonnegative(),
|
|
812
|
+
/** Events committed but not yet relayed to Durable Streams, over the open Tenants. */
|
|
813
|
+
outboxDepth: z.number().int().nonnegative().optional(),
|
|
814
|
+
/** The largest relay lag of an open Tenant: its oldest unrelayed event's age. */
|
|
815
|
+
relayLagMs: z.number().nonnegative().optional(),
|
|
816
|
+
})
|
|
817
|
+
.strict();
|
|
818
|
+
export const AdminHostStatusSchema = z
|
|
819
|
+
.object({
|
|
820
|
+
hostId: z.string().min(1),
|
|
821
|
+
url: z.string().min(1),
|
|
822
|
+
pid: z.number().int(),
|
|
823
|
+
version: z.string().min(1),
|
|
824
|
+
protocol: ProtocolRangeSchema,
|
|
825
|
+
tenants: z.array(AdminTenantSchema),
|
|
826
|
+
aggregate: HostAggregateSchema,
|
|
827
|
+
})
|
|
828
|
+
.strict();
|
|
829
|
+
/** Shared Admin API status (D§4.1). OSS fills `host`; Cloud omits it. */
|
|
830
|
+
export const AdminStatusSchema = z
|
|
831
|
+
.object({
|
|
832
|
+
service: z.string().min(1),
|
|
833
|
+
version: z.string().min(1),
|
|
834
|
+
protocol: ProtocolRangeSchema,
|
|
835
|
+
tenants: z.array(AdminTenantSchema),
|
|
836
|
+
aggregate: HostAggregateSchema,
|
|
837
|
+
host: z
|
|
838
|
+
.object({
|
|
839
|
+
hostId: z.string().min(1),
|
|
840
|
+
url: z.string().min(1),
|
|
841
|
+
pid: z.number().int(),
|
|
842
|
+
})
|
|
843
|
+
.strict()
|
|
844
|
+
.optional(),
|
|
845
|
+
})
|
|
846
|
+
.strict();
|
|
847
|
+
export const ProjectLinkFileSchema = z
|
|
848
|
+
.object({
|
|
849
|
+
format: z.union([z.literal(0), z.literal(1)]).default(0),
|
|
850
|
+
hostUrl: z.string().min(1),
|
|
851
|
+
hostId: z.string().min(1),
|
|
852
|
+
tenantId: z.string().min(1),
|
|
853
|
+
})
|
|
854
|
+
.passthrough();
|
|
855
|
+
export const ProjectCredentialsFileSchema = z
|
|
856
|
+
.object({
|
|
857
|
+
format: z.union([z.literal(0), z.literal(1)]).default(0),
|
|
858
|
+
applicationKey: z.string().regex(/^[0-9a-f]{64}$/),
|
|
859
|
+
principalId: z.string().min(1),
|
|
860
|
+
})
|
|
861
|
+
.passthrough();
|
|
862
|
+
export const HostModelViewSchema = z.union([
|
|
863
|
+
z.object({ configured: z.literal(false) }).strict(),
|
|
864
|
+
z
|
|
865
|
+
.object({
|
|
866
|
+
configured: z.literal(true),
|
|
867
|
+
provider: z.string(),
|
|
868
|
+
model: z.string(),
|
|
869
|
+
authType: z.enum(["api_key", "oauth"]),
|
|
870
|
+
baseUrl: z.string().optional(),
|
|
871
|
+
})
|
|
872
|
+
.strict(),
|
|
873
|
+
]);
|
|
874
|
+
export const TenantStatusSchema = z
|
|
875
|
+
.object({
|
|
876
|
+
tenant: TenantEnvelopeSchema,
|
|
877
|
+
path: z.string().min(1),
|
|
878
|
+
checks: z
|
|
879
|
+
.object({
|
|
880
|
+
store: z.boolean(),
|
|
881
|
+
scheduler: z.boolean(),
|
|
882
|
+
model: z.boolean(),
|
|
883
|
+
executors: z.boolean(),
|
|
884
|
+
schema: z.boolean(),
|
|
885
|
+
})
|
|
886
|
+
.strict(),
|
|
887
|
+
model: HostModelViewSchema,
|
|
888
|
+
agents: z.array(z
|
|
889
|
+
.object({
|
|
890
|
+
agentId: z.string(),
|
|
891
|
+
registered: z.boolean(),
|
|
892
|
+
connected: z.boolean(),
|
|
893
|
+
})
|
|
894
|
+
.strict()),
|
|
895
|
+
counts: z
|
|
896
|
+
.object({
|
|
897
|
+
sessions: z.number().int().nonnegative(),
|
|
898
|
+
runningSessions: z.number().int().nonnegative(),
|
|
899
|
+
pendingActions: z.number().int().nonnegative(),
|
|
900
|
+
uncertainEffects: z.number().int().nonnegative(),
|
|
901
|
+
})
|
|
902
|
+
.strict(),
|
|
903
|
+
sandbox: z
|
|
904
|
+
.object({
|
|
905
|
+
backend: z.string().nullable(),
|
|
906
|
+
retained: z.number().int().nonnegative(),
|
|
907
|
+
})
|
|
908
|
+
.strict(),
|
|
909
|
+
/**
|
|
910
|
+
* Durable Session Execution invocations of this Tenant that need an operator: paused
|
|
911
|
+
* after exhausting retries, or backing off after failures. Absent when the execution
|
|
912
|
+
* cannot report them; `error` when it could not be asked.
|
|
913
|
+
*/
|
|
914
|
+
execution: z
|
|
915
|
+
.object({
|
|
916
|
+
stuckInvocations: z.array(z
|
|
917
|
+
.object({
|
|
918
|
+
id: z.string(),
|
|
919
|
+
status: z.string(),
|
|
920
|
+
service: z.string(),
|
|
921
|
+
handler: z.string(),
|
|
922
|
+
key: z.string(),
|
|
923
|
+
retryCount: z.number().int().nonnegative(),
|
|
924
|
+
lastFailure: z.string().optional(),
|
|
925
|
+
modifiedAt: z.string().optional(),
|
|
926
|
+
})
|
|
927
|
+
.strict()),
|
|
928
|
+
error: z.string().optional(),
|
|
929
|
+
})
|
|
930
|
+
.strict()
|
|
931
|
+
.optional(),
|
|
932
|
+
/**
|
|
933
|
+
* This Tenant's Durable Streams: whether the service answers, its basin, the events
|
|
934
|
+
* committed but not yet relayed, and how far the relay is behind.
|
|
935
|
+
*/
|
|
936
|
+
streams: z
|
|
937
|
+
.object({
|
|
938
|
+
reachable: z.boolean(),
|
|
939
|
+
basin: z
|
|
940
|
+
.object({
|
|
941
|
+
ready: z.boolean(),
|
|
942
|
+
failures: z.number().int().nonnegative(),
|
|
943
|
+
lastError: z.string().nullable(),
|
|
944
|
+
})
|
|
945
|
+
.strict(),
|
|
946
|
+
outbox: z
|
|
947
|
+
.object({
|
|
948
|
+
depth: z.number().int().nonnegative(),
|
|
949
|
+
oldestAgeMs: z.number().nonnegative().nullable(),
|
|
950
|
+
})
|
|
951
|
+
.strict(),
|
|
952
|
+
relayLagMs: z.number().nonnegative(),
|
|
953
|
+
collectionPending: z.boolean(),
|
|
954
|
+
})
|
|
955
|
+
.strict()
|
|
956
|
+
.optional(),
|
|
957
|
+
})
|
|
958
|
+
.strict();
|
|
959
|
+
const seedModelSchema = PutHostModelRequestSchema.omit({
|
|
960
|
+
requestId: true,
|
|
961
|
+
idempotencyKey: true,
|
|
962
|
+
});
|
|
963
|
+
export const SeedTenantConfigRequestSchema = z
|
|
964
|
+
.object({
|
|
965
|
+
requestId: RequestIdSchema,
|
|
966
|
+
sandbox: z
|
|
967
|
+
.object({
|
|
968
|
+
backend: z.enum(["auto", "virtual"]),
|
|
969
|
+
})
|
|
970
|
+
.strict()
|
|
971
|
+
.optional(),
|
|
972
|
+
model: seedModelSchema.optional(),
|
|
973
|
+
/**
|
|
974
|
+
* The Tenant's model calls use the Runtime's deterministic fixture model instead of its
|
|
975
|
+
* host model, e.g. for a temporary test Tenant (scripts/lib/temporary-tenant.mjs). Stored
|
|
976
|
+
* as Tenant setting `model.fixture`. Host feature `tenant-fixture-model`.
|
|
977
|
+
*/
|
|
978
|
+
fixtureModel: z.literal(true).optional(),
|
|
979
|
+
})
|
|
980
|
+
.strict();
|
|
981
|
+
export const SeedTenantConfigResponseSchema = z
|
|
982
|
+
.object({
|
|
983
|
+
applied: z.array(z.string()),
|
|
984
|
+
kept: z.array(z.string()),
|
|
985
|
+
})
|
|
986
|
+
.strict();
|
|
987
|
+
export const ResetTenantRequestSchema = z
|
|
988
|
+
.object({
|
|
989
|
+
requestId: RequestIdSchema,
|
|
990
|
+
scope: z.enum(["sessions", "sandboxes", "all"]),
|
|
991
|
+
activeWork: z.enum(["drain", "cancel"]),
|
|
992
|
+
})
|
|
993
|
+
.strict();
|
package/dist/define.d.ts
CHANGED
|
@@ -25,6 +25,10 @@ export type { Interaction, RequiredInteraction, ToolContent, ToolDefinition, Too
|
|
|
25
25
|
export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
|
|
26
26
|
export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
|
|
27
27
|
export type { AgentBinding } from "./definition/binding.js";
|
|
28
|
+
export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
|
|
29
|
+
export type { BuiltWorkflow, OutputOf, InputOf, LoopOptions, LoopRunnable, LoopVerify, LoopVerifyFn, LoopDecideFn, LoopVerifyArgs, LoopDecideArgs, LoopDecision, ChainOptions, ChainStep, ChainResults, ChainSlot, SwitchOptions, SwitchCases, ParallelOptions, ParallelBranches, MapOptions, MapOver, Slot, SlotInputArgs, WorkflowRunnable, } from "./definition/workflow/index.js";
|
|
30
|
+
export { isVariantOf } from "./definition/variant.js";
|
|
31
|
+
export type { Verdict, WorkflowBinding, WorkflowManifest } from "./types/workflow.js";
|
|
28
32
|
export type { BoundMiddleware, BoundToolDefinition, } from "./definition/bound.js";
|
|
29
33
|
export { bindTool } from "./definition/bind-tool.js";
|
|
30
34
|
export { bindOutputContract } from "./definition/output-contract.js";
|
package/dist/define.js
CHANGED
|
@@ -10,6 +10,8 @@ export { SANDBOX_DEFERRED_FIELDS, SANDBOX_FIELDS, SANDBOX_NETWORK_PRESETS, SANDB
|
|
|
10
10
|
export { HOOK_POINTS, hasHook, hookListIssue, hooksFrom, runHookPoint, } from "./definition/hooks.js";
|
|
11
11
|
export { normalizeToolDefinition, normalizedSchemasFor, } from "./definition/schema.js";
|
|
12
12
|
export { implementationsFor, bindingFromAgent } from "./definition/binding.js";
|
|
13
|
+
export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
|
|
14
|
+
export { isVariantOf } from "./definition/variant.js";
|
|
13
15
|
export { bindTool } from "./definition/bind-tool.js";
|
|
14
16
|
export { bindOutputContract } from "./definition/output-contract.js";
|
|
15
17
|
export { agentFrom } from "./definition/from.js";
|
|
@@ -12,7 +12,7 @@ export const SANDBOX_INSTRUCTIONS = `You have an isolated Linux sandbox with a p
|
|
|
12
12
|
* reaching this means the agent ran without a Nylorun Runtime.
|
|
13
13
|
*/
|
|
14
14
|
async function runtimeOnly() {
|
|
15
|
-
throw new ToolError("sandbox.runtime-only", "Sandbox tools run in the Nylorun Runtime.
|
|
15
|
+
throw new ToolError("sandbox.runtime-only", "Sandbox tools run in the Nylorun Runtime. Connect the agent to a Runtime (npx nylorun up, then npm run dev) to use them.");
|
|
16
16
|
}
|
|
17
17
|
/** The six built-in sandbox tools. Schemas are part of the hashed manifest; change them deliberately. */
|
|
18
18
|
export function createSandboxTools() {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AgentManifest } from "../types/manifest.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether `candidate` is a valid turn-manifest variant of the session's pinned
|
|
4
|
+
* manifest (`loops.md` §3.4). Hooks and setup (MCP, sandbox) are fixed;
|
|
5
|
+
* code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
|
|
6
|
+
*/
|
|
7
|
+
export declare function isVariantOf(candidate: AgentManifest, pinned: AgentManifest): boolean;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { canonical } from "../utils/canonical.js";
|
|
2
|
+
function same(a, b) {
|
|
3
|
+
return canonical(a) === canonical(b);
|
|
4
|
+
}
|
|
5
|
+
function toolsByName(tools) {
|
|
6
|
+
const map = new Map();
|
|
7
|
+
for (const tool of tools ?? [])
|
|
8
|
+
map.set(tool.name, tool);
|
|
9
|
+
return map;
|
|
10
|
+
}
|
|
11
|
+
/** Candidate tools/skills/agents-as-tools may only be removed, never added or changed. */
|
|
12
|
+
function removeOnlyTools(pinned, candidate) {
|
|
13
|
+
const base = toolsByName(pinned);
|
|
14
|
+
for (const tool of candidate ?? []) {
|
|
15
|
+
const prior = base.get(tool.name);
|
|
16
|
+
if (!prior || !same(prior, tool))
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
function removeOnlySkills(pinned, candidate) {
|
|
22
|
+
const base = pinned ?? {};
|
|
23
|
+
for (const [name, skill] of Object.entries(candidate ?? {})) {
|
|
24
|
+
const prior = base[name];
|
|
25
|
+
if (!prior || !same(prior, skill))
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether `candidate` is a valid turn-manifest variant of the session's pinned
|
|
32
|
+
* manifest (`loops.md` §3.4). Hooks and setup (MCP, sandbox) are fixed;
|
|
33
|
+
* code-backed tools/skills/agents-as-tools are remove-only; plain data may change.
|
|
34
|
+
*/
|
|
35
|
+
export function isVariantOf(candidate, pinned) {
|
|
36
|
+
if (candidate.id !== pinned.id)
|
|
37
|
+
return false;
|
|
38
|
+
if (candidate.manifestSchemaVersion !== pinned.manifestSchemaVersion)
|
|
39
|
+
return false;
|
|
40
|
+
if (!same(candidate.runtime ?? {}, pinned.runtime ?? {}))
|
|
41
|
+
return false;
|
|
42
|
+
const pinnedById = new Map(pinned.capabilities.map((capability) => [capability.id, capability]));
|
|
43
|
+
const candidateById = new Map(candidate.capabilities.map((capability) => [capability.id, capability]));
|
|
44
|
+
for (const [, prior] of pinnedById) {
|
|
45
|
+
const next = candidateById.get(prior.id);
|
|
46
|
+
if (prior.hooks?.length) {
|
|
47
|
+
// Hooks — and any capability that registers them — must not change or be removed.
|
|
48
|
+
if (!next || !same(next.hooks, prior.hooks))
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (prior.mcpServers !== undefined) {
|
|
52
|
+
if (!next || !same(next.mcpServers, prior.mcpServers))
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (prior.sandbox !== undefined) {
|
|
56
|
+
if (!next || !same(next.sandbox, prior.sandbox))
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
for (const [id, next] of candidateById) {
|
|
61
|
+
const prior = pinnedById.get(id);
|
|
62
|
+
if (!prior)
|
|
63
|
+
return false; // cannot add capabilities
|
|
64
|
+
if (next.type !== prior.type)
|
|
65
|
+
return false;
|
|
66
|
+
if (!removeOnlyTools(prior.tools, next.tools))
|
|
67
|
+
return false;
|
|
68
|
+
if (!removeOnlySkills(prior.skills, next.skills))
|
|
69
|
+
return false;
|
|
70
|
+
// Free: name, description, metadata, instructions (and model once it exists).
|
|
71
|
+
if (prior.hooks?.length) {
|
|
72
|
+
if (!same(next.hooks, prior.hooks))
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
else if (next.hooks?.length) {
|
|
76
|
+
return false; // cannot add hooks
|
|
77
|
+
}
|
|
78
|
+
if (!same(next.mcpServers, prior.mcpServers))
|
|
79
|
+
return false;
|
|
80
|
+
if (!same(next.sandbox, prior.sandbox))
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// Dropping a capability is allowed only when it had no hooks / MCP / sandbox
|
|
84
|
+
// (those are enforced above). Tools and skills on a dropped capability are
|
|
85
|
+
// removals, which §3.4 permits.
|
|
86
|
+
return true;
|
|
87
|
+
}
|