@nylorun/core 0.44.0-beta → 0.45.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 +12 -0
- package/dist/compatibility.d.ts +7 -0
- package/dist/compatibility.js +7 -0
- package/dist/contracts.d.ts +87 -23
- package/dist/contracts.js +61 -37
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @nylorun/core
|
|
2
2
|
|
|
3
|
+
## 0.45.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 17951fe: A client can give one Agent a trigger over the API (D88, ADR-145; Host feature `api-triggers`). `PUT /v1/agents/{agentId}/triggers/{triggerId}` creates or replaces the Agent's trigger of a fourth origin, `api`: the body is a `Trigger` exactly as a definition's `runtime.triggers` entry holds it (one of `schedule` with `timezone`, `at` or `webhook`; `session`; `prompt`) and an optional `title`. A new one is active with its next time; a replaced one gets its next time again and keeps its status; the same body again changes nothing and records no event. An id the definition declares, or one an agent's trigger or a booked wake holds, is `409 trigger_conflict`. The checks and limits are a definition's, and `runtime.limits.triggers.count` now counts the triggers an Agent's agents made and those clients put together (`422 trigger_limit`). Upgrades and moves never touch an `api` trigger, `DELETE` removes it, and pause, resume, run and a webhook's secret work as for any trigger.
|
|
8
|
+
|
|
9
|
+
- `@nylorun/core`: `TRIGGER_ORIGINS` adds `api`; `TriggerPutSchema`; `TriggerView.principal`; `agent.trigger_created` and `agent.trigger_updated` carry `origin`, `principal`, the timing and `changed` (their `sessionId` is now optional, set for `agent` only; `kind` adds `webhook`), and `agent.trigger_deleted` carries `origin`; Host feature `api-triggers`.
|
|
10
|
+
- `@nylorun/runtime`: the route; `agent_triggers.principal` and the `api` origin (store migration 0049, run at start).
|
|
11
|
+
- `@nylorun/agents`: `agents.putTrigger(agentId, triggerId, trigger)`; `deleteTrigger` deletes `api` triggers too.
|
|
12
|
+
- `nylorun`: `nylorun agents triggers put <id> <trigger>` with `--schedule`, `--timezone`, `--at`, `--webhook`, `--session`, `--prompt` and `--title`, or a JSON file; `rm` deletes `api` triggers.
|
|
13
|
+
- `@nylorun/studio`: the Triggers tab shows where each trigger came from (the definition's version, the agent that made it, or the principal that put it), its prompt and time zone for every origin, and deletes one an agent made or a client put; Activity words trigger changes and filters them.
|
|
14
|
+
|
|
3
15
|
## 0.44.0-beta
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/dist/compatibility.d.ts
CHANGED
|
@@ -259,6 +259,13 @@ export declare const OPTIONAL_HOST_FEATURES: readonly ["tenant-fixture-model", "
|
|
|
259
259
|
* `runtime.limits.triggers`; and `GET /v1/runs/stream`, the Tenant's runs as server-sent events.
|
|
260
260
|
*/
|
|
261
261
|
"agent-triggers",
|
|
262
|
+
/**
|
|
263
|
+
* Triggers a client puts on one Agent (D88): `PUT /v1/agents/{id}/triggers/{triggerId}` with a
|
|
264
|
+
* `Trigger` and an optional `title` creates or replaces the Agent's `api` trigger; `DELETE`
|
|
265
|
+
* removes it; the list shows `origin: api` and its `principal`; the trigger events carry `origin`,
|
|
266
|
+
* `principal` and `changed`.
|
|
267
|
+
*/
|
|
268
|
+
"api-triggers",
|
|
262
269
|
/**
|
|
263
270
|
* A message's `delivery: "steer"` (D85): to a busy agent session it waits in the session queue
|
|
264
271
|
* marked `steer`, and our engine takes it into the running turn before its next step (the
|
package/dist/compatibility.js
CHANGED
|
@@ -281,6 +281,13 @@ export const OPTIONAL_HOST_FEATURES = [
|
|
|
281
281
|
* `runtime.limits.triggers`; and `GET /v1/runs/stream`, the Tenant's runs as server-sent events.
|
|
282
282
|
*/
|
|
283
283
|
"agent-triggers",
|
|
284
|
+
/**
|
|
285
|
+
* Triggers a client puts on one Agent (D88): `PUT /v1/agents/{id}/triggers/{triggerId}` with a
|
|
286
|
+
* `Trigger` and an optional `title` creates or replaces the Agent's `api` trigger; `DELETE`
|
|
287
|
+
* removes it; the list shows `origin: api` and its `principal`; the trigger events carry `origin`,
|
|
288
|
+
* `principal` and `changed`.
|
|
289
|
+
*/
|
|
290
|
+
"api-triggers",
|
|
284
291
|
/**
|
|
285
292
|
* A message's `delivery: "steer"` (D85): to a busy agent session it waits in the session queue
|
|
286
293
|
* marked `steer`, and our engine takes it into the running turn before its next step (the
|
package/dist/contracts.d.ts
CHANGED
|
@@ -728,6 +728,28 @@ export declare const MemoryUpdatedPayloadSchema: z.ZodObject<{
|
|
|
728
728
|
}, z.core.$loose>;
|
|
729
729
|
export declare const AGENT_EVENT_TYPES: readonly ["agent.created", "agent.attached", "agent.detached", "agent.deleted", "agent.running", "agent.suspended", "agent.relaunched", "agent.lost", "agent.reset", "agent.failed", "agent.forked", "agent.outdated", "agent.version_changed", "agent.start_failed", "agent.egress", "agent.run", "agent.trigger_paused", "agent.trigger_resumed", "agent.trigger_secret_rotated", "agent.trigger_created", "agent.trigger_updated", "agent.trigger_deleted", "agent.memory_updated"];
|
|
730
730
|
export type AgentEventType = (typeof AGENT_EVENT_TYPES)[number];
|
|
731
|
+
/** `agent.trigger_created` and `agent.trigger_updated`'s payload (D83, D88). */
|
|
732
|
+
export declare const TriggerChangePayloadSchema: z.ZodObject<{
|
|
733
|
+
triggerId: z.ZodString;
|
|
734
|
+
kind: z.ZodEnum<{
|
|
735
|
+
at: "at";
|
|
736
|
+
schedule: "schedule";
|
|
737
|
+
webhook: "webhook";
|
|
738
|
+
}>;
|
|
739
|
+
origin: z.ZodOptional<z.ZodEnum<{
|
|
740
|
+
agent: "agent";
|
|
741
|
+
api: "api";
|
|
742
|
+
}>>;
|
|
743
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
744
|
+
principal: z.ZodOptional<z.ZodString>;
|
|
745
|
+
session: z.ZodString;
|
|
746
|
+
title: z.ZodOptional<z.ZodString>;
|
|
747
|
+
schedule: z.ZodOptional<z.ZodString>;
|
|
748
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
749
|
+
at: z.ZodOptional<z.ZodString>;
|
|
750
|
+
changed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
751
|
+
nextRunAt: z.ZodNullable<z.ZodString>;
|
|
752
|
+
}, z.core.$loose>;
|
|
731
753
|
/** The payload of each Agent lifecycle event. */
|
|
732
754
|
export declare const AGENT_EVENT_PAYLOADS: {
|
|
733
755
|
readonly "agent.created": z.ZodObject<{
|
|
@@ -885,19 +907,31 @@ export declare const AGENT_EVENT_PAYLOADS: {
|
|
|
885
907
|
triggerId: z.ZodString;
|
|
886
908
|
}, z.core.$loose>;
|
|
887
909
|
/**
|
|
888
|
-
* An agent made a trigger with the `triggers` tool (D83), or
|
|
889
|
-
* (
|
|
890
|
-
*
|
|
910
|
+
* An agent made a trigger with the `triggers` tool (D83), or a client put one over the API
|
|
911
|
+
* (D88), or either replaced one with the same id (`agent.trigger_updated`): where it came from
|
|
912
|
+
* (`origin`), the session whose agent made it (`sessionId`, for `agent`) or who put it
|
|
913
|
+
* (`principal`, for `api`), the session it runs in (`session`), its timing, its title, its next
|
|
914
|
+
* run, and on an update the fields that changed (`changed`).
|
|
891
915
|
*/
|
|
892
916
|
readonly "agent.trigger_created": z.ZodObject<{
|
|
893
917
|
triggerId: z.ZodString;
|
|
894
918
|
kind: z.ZodEnum<{
|
|
895
919
|
at: "at";
|
|
896
920
|
schedule: "schedule";
|
|
921
|
+
webhook: "webhook";
|
|
897
922
|
}>;
|
|
898
|
-
|
|
923
|
+
origin: z.ZodOptional<z.ZodEnum<{
|
|
924
|
+
agent: "agent";
|
|
925
|
+
api: "api";
|
|
926
|
+
}>>;
|
|
927
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
928
|
+
principal: z.ZodOptional<z.ZodString>;
|
|
899
929
|
session: z.ZodString;
|
|
900
930
|
title: z.ZodOptional<z.ZodString>;
|
|
931
|
+
schedule: z.ZodOptional<z.ZodString>;
|
|
932
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
933
|
+
at: z.ZodOptional<z.ZodString>;
|
|
934
|
+
changed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
901
935
|
nextRunAt: z.ZodNullable<z.ZodString>;
|
|
902
936
|
}, z.core.$loose>;
|
|
903
937
|
readonly "agent.trigger_updated": z.ZodObject<{
|
|
@@ -905,15 +939,32 @@ export declare const AGENT_EVENT_PAYLOADS: {
|
|
|
905
939
|
kind: z.ZodEnum<{
|
|
906
940
|
at: "at";
|
|
907
941
|
schedule: "schedule";
|
|
942
|
+
webhook: "webhook";
|
|
908
943
|
}>;
|
|
909
|
-
|
|
944
|
+
origin: z.ZodOptional<z.ZodEnum<{
|
|
945
|
+
agent: "agent";
|
|
946
|
+
api: "api";
|
|
947
|
+
}>>;
|
|
948
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
949
|
+
principal: z.ZodOptional<z.ZodString>;
|
|
910
950
|
session: z.ZodString;
|
|
911
951
|
title: z.ZodOptional<z.ZodString>;
|
|
952
|
+
schedule: z.ZodOptional<z.ZodString>;
|
|
953
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
954
|
+
at: z.ZodOptional<z.ZodString>;
|
|
955
|
+
changed: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
912
956
|
nextRunAt: z.ZodNullable<z.ZodString>;
|
|
913
957
|
}, z.core.$loose>;
|
|
914
|
-
/**
|
|
958
|
+
/**
|
|
959
|
+
* A trigger an agent made or a client put was deleted: by an agent of `sessionId`, or over the
|
|
960
|
+
* API (`principal`); `origin` says which kind of trigger it was (D88).
|
|
961
|
+
*/
|
|
915
962
|
readonly "agent.trigger_deleted": z.ZodObject<{
|
|
916
963
|
triggerId: z.ZodString;
|
|
964
|
+
origin: z.ZodOptional<z.ZodEnum<{
|
|
965
|
+
agent: "agent";
|
|
966
|
+
api: "api";
|
|
967
|
+
}>>;
|
|
917
968
|
sessionId: z.ZodOptional<z.ZodString>;
|
|
918
969
|
principal: z.ZodOptional<z.ZodString>;
|
|
919
970
|
}, z.core.$loose>;
|
|
@@ -1341,17 +1392,6 @@ export declare const HarnessSectionSchema: z.ZodUnion<readonly [z.ZodType<Workfl
|
|
|
1341
1392
|
export declare const TriggerIdSchema: z.ZodString;
|
|
1342
1393
|
/** The signature schemes a webhook trigger verifies: Standard Webhooks only. */
|
|
1343
1394
|
export declare const WEBHOOK_SCHEMES: readonly ["standard-webhooks"];
|
|
1344
|
-
/**
|
|
1345
|
-
* One trigger of an agent manifest's `runtime.triggers`: exactly one of
|
|
1346
|
-
* `schedule` (five-field cron, minute granularity, in `timezone`, an IANA name, default UTC), `at`
|
|
1347
|
-
* (one run at an RFC 3339 time with an offset) or `webhook` (a webhook endpoint verified with the
|
|
1348
|
-
* named scheme), plus the `session` each run goes to and the author's `prompt`.
|
|
1349
|
-
*
|
|
1350
|
-
* `session` is a session id of the Agent, opened on the trigger's first run if it does not
|
|
1351
|
-
* exist, or `"new"` for a new session per run (`run-<runId>`). The Runtime keeps no main session.
|
|
1352
|
-
* The cron's smallest gap, the `at` time, the prompt's length and how many triggers a
|
|
1353
|
-
* manifest holds are checked against the Tenant's Runtime limits when it is saved.
|
|
1354
|
-
*/
|
|
1355
1395
|
export declare const TriggerSchema: z.ZodObject<{
|
|
1356
1396
|
schedule: z.ZodOptional<z.ZodString>;
|
|
1357
1397
|
timezone: z.ZodOptional<z.ZodString>;
|
|
@@ -1374,11 +1414,12 @@ export declare function triggerKindOf(trigger: Trigger): Exclude<TriggerKind, "w
|
|
|
1374
1414
|
*/
|
|
1375
1415
|
export declare const TRIGGER_STATUSES: readonly ["active", "paused", "completed"];
|
|
1376
1416
|
/**
|
|
1377
|
-
* Where a trigger's definition comes from (D83): `manifest` (the version's `runtime.triggers`),
|
|
1378
|
-
* `agent` (made by an agent of the Agent's sessions with the `triggers` tool, kept by the Agent)
|
|
1379
|
-
*
|
|
1417
|
+
* Where a trigger's definition comes from (D83, D88): `manifest` (the version's `runtime.triggers`),
|
|
1418
|
+
* `agent` (made by an agent of the Agent's sessions with the `triggers` tool, kept by the Agent),
|
|
1419
|
+
* `api` (put on the Agent by a client, `PUT /v1/agents/{id}/triggers/{triggerId}`, kept by the
|
|
1420
|
+
* Agent with the principal that put it) or `wake` (a session's booked wake, never listed).
|
|
1380
1421
|
*/
|
|
1381
|
-
export declare const TRIGGER_ORIGINS: readonly ["manifest", "agent", "wake"];
|
|
1422
|
+
export declare const TRIGGER_ORIGINS: readonly ["manifest", "agent", "api", "wake"];
|
|
1382
1423
|
export type TriggerOrigin = (typeof TRIGGER_ORIGINS)[number];
|
|
1383
1424
|
/**
|
|
1384
1425
|
* `GET /v1/agents/{id}/triggers`: one trigger, from its manifest entry (or, for one an agent made,
|
|
@@ -1394,11 +1435,13 @@ export declare const TriggerViewSchema: z.ZodObject<{
|
|
|
1394
1435
|
}>;
|
|
1395
1436
|
origin: z.ZodEnum<{
|
|
1396
1437
|
agent: "agent";
|
|
1438
|
+
api: "api";
|
|
1397
1439
|
manifest: "manifest";
|
|
1398
1440
|
wake: "wake";
|
|
1399
1441
|
}>;
|
|
1400
1442
|
title: z.ZodNullable<z.ZodString>;
|
|
1401
1443
|
createdSessionId: z.ZodNullable<z.ZodString>;
|
|
1444
|
+
principal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1402
1445
|
status: z.ZodEnum<{
|
|
1403
1446
|
active: "active";
|
|
1404
1447
|
completed: "completed";
|
|
@@ -1427,11 +1470,13 @@ export declare const TriggerListSchema: z.ZodObject<{
|
|
|
1427
1470
|
}>;
|
|
1428
1471
|
origin: z.ZodEnum<{
|
|
1429
1472
|
agent: "agent";
|
|
1473
|
+
api: "api";
|
|
1430
1474
|
manifest: "manifest";
|
|
1431
1475
|
wake: "wake";
|
|
1432
1476
|
}>;
|
|
1433
1477
|
title: z.ZodNullable<z.ZodString>;
|
|
1434
1478
|
createdSessionId: z.ZodNullable<z.ZodString>;
|
|
1479
|
+
principal: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
1435
1480
|
status: z.ZodEnum<{
|
|
1436
1481
|
active: "active";
|
|
1437
1482
|
completed: "completed";
|
|
@@ -1449,10 +1494,27 @@ export declare const TriggerListSchema: z.ZodObject<{
|
|
|
1449
1494
|
prompt: z.ZodOptional<z.ZodString>;
|
|
1450
1495
|
}, z.core.$strict>>;
|
|
1451
1496
|
}, z.core.$strict>;
|
|
1497
|
+
/** The longest title an agent or a client gives a trigger it makes. */
|
|
1498
|
+
export declare const TRIGGER_TITLE_MAX = 80;
|
|
1499
|
+
/**
|
|
1500
|
+
* The body of `PUT /v1/agents/{agentId}/triggers/{triggerId}` (D88): a `Trigger`, exactly as a
|
|
1501
|
+
* definition's `runtime.triggers` entry holds it, and an optional `title`. It creates the Agent's
|
|
1502
|
+
* `api` trigger with that id, or replaces it; the same body again changes nothing.
|
|
1503
|
+
*/
|
|
1504
|
+
export declare const TriggerPutSchema: z.ZodObject<{
|
|
1505
|
+
schedule: z.ZodOptional<z.ZodString>;
|
|
1506
|
+
timezone: z.ZodOptional<z.ZodString>;
|
|
1507
|
+
at: z.ZodOptional<z.ZodISODateTime>;
|
|
1508
|
+
webhook: z.ZodOptional<z.ZodEnum<{
|
|
1509
|
+
"standard-webhooks": "standard-webhooks";
|
|
1510
|
+
}>>;
|
|
1511
|
+
session: z.ZodString;
|
|
1512
|
+
prompt: z.ZodString;
|
|
1513
|
+
title: z.ZodOptional<z.ZodString>;
|
|
1514
|
+
}, z.core.$strict>;
|
|
1515
|
+
export type TriggerPut = z.infer<typeof TriggerPutSchema>;
|
|
1452
1516
|
/** `in` of the `triggers` tool (D83): a delay in minutes, hours or days, such as `30m`, `2h`, `1d`. */
|
|
1453
1517
|
export declare const TRIGGER_DELAY_PATTERN: RegExp;
|
|
1454
|
-
/** The longest title an agent gives a trigger it makes. */
|
|
1455
|
-
export declare const TRIGGER_TITLE_MAX = 80;
|
|
1456
1518
|
/** Where an agent-made trigger runs: the calling session (`this`), or a session of its own (`own`). */
|
|
1457
1519
|
export declare const TRIGGER_TOOL_SESSIONS: readonly ["this", "own"];
|
|
1458
1520
|
/**
|
|
@@ -1592,6 +1654,7 @@ export declare const TenantRunSchema: z.ZodObject<{
|
|
|
1592
1654
|
late: z.ZodBoolean;
|
|
1593
1655
|
origin: z.ZodEnum<{
|
|
1594
1656
|
agent: "agent";
|
|
1657
|
+
api: "api";
|
|
1595
1658
|
manifest: "manifest";
|
|
1596
1659
|
wake: "wake";
|
|
1597
1660
|
}>;
|
|
@@ -1626,6 +1689,7 @@ export declare const TenantRunEventSchema: z.ZodObject<{
|
|
|
1626
1689
|
late: z.ZodBoolean;
|
|
1627
1690
|
origin: z.ZodEnum<{
|
|
1628
1691
|
agent: "agent";
|
|
1692
|
+
api: "api";
|
|
1629
1693
|
manifest: "manifest";
|
|
1630
1694
|
wake: "wake";
|
|
1631
1695
|
}>;
|
package/dist/contracts.js
CHANGED
|
@@ -1172,6 +1172,27 @@ export const AGENT_EVENT_TYPES = [
|
|
|
1172
1172
|
// Memory (track T5, D72): a turn changed the Agent's memories.
|
|
1173
1173
|
"agent.memory_updated",
|
|
1174
1174
|
];
|
|
1175
|
+
/** `agent.trigger_created` and `agent.trigger_updated`'s payload (D83, D88). */
|
|
1176
|
+
export const TriggerChangePayloadSchema = z
|
|
1177
|
+
.object({
|
|
1178
|
+
triggerId: z.string(),
|
|
1179
|
+
kind: z.enum(["schedule", "at", "webhook"]),
|
|
1180
|
+
/** Absent on events recorded before D88, which were all `agent`. */
|
|
1181
|
+
origin: z.enum(["agent", "api"]).optional(),
|
|
1182
|
+
/** The session whose agent made it: an `agent` trigger's. */
|
|
1183
|
+
sessionId: z.string().optional(),
|
|
1184
|
+
/** Who put it: an `api` trigger's. */
|
|
1185
|
+
principal: z.string().optional(),
|
|
1186
|
+
session: z.string(),
|
|
1187
|
+
title: z.string().optional(),
|
|
1188
|
+
schedule: z.string().optional(),
|
|
1189
|
+
timezone: z.string().optional(),
|
|
1190
|
+
at: z.string().optional(),
|
|
1191
|
+
/** On `agent.trigger_updated` from D88: the definition's fields that changed. */
|
|
1192
|
+
changed: z.array(z.string()).optional(),
|
|
1193
|
+
nextRunAt: z.string().nullable(),
|
|
1194
|
+
})
|
|
1195
|
+
.passthrough();
|
|
1175
1196
|
/** The payload of each Agent lifecycle event. */
|
|
1176
1197
|
export const AGENT_EVENT_PAYLOADS = {
|
|
1177
1198
|
"agent.created": z
|
|
@@ -1268,34 +1289,26 @@ export const AGENT_EVENT_PAYLOADS = {
|
|
|
1268
1289
|
/** A webhook trigger's signing secret was made or replaced; the one before stopped working. */
|
|
1269
1290
|
"agent.trigger_secret_rotated": z.object({ triggerId: z.string() }).passthrough(),
|
|
1270
1291
|
/**
|
|
1271
|
-
* An agent made a trigger with the `triggers` tool (D83), or
|
|
1272
|
-
* (
|
|
1273
|
-
*
|
|
1292
|
+
* An agent made a trigger with the `triggers` tool (D83), or a client put one over the API
|
|
1293
|
+
* (D88), or either replaced one with the same id (`agent.trigger_updated`): where it came from
|
|
1294
|
+
* (`origin`), the session whose agent made it (`sessionId`, for `agent`) or who put it
|
|
1295
|
+
* (`principal`, for `api`), the session it runs in (`session`), its timing, its title, its next
|
|
1296
|
+
* run, and on an update the fields that changed (`changed`).
|
|
1274
1297
|
*/
|
|
1275
|
-
"agent.trigger_created":
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
nextRunAt: z.string().nullable(),
|
|
1283
|
-
})
|
|
1284
|
-
.passthrough(),
|
|
1285
|
-
"agent.trigger_updated": z
|
|
1298
|
+
"agent.trigger_created": TriggerChangePayloadSchema,
|
|
1299
|
+
"agent.trigger_updated": TriggerChangePayloadSchema,
|
|
1300
|
+
/**
|
|
1301
|
+
* A trigger an agent made or a client put was deleted: by an agent of `sessionId`, or over the
|
|
1302
|
+
* API (`principal`); `origin` says which kind of trigger it was (D88).
|
|
1303
|
+
*/
|
|
1304
|
+
"agent.trigger_deleted": z
|
|
1286
1305
|
.object({
|
|
1287
1306
|
triggerId: z.string(),
|
|
1288
|
-
|
|
1289
|
-
sessionId: z.string(),
|
|
1290
|
-
|
|
1291
|
-
title: z.string().optional(),
|
|
1292
|
-
nextRunAt: z.string().nullable(),
|
|
1307
|
+
origin: z.enum(["agent", "api"]).optional(),
|
|
1308
|
+
sessionId: z.string().optional(),
|
|
1309
|
+
principal: z.string().optional(),
|
|
1293
1310
|
})
|
|
1294
1311
|
.passthrough(),
|
|
1295
|
-
/** A trigger an agent made was deleted: by an agent of `sessionId`, or over the API (`principal`). */
|
|
1296
|
-
"agent.trigger_deleted": z
|
|
1297
|
-
.object({ triggerId: z.string(), sessionId: z.string().optional(), principal: z.string().optional() })
|
|
1298
|
-
.passthrough(),
|
|
1299
1312
|
/** A turn changed the Agent's memories (`memory.updated` in its session): which, and how. */
|
|
1300
1313
|
"agent.memory_updated": MemoryUpdatedPayloadSchema.extend({ sessionId: z.string(), turnId: z.string() }),
|
|
1301
1314
|
};
|
|
@@ -1902,8 +1915,7 @@ export const WEBHOOK_SCHEMES = ["standard-webhooks"];
|
|
|
1902
1915
|
* The cron's smallest gap, the `at` time, the prompt's length and how many triggers a
|
|
1903
1916
|
* manifest holds are checked against the Tenant's Runtime limits when it is saved.
|
|
1904
1917
|
*/
|
|
1905
|
-
|
|
1906
|
-
.strictObject({
|
|
1918
|
+
const TRIGGER_FIELDS = {
|
|
1907
1919
|
schedule: z
|
|
1908
1920
|
.string()
|
|
1909
1921
|
.regex(/^\S+(\s+\S+){4}$/, { message: "schedule is five cron fields: minute hour day-of-month month day-of-week" })
|
|
@@ -1913,15 +1925,16 @@ export const TriggerSchema = z
|
|
|
1913
1925
|
webhook: z.enum(WEBHOOK_SCHEMES).optional(),
|
|
1914
1926
|
session: z.string().min(1).max(200),
|
|
1915
1927
|
prompt: z.string().min(1),
|
|
1916
|
-
}
|
|
1917
|
-
|
|
1928
|
+
};
|
|
1929
|
+
/** A trigger has exactly one of `schedule`, `at` or `webhook`, and `timezone` only with `schedule`. */
|
|
1930
|
+
function checkTriggerKind(trigger, ctx) {
|
|
1918
1931
|
const kinds = [trigger.schedule, trigger.at, trigger.webhook].filter((value) => value !== undefined);
|
|
1919
1932
|
if (kinds.length !== 1)
|
|
1920
1933
|
ctx.addIssue({ code: "custom", message: "A trigger has exactly one of schedule, at or webhook" });
|
|
1921
1934
|
if (trigger.timezone !== undefined && trigger.schedule === undefined)
|
|
1922
1935
|
ctx.addIssue({ code: "custom", path: ["timezone"], message: "timezone goes with schedule" });
|
|
1923
|
-
}
|
|
1924
|
-
|
|
1936
|
+
}
|
|
1937
|
+
export const TriggerSchema = z.strictObject(TRIGGER_FIELDS).superRefine(checkTriggerKind).meta({ id: "Trigger" });
|
|
1925
1938
|
/** What a trigger is: the field it has, or `wake` for a session's own booking. */
|
|
1926
1939
|
export const TRIGGER_KINDS = ["schedule", "at", "webhook", "wake"];
|
|
1927
1940
|
/** A trigger's kind, from its manifest entry. */
|
|
@@ -1934,11 +1947,12 @@ export function triggerKindOf(trigger) {
|
|
|
1934
1947
|
*/
|
|
1935
1948
|
export const TRIGGER_STATUSES = ["active", "paused", "completed"];
|
|
1936
1949
|
/**
|
|
1937
|
-
* Where a trigger's definition comes from (D83): `manifest` (the version's `runtime.triggers`),
|
|
1938
|
-
* `agent` (made by an agent of the Agent's sessions with the `triggers` tool, kept by the Agent)
|
|
1939
|
-
*
|
|
1950
|
+
* Where a trigger's definition comes from (D83, D88): `manifest` (the version's `runtime.triggers`),
|
|
1951
|
+
* `agent` (made by an agent of the Agent's sessions with the `triggers` tool, kept by the Agent),
|
|
1952
|
+
* `api` (put on the Agent by a client, `PUT /v1/agents/{id}/triggers/{triggerId}`, kept by the
|
|
1953
|
+
* Agent with the principal that put it) or `wake` (a session's booked wake, never listed).
|
|
1940
1954
|
*/
|
|
1941
|
-
export const TRIGGER_ORIGINS = ["manifest", "agent", "wake"];
|
|
1955
|
+
export const TRIGGER_ORIGINS = ["manifest", "agent", "api", "wake"];
|
|
1942
1956
|
/**
|
|
1943
1957
|
* `GET /v1/agents/{id}/triggers`: one trigger, from its manifest entry (or, for one an agent made,
|
|
1944
1958
|
* its own definition) and the Agent's state.
|
|
@@ -1948,10 +1962,12 @@ export const TriggerViewSchema = z
|
|
|
1948
1962
|
id: z.string(),
|
|
1949
1963
|
kind: z.enum(TRIGGER_KINDS),
|
|
1950
1964
|
origin: z.enum(TRIGGER_ORIGINS),
|
|
1951
|
-
/** The title an agent gave a trigger it made; null for a manifest's. */
|
|
1965
|
+
/** The title an agent or a client gave a trigger it made; null for a manifest's. */
|
|
1952
1966
|
title: z.string().nullable(),
|
|
1953
|
-
/** The session whose agent made it; null for a manifest's. */
|
|
1967
|
+
/** The session whose agent made it; null for a manifest's or an `api` trigger. */
|
|
1954
1968
|
createdSessionId: z.string().nullable(),
|
|
1969
|
+
/** Who put an `api` trigger (D88); null for every other origin. Absent from a Runtime before D88. */
|
|
1970
|
+
principal: z.string().nullable().optional(),
|
|
1955
1971
|
status: z.enum(TRIGGER_STATUSES),
|
|
1956
1972
|
/** `manual`, `new` for one an upgrade added, `undeclared` for an agent's while the version lacks `engine.triggers`. */
|
|
1957
1973
|
pausedReason: z.string().nullable(),
|
|
@@ -1975,10 +1991,18 @@ export const TriggerViewSchema = z
|
|
|
1975
1991
|
})
|
|
1976
1992
|
.strict();
|
|
1977
1993
|
export const TriggerListSchema = z.object({ triggers: z.array(TriggerViewSchema) }).strict();
|
|
1994
|
+
/** The longest title an agent or a client gives a trigger it makes. */
|
|
1995
|
+
export const TRIGGER_TITLE_MAX = 80;
|
|
1996
|
+
/**
|
|
1997
|
+
* The body of `PUT /v1/agents/{agentId}/triggers/{triggerId}` (D88): a `Trigger`, exactly as a
|
|
1998
|
+
* definition's `runtime.triggers` entry holds it, and an optional `title`. It creates the Agent's
|
|
1999
|
+
* `api` trigger with that id, or replaces it; the same body again changes nothing.
|
|
2000
|
+
*/
|
|
2001
|
+
export const TriggerPutSchema = z
|
|
2002
|
+
.strictObject({ ...TRIGGER_FIELDS, title: z.string().min(1).max(TRIGGER_TITLE_MAX).optional() })
|
|
2003
|
+
.superRefine(checkTriggerKind);
|
|
1978
2004
|
/** `in` of the `triggers` tool (D83): a delay in minutes, hours or days, such as `30m`, `2h`, `1d`. */
|
|
1979
2005
|
export const TRIGGER_DELAY_PATTERN = /^[1-9][0-9]*(m|h|d)$/;
|
|
1980
|
-
/** The longest title an agent gives a trigger it makes. */
|
|
1981
|
-
export const TRIGGER_TITLE_MAX = 80;
|
|
1982
2006
|
/** Where an agent-made trigger runs: the calling session (`this`), or a session of its own (`own`). */
|
|
1983
2007
|
export const TRIGGER_TOOL_SESSIONS = ["this", "own"];
|
|
1984
2008
|
const triggerCreateSchema = z
|