@segmentstream/ontology 0.106.3 → 0.108.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 (59) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +45 -11
  3. package/dist/analyze.d.ts +7 -1
  4. package/dist/analyze.js +271 -16
  5. package/dist/authoring.js +6 -0
  6. package/dist/diagnostics.d.ts +3 -3
  7. package/dist/diagnostics.js +1 -0
  8. package/dist/emails.d.ts +36 -5
  9. package/dist/emails.js +139 -2
  10. package/dist/index.d.ts +7 -7
  11. package/dist/index.js +5 -3
  12. package/dist/manifest.d.ts +262 -1
  13. package/dist/manifest.js +73 -4
  14. package/dist/migrate/apply.js +8 -1
  15. package/dist/migrate/model.d.ts +154 -0
  16. package/dist/migrate/storage.d.ts +2 -0
  17. package/dist/migrate/storage.js +8 -0
  18. package/dist/names.d.ts +5 -0
  19. package/dist/names.js +5 -0
  20. package/dist/ontology.d.ts +4 -1
  21. package/dist/permissions.d.ts +30 -2
  22. package/dist/permissions.js +51 -6
  23. package/dist/runtime/agent-counters.d.ts +5 -1
  24. package/dist/runtime/agent-counters.js +21 -6
  25. package/dist/runtime/agent-web.d.ts +9 -6
  26. package/dist/runtime/agent-web.js +101 -5
  27. package/dist/runtime/generated-actions.js +2 -3
  28. package/dist/runtime/guests.d.ts +32 -0
  29. package/dist/runtime/guests.js +64 -0
  30. package/dist/runtime/new-user-hook.js +2 -1
  31. package/dist/runtime/oauth.js +7 -1
  32. package/dist/runtime/pipeline.js +3 -2
  33. package/dist/runtime/principals.js +6 -4
  34. package/dist/runtime/sql-runtime.js +2 -1
  35. package/dist/runtime.d.ts +10 -2
  36. package/dist/service/agent/authentication.d.ts +6 -4
  37. package/dist/service/agent/authentication.js +20 -5
  38. package/dist/service/agent/protocol.d.ts +28 -2
  39. package/dist/service/agent/protocol.js +23 -10
  40. package/dist/service/agent/server.d.ts +9 -2
  41. package/dist/service/agent/server.js +12 -12
  42. package/dist/service/agent/tasks.d.ts +3 -0
  43. package/dist/service/agent/tasks.js +5 -3
  44. package/dist/service/agent/web-tokens.d.ts +28 -13
  45. package/dist/service/agent/web-tokens.js +91 -38
  46. package/dist/service/authentication.d.ts +6 -0
  47. package/dist/service/authentication.js +11 -2
  48. package/dist/service/chat/review-delivery.js +4 -0
  49. package/dist/service/mcp/server.js +3 -3
  50. package/dist/service/mcp/tools.d.ts +4 -2
  51. package/dist/service/mcp/tools.js +14 -2
  52. package/dist/service/oauth/protocol.js +8 -2
  53. package/dist/service/oauth/server.js +5 -1
  54. package/dist/service/runtime-contract.d.ts +58 -6
  55. package/dist/service/schemas.d.ts +40 -0
  56. package/dist/service/service.js +15 -4
  57. package/dist/sign-in.d.ts +66 -9
  58. package/dist/sign-in.js +87 -9
  59. package/package.json +1 -1
@@ -19,7 +19,7 @@ import { principalsOntology, reconcileWorkflowUsers } from "../runtime/principal
19
19
  import { FEDERATION_TABLES } from "../runtime/federation-tables.js";
20
20
  import { syncUserIdentities, USER_IDENTITY_ENTITY_ID } from "../runtime/user-identities.js";
21
21
  import { resolveReplicationSelection, } from "../replication/model.js";
22
- import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, CHANNEL_USERS_TABLE, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
22
+ import { ACTION_ATTRIBUTION_TABLE, AGENT_TABLES, API_KEYS_TABLE, CATALOG_TABLE, CHANNEL_USERS_TABLE, OAUTH_GRANTS_GUEST_CHECK, OAUTH_TABLES, USER_ROLES_TABLE, quoteIdentifier, quoteLiteral, historyTableName, } from "./storage.js";
23
23
  const CATALOG = quoteIdentifier(CATALOG_TABLE);
24
24
  const IDENTITY_SYNC = "Copy members' sign-in identities the legacy identity stores hold.";
25
25
  /**
@@ -502,6 +502,13 @@ export const readRuntimeTables = (input) => input.sql
502
502
  `AND ("tablename" <> '_oauth_grants' OR EXISTS (` +
503
503
  `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
504
504
  `AND table_name = '_oauth_grants' AND column_name = 'identity_id')) ` +
505
+ // Without the guests' check the OAuth DDL runs again and lets guests' grants name no user.
506
+ `AND ("tablename" <> '_oauth_grants' OR EXISTS (` +
507
+ `SELECT 1 FROM pg_catalog.pg_constraint c ` +
508
+ `JOIN pg_catalog.pg_class t ON t.oid = c.conrelid ` +
509
+ `JOIN pg_catalog.pg_namespace n ON n.oid = t.relnamespace ` +
510
+ `WHERE n.nspname = current_schema() AND t.relname = '_oauth_grants' ` +
511
+ `AND c.conname = ${quoteLiteral(OAUTH_GRANTS_GUEST_CHECK)})) ` +
505
512
  // Without `signed_up` the agent tables' idempotent DDL runs again and adds it.
506
513
  `AND ("tablename" <> ${quoteLiteral(CHANNEL_USERS_TABLE)} OR EXISTS (` +
507
514
  `SELECT 1 FROM information_schema.columns WHERE table_schema = current_schema() ` +
@@ -481,6 +481,10 @@ export declare const MigrationPlan: Schema.Struct<{
481
481
  } | undefined;
482
482
  readonly signIn?: {
483
483
  readonly policy: string;
484
+ readonly guest?: {
485
+ readonly channels: readonly string[];
486
+ readonly origins: readonly string[];
487
+ } | undefined;
484
488
  readonly browser?: {
485
489
  readonly methods: readonly string[];
486
490
  readonly primary: string;
@@ -501,6 +505,7 @@ export declare const MigrationPlan: Schema.Struct<{
501
505
  readonly origins?: readonly string[] | undefined;
502
506
  } | undefined;
503
507
  readonly onSignUp?: string | undefined;
508
+ readonly invitationEmail?: string | undefined;
504
509
  } | undefined;
505
510
  readonly emails?: {
506
511
  readonly [x: string]: {
@@ -515,6 +520,20 @@ export declare const MigrationPlan: Schema.Struct<{
515
520
  } | undefined;
516
521
  readonly note?: string | undefined;
517
522
  readonly paragraphs?: readonly string[] | undefined;
523
+ readonly sections?: readonly {
524
+ readonly title: string;
525
+ readonly text?: string | undefined;
526
+ readonly items?: readonly {
527
+ readonly label: string;
528
+ readonly code?: string | undefined;
529
+ readonly text?: string | undefined;
530
+ }[] | undefined;
531
+ readonly note?: string | undefined;
532
+ readonly copy?: {
533
+ readonly value: string;
534
+ readonly label?: string | undefined;
535
+ } | undefined;
536
+ }[] | undefined;
518
537
  readonly footer?: string | undefined;
519
538
  };
520
539
  } | undefined;
@@ -753,6 +772,10 @@ export declare const MigrationPlan: Schema.Struct<{
753
772
  } | undefined;
754
773
  readonly signIn?: {
755
774
  readonly policy: string;
775
+ readonly guest?: {
776
+ readonly channels: readonly string[];
777
+ readonly origins: readonly string[];
778
+ } | undefined;
756
779
  readonly browser?: {
757
780
  readonly methods: readonly string[];
758
781
  readonly primary: string;
@@ -773,6 +796,7 @@ export declare const MigrationPlan: Schema.Struct<{
773
796
  readonly origins?: readonly string[] | undefined;
774
797
  } | undefined;
775
798
  readonly onSignUp?: string | undefined;
799
+ readonly invitationEmail?: string | undefined;
776
800
  } | undefined;
777
801
  readonly emails?: {
778
802
  readonly [x: string]: {
@@ -787,6 +811,20 @@ export declare const MigrationPlan: Schema.Struct<{
787
811
  } | undefined;
788
812
  readonly note?: string | undefined;
789
813
  readonly paragraphs?: readonly string[] | undefined;
814
+ readonly sections?: readonly {
815
+ readonly title: string;
816
+ readonly text?: string | undefined;
817
+ readonly items?: readonly {
818
+ readonly label: string;
819
+ readonly code?: string | undefined;
820
+ readonly text?: string | undefined;
821
+ }[] | undefined;
822
+ readonly note?: string | undefined;
823
+ readonly copy?: {
824
+ readonly value: string;
825
+ readonly label?: string | undefined;
826
+ } | undefined;
827
+ }[] | undefined;
790
828
  readonly footer?: string | undefined;
791
829
  };
792
830
  } | undefined;
@@ -1035,6 +1073,20 @@ export declare const MigrationPlan: Schema.Struct<{
1035
1073
  } | undefined;
1036
1074
  readonly note?: string | undefined;
1037
1075
  readonly paragraphs?: readonly string[] | undefined;
1076
+ readonly sections?: readonly {
1077
+ readonly title: string;
1078
+ readonly text?: string | undefined;
1079
+ readonly items?: readonly {
1080
+ readonly label: string;
1081
+ readonly code?: string | undefined;
1082
+ readonly text?: string | undefined;
1083
+ }[] | undefined;
1084
+ readonly note?: string | undefined;
1085
+ readonly copy?: {
1086
+ readonly value: string;
1087
+ readonly label?: string | undefined;
1088
+ } | undefined;
1089
+ }[] | undefined;
1038
1090
  readonly footer?: string | undefined;
1039
1091
  readonly reply_to?: string | undefined;
1040
1092
  };
@@ -1076,6 +1128,10 @@ export declare const MigrationPlan: Schema.Struct<{
1076
1128
  }[] | undefined;
1077
1129
  readonly sign_in?: {
1078
1130
  readonly policy: string;
1131
+ readonly guest?: {
1132
+ readonly channels: readonly string[];
1133
+ readonly origins: readonly string[];
1134
+ } | undefined;
1079
1135
  readonly browser?: {
1080
1136
  readonly methods: readonly string[];
1081
1137
  readonly primary: string;
@@ -1096,6 +1152,7 @@ export declare const MigrationPlan: Schema.Struct<{
1096
1152
  readonly origins?: readonly string[] | undefined;
1097
1153
  } | undefined;
1098
1154
  readonly on_sign_up?: string | undefined;
1155
+ readonly invitation_email?: string | undefined;
1099
1156
  } | undefined;
1100
1157
  } | {
1101
1158
  readonly version: number;
@@ -1297,6 +1354,10 @@ export declare const MigrationPlan: Schema.Struct<{
1297
1354
  } | undefined;
1298
1355
  readonly signIn?: {
1299
1356
  readonly policy: string;
1357
+ readonly guest?: {
1358
+ readonly channels: readonly string[];
1359
+ readonly origins: readonly string[];
1360
+ } | undefined;
1300
1361
  readonly browser?: {
1301
1362
  readonly methods: readonly string[];
1302
1363
  readonly primary: string;
@@ -1317,6 +1378,7 @@ export declare const MigrationPlan: Schema.Struct<{
1317
1378
  readonly origins?: readonly string[] | undefined;
1318
1379
  } | undefined;
1319
1380
  readonly on_sign_up?: string | undefined;
1381
+ readonly invitation_email?: string | undefined;
1320
1382
  } | undefined;
1321
1383
  readonly emails?: {
1322
1384
  readonly [x: string]: {
@@ -1330,6 +1392,20 @@ export declare const MigrationPlan: Schema.Struct<{
1330
1392
  } | undefined;
1331
1393
  readonly note?: string | undefined;
1332
1394
  readonly paragraphs?: readonly string[] | undefined;
1395
+ readonly sections?: readonly {
1396
+ readonly title: string;
1397
+ readonly text?: string | undefined;
1398
+ readonly items?: readonly {
1399
+ readonly label: string;
1400
+ readonly code?: string | undefined;
1401
+ readonly text?: string | undefined;
1402
+ }[] | undefined;
1403
+ readonly note?: string | undefined;
1404
+ readonly copy?: {
1405
+ readonly value: string;
1406
+ readonly label?: string | undefined;
1407
+ } | undefined;
1408
+ }[] | undefined;
1333
1409
  readonly footer?: string | undefined;
1334
1410
  readonly reply_to?: string | undefined;
1335
1411
  };
@@ -1526,11 +1602,17 @@ export declare const MigrationPlan: Schema.Struct<{
1526
1602
  readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
1527
1603
  }>>;
1528
1604
  readonly onSignUp: Schema.optionalKey<Schema.String>;
1605
+ readonly guest: Schema.optionalKey<Schema.Struct<{
1606
+ readonly channels: Schema.$Array<Schema.String>;
1607
+ readonly origins: Schema.$Array<Schema.String>;
1608
+ }>>;
1609
+ readonly invitationEmail: Schema.optionalKey<Schema.String>;
1529
1610
  }>, {
1530
1611
  readonly onNewUser: "on_new_user";
1531
1612
  readonly codeLink: "code_link";
1532
1613
  readonly signUp: "sign_up";
1533
1614
  readonly onSignUp: "on_sign_up";
1615
+ readonly invitationEmail: "invitation_email";
1534
1616
  }>>;
1535
1617
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
1536
1618
  readonly subject: Schema.String;
@@ -1543,6 +1625,20 @@ export declare const MigrationPlan: Schema.Struct<{
1543
1625
  readonly note: Schema.optionalKey<Schema.String>;
1544
1626
  readonly paragraphs: Schema.optionalKey<Schema.$Array<Schema.String>>;
1545
1627
  readonly action: Schema.String;
1628
+ readonly sections: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1629
+ readonly title: Schema.String;
1630
+ readonly text: Schema.optionalKey<Schema.String>;
1631
+ readonly copy: Schema.optionalKey<Schema.Struct<{
1632
+ readonly label: Schema.optionalKey<Schema.String>;
1633
+ readonly value: Schema.String;
1634
+ }>>;
1635
+ readonly items: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1636
+ readonly label: Schema.String;
1637
+ readonly text: Schema.optionalKey<Schema.String>;
1638
+ readonly code: Schema.optionalKey<Schema.String>;
1639
+ }>>>;
1640
+ readonly note: Schema.optionalKey<Schema.String>;
1641
+ }>>>;
1546
1642
  readonly footer: Schema.optionalKey<Schema.String>;
1547
1643
  readonly replyTo: Schema.optionalKey<Schema.String>;
1548
1644
  }>, {
@@ -1789,11 +1885,17 @@ export declare const MigrationPlan: Schema.Struct<{
1789
1885
  readonly origins: Schema.optionalKey<Schema.$Array<Schema.String>>;
1790
1886
  }>>;
1791
1887
  readonly onSignUp: Schema.optionalKey<Schema.String>;
1888
+ readonly guest: Schema.optionalKey<Schema.Struct<{
1889
+ readonly channels: Schema.$Array<Schema.String>;
1890
+ readonly origins: Schema.$Array<Schema.String>;
1891
+ }>>;
1892
+ readonly invitationEmail: Schema.optionalKey<Schema.String>;
1792
1893
  }>, {
1793
1894
  readonly onNewUser: "on_new_user";
1794
1895
  readonly codeLink: "code_link";
1795
1896
  readonly signUp: "sign_up";
1796
1897
  readonly onSignUp: "on_sign_up";
1898
+ readonly invitationEmail: "invitation_email";
1797
1899
  }>>;
1798
1900
  readonly emails: Schema.optionalKey<Schema.$Record<Schema.String, Schema.encodeKeys<Schema.Struct<{
1799
1901
  readonly subject: Schema.String;
@@ -1806,6 +1908,20 @@ export declare const MigrationPlan: Schema.Struct<{
1806
1908
  readonly note: Schema.optionalKey<Schema.String>;
1807
1909
  readonly paragraphs: Schema.optionalKey<Schema.$Array<Schema.String>>;
1808
1910
  readonly action: Schema.String;
1911
+ readonly sections: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1912
+ readonly title: Schema.String;
1913
+ readonly text: Schema.optionalKey<Schema.String>;
1914
+ readonly copy: Schema.optionalKey<Schema.Struct<{
1915
+ readonly label: Schema.optionalKey<Schema.String>;
1916
+ readonly value: Schema.String;
1917
+ }>>;
1918
+ readonly items: Schema.optionalKey<Schema.$Array<Schema.Struct<{
1919
+ readonly label: Schema.String;
1920
+ readonly text: Schema.optionalKey<Schema.String>;
1921
+ readonly code: Schema.optionalKey<Schema.String>;
1922
+ }>>>;
1923
+ readonly note: Schema.optionalKey<Schema.String>;
1924
+ }>>>;
1809
1925
  readonly footer: Schema.optionalKey<Schema.String>;
1810
1926
  readonly replyTo: Schema.optionalKey<Schema.String>;
1811
1927
  }>, {
@@ -2108,6 +2224,10 @@ export declare const MigrationPlan: Schema.Struct<{
2108
2224
  } | undefined;
2109
2225
  readonly signIn?: {
2110
2226
  readonly policy: string;
2227
+ readonly guest?: {
2228
+ readonly channels: readonly string[];
2229
+ readonly origins: readonly string[];
2230
+ } | undefined;
2111
2231
  readonly browser?: {
2112
2232
  readonly methods: readonly string[];
2113
2233
  readonly primary: string;
@@ -2128,6 +2248,7 @@ export declare const MigrationPlan: Schema.Struct<{
2128
2248
  readonly origins?: readonly string[] | undefined;
2129
2249
  } | undefined;
2130
2250
  readonly onSignUp?: string | undefined;
2251
+ readonly invitationEmail?: string | undefined;
2131
2252
  } | undefined;
2132
2253
  readonly emails?: {
2133
2254
  readonly [x: string]: {
@@ -2142,6 +2263,20 @@ export declare const MigrationPlan: Schema.Struct<{
2142
2263
  } | undefined;
2143
2264
  readonly note?: string | undefined;
2144
2265
  readonly paragraphs?: readonly string[] | undefined;
2266
+ readonly sections?: readonly {
2267
+ readonly title: string;
2268
+ readonly text?: string | undefined;
2269
+ readonly items?: readonly {
2270
+ readonly label: string;
2271
+ readonly code?: string | undefined;
2272
+ readonly text?: string | undefined;
2273
+ }[] | undefined;
2274
+ readonly note?: string | undefined;
2275
+ readonly copy?: {
2276
+ readonly value: string;
2277
+ readonly label?: string | undefined;
2278
+ } | undefined;
2279
+ }[] | undefined;
2145
2280
  readonly footer?: string | undefined;
2146
2281
  };
2147
2282
  } | undefined;
@@ -2380,6 +2515,10 @@ export declare const MigrationPlan: Schema.Struct<{
2380
2515
  } | undefined;
2381
2516
  readonly signIn?: {
2382
2517
  readonly policy: string;
2518
+ readonly guest?: {
2519
+ readonly channels: readonly string[];
2520
+ readonly origins: readonly string[];
2521
+ } | undefined;
2383
2522
  readonly browser?: {
2384
2523
  readonly methods: readonly string[];
2385
2524
  readonly primary: string;
@@ -2400,6 +2539,7 @@ export declare const MigrationPlan: Schema.Struct<{
2400
2539
  readonly origins?: readonly string[] | undefined;
2401
2540
  } | undefined;
2402
2541
  readonly onSignUp?: string | undefined;
2542
+ readonly invitationEmail?: string | undefined;
2403
2543
  } | undefined;
2404
2544
  readonly emails?: {
2405
2545
  readonly [x: string]: {
@@ -2414,6 +2554,20 @@ export declare const MigrationPlan: Schema.Struct<{
2414
2554
  } | undefined;
2415
2555
  readonly note?: string | undefined;
2416
2556
  readonly paragraphs?: readonly string[] | undefined;
2557
+ readonly sections?: readonly {
2558
+ readonly title: string;
2559
+ readonly text?: string | undefined;
2560
+ readonly items?: readonly {
2561
+ readonly label: string;
2562
+ readonly code?: string | undefined;
2563
+ readonly text?: string | undefined;
2564
+ }[] | undefined;
2565
+ readonly note?: string | undefined;
2566
+ readonly copy?: {
2567
+ readonly value: string;
2568
+ readonly label?: string | undefined;
2569
+ } | undefined;
2570
+ }[] | undefined;
2417
2571
  readonly footer?: string | undefined;
2418
2572
  };
2419
2573
  } | undefined;
@@ -172,6 +172,8 @@ export declare const OAUTH_REQUESTS_TABLE = "_oauth_requests";
172
172
  export declare const OAUTH_GRANTS_TABLE = "_oauth_grants";
173
173
  /** Authorization codes, access tokens and refresh tokens, stored only as SHA-256 hashes. */
174
174
  export declare const OAUTH_TOKENS_TABLE = "_oauth_tokens";
175
+ /** The check that only the agent's client (`agent-web`) holds grants without a user: guests'. */
176
+ export declare const OAUTH_GRANTS_GUEST_CHECK = "_oauth_grants_guest_check";
175
177
  /** The OAuth tables, in the order they are created. */
176
178
  export declare const OAUTH_TABLES: ReadonlyArray<string>;
177
179
  /** The OAuth tables of the MCP server's authorization server. Every statement is idempotent. */
@@ -484,6 +484,8 @@ export const OAUTH_REQUESTS_TABLE = "_oauth_requests";
484
484
  export const OAUTH_GRANTS_TABLE = "_oauth_grants";
485
485
  /** Authorization codes, access tokens and refresh tokens, stored only as SHA-256 hashes. */
486
486
  export const OAUTH_TOKENS_TABLE = "_oauth_tokens";
487
+ /** The check that only the agent's client (`agent-web`) holds grants without a user: guests'. */
488
+ export const OAUTH_GRANTS_GUEST_CHECK = `${OAUTH_GRANTS_TABLE}_guest_check`;
487
489
  /** The OAuth tables, in the order they are created. */
488
490
  export const OAUTH_TABLES = [
489
491
  OAUTH_CLIENTS_TABLE,
@@ -559,6 +561,12 @@ export const OAUTH_TABLES_DDL = [
559
561
  `CREATE INDEX IF NOT EXISTS "${OAUTH_TOKENS_TABLE}_grant_id_idx" ` +
560
562
  `ON ${quoteIdentifier(OAUTH_TOKENS_TABLE)} ("grant_id")`,
561
563
  `ALTER TABLE "${OAUTH_GRANTS_TABLE}" ADD COLUMN IF NOT EXISTS "identity_id" uuid`,
564
+ // A guest's grant to the agent names no user: a guest is a session, not a user. Only the agent's
565
+ // first-party client holds such grants.
566
+ `ALTER TABLE "${OAUTH_GRANTS_TABLE}" ALTER COLUMN "user_id" DROP NOT NULL`,
567
+ `ALTER TABLE "${OAUTH_GRANTS_TABLE}" DROP CONSTRAINT IF EXISTS "${OAUTH_GRANTS_GUEST_CHECK}", ` +
568
+ `ADD CONSTRAINT "${OAUTH_GRANTS_GUEST_CHECK}" ` +
569
+ `CHECK ("user_id" IS NOT NULL OR "client_id" = 'agent-web')`,
562
570
  `ALTER TABLE "_oauth_tokens" ADD COLUMN IF NOT EXISTS "replay" text`,
563
571
  `ALTER TABLE "_oauth_tokens" ADD COLUMN IF NOT EXISTS "successor_hash" text`,
564
572
  `CREATE TABLE IF NOT EXISTS "_oauth_devices" (
package/dist/names.d.ts CHANGED
@@ -18,6 +18,11 @@ export declare const GENERATED_UPSERT_PREFIX = "upsert_by_";
18
18
  export declare const MEMBER_ROLE = "member";
19
19
  /** Implicit human feedback authority; never a stored or assignable role. */
20
20
  export declare const FEEDBACK_REPORTER_ROLE = "feedback_reporter";
21
+ /**
22
+ * The built-in role every guest holds, and only guests: `defineOntology({ guest })` gives it its
23
+ * permissions. Reserved once the ontology declares `guest`; never a stored or assignable role.
24
+ */
25
+ export declare const GUEST_ROLE = "guest";
21
26
  /** Suffix reserved for the history table each entity gets. */
22
27
  export declare const HISTORY_SUFFIX = "_history";
23
28
  /** The combinators of the query language, which take the place of field names in a `where`. */
package/dist/names.js CHANGED
@@ -50,6 +50,11 @@ export const GENERATED_UPSERT_PREFIX = "upsert_by_";
50
50
  export const MEMBER_ROLE = "member";
51
51
  /** Implicit human feedback authority; never a stored or assignable role. */
52
52
  export const FEEDBACK_REPORTER_ROLE = "feedback_reporter";
53
+ /**
54
+ * The built-in role every guest holds, and only guests: `defineOntology({ guest })` gives it its
55
+ * permissions. Reserved once the ontology declares `guest`; never a stored or assignable role.
56
+ */
57
+ export const GUEST_ROLE = "guest";
53
58
  /** Suffix reserved for the history table each entity gets. */
54
59
  export const HISTORY_SUFFIX = "_history";
55
60
  /** The combinators of the query language, which take the place of field names in a `where`. */
@@ -12,7 +12,10 @@ export interface Ontology<Entities extends ReadonlyArray<AnyEntity> = ReadonlyAr
12
12
  readonly config: OntologyConfig<Entities, Metrics>;
13
13
  /** The built-in `User` first, then the declared entities in order. */
14
14
  readonly entities: ReadonlyArray<ResolvedEntity>;
15
- /** The workspace-owned `member` role first, declared roles, then the implicit reporter when enabled. */
15
+ /**
16
+ * The workspace-owned `member` role first, declared roles, then the implicit reporter when
17
+ * enabled, then `guest` when the definition declares guests.
18
+ */
16
19
  readonly roles: ReadonlyArray<Role>;
17
20
  /** Who may become a member by signing in, with the default policy when the definition sets none. */
18
21
  readonly signIn: ResolvedSignInOptions;
@@ -22,7 +22,8 @@ export declare const READ_VERB = "read";
22
22
  * chats with the people it serves, and approving one sends it: only a role that names
23
23
  * `agent_review` reads, approves or rejects them. The workspace's deployed code is no entity, but
24
24
  * {@link WORKSPACE_SOURCE_PERMISSION} is covered the same way: `workspace_source:read` or
25
- * `workspace_source:*` grants it, `*:read` and `*:*` do not.
25
+ * `workspace_source:*` grants it, `*:read` and `*:*` do not. So are the agent's own tools
26
+ * ({@link AGENT_TOOL}): `agent_tool:sandbox` or `agent_tool:*` grants the sandbox, `*:*` does not.
26
27
  */
27
28
  export declare const EXPLICIT_GRANT_ENTITIES: ReadonlySet<string>;
28
29
  /**
@@ -35,6 +36,22 @@ export declare const WORKSPACE_SOURCE = "workspace_source";
35
36
  * member it acts for, through `GET /api/ontology/agent/source`. Only a role that names it grants it.
36
37
  */
37
38
  export declare const WORKSPACE_SOURCE_PERMISSION = "workspace_source:read";
39
+ /**
40
+ * The built-in permissions' entity for the tools the app's agent has of its own, beside the
41
+ * ontology's: `agent_tool:<tool>`. It names no entity: `check` refuses an entity or a toolset of
42
+ * this name, a scoped grant of it, and any verb of it but those of {@link AGENT_TOOL_VERBS}.
43
+ */
44
+ export declare const AGENT_TOOL = "agent_tool";
45
+ /**
46
+ * The agent's own tools a role may grant. `sandbox`: the shell and file tools in the agent's
47
+ * sandbox, copying a file the caller may read into it, and calling an ontology tool with arguments
48
+ * from a file in it. `web`: fetching pages from the domains the agent's configuration lists. The
49
+ * agent's configuration says which of them the agent has; the roles say which caller gets them.
50
+ */
51
+ export declare const AGENT_TOOL_VERBS: readonly ["sandbox", "web"];
52
+ export type AgentToolVerb = (typeof AGENT_TOOL_VERBS)[number];
53
+ /** `agent_tool:sandbox`. */
54
+ export declare function agentToolPermission(tool: AgentToolVerb): string;
38
55
  /**
39
56
  * The verbs of the built-in user's member management: inviting a member, granting and revoking
40
57
  * roles, and deactivating and reactivating a member. Like every other verb on `user` but `read` and
@@ -165,7 +182,7 @@ export interface PermissionHolder {
165
182
  /**
166
183
  * Whether the principal may do what `required` names: one of its permissions equals it, or covers it
167
184
  * through a wildcard. Workload wildcards exclude user administration, feedback, the agent's held
168
- * replies, the workspace's code and writes of sign-in identities.
185
+ * replies, the workspace's code, the agent's own tools and writes of sign-in identities.
169
186
  */
170
187
  export declare function isAllowed(required: string, principal: PermissionHolder): boolean;
171
188
  /**
@@ -219,3 +236,14 @@ export declare function principalScopes(roles: ReadonlyArray<RolePermissions>, h
219
236
  };
220
237
  /** The roles whose permissions cover `required`, by name. */
221
238
  export declare function rolesGranting(roles: ReadonlyArray<RolePermissions>, required: string): ReadonlyArray<string>;
239
+ /**
240
+ * Whether one of the ontology's roles, `member` and the roles sign-up gives included, names an agent
241
+ * tool. Only then do the roles alone decide who gets the agent's tools.
242
+ */
243
+ export declare function namesAgentTools(roles: ReadonlyArray<RolePermissions>): boolean;
244
+ /**
245
+ * The agent's own tools a caller holds, as the ontology tells the agent whom it acts for: each of
246
+ * {@link AGENT_TOOL_VERBS} whose `agent_tool:<tool>` the caller's current permissions grant, in
247
+ * that order. `roles` are the ontology's roles.
248
+ */
249
+ export declare function agentToolsOf(roles: ReadonlyArray<RolePermissions>, holder: PermissionHolder): ReadonlyArray<AgentToolVerb>;
@@ -21,11 +21,13 @@ export const READ_VERB = "read";
21
21
  * chats with the people it serves, and approving one sends it: only a role that names
22
22
  * `agent_review` reads, approves or rejects them. The workspace's deployed code is no entity, but
23
23
  * {@link WORKSPACE_SOURCE_PERMISSION} is covered the same way: `workspace_source:read` or
24
- * `workspace_source:*` grants it, `*:read` and `*:*` do not.
24
+ * `workspace_source:*` grants it, `*:read` and `*:*` do not. So are the agent's own tools
25
+ * ({@link AGENT_TOOL}): `agent_tool:sandbox` or `agent_tool:*` grants the sandbox, `*:*` does not.
25
26
  */
26
27
  export const EXPLICIT_GRANT_ENTITIES = new Set([
27
28
  "agent_chat",
28
29
  "agent_review",
30
+ "agent_tool",
29
31
  "app_feedback",
30
32
  "app_feedback_file",
31
33
  "user_identity",
@@ -41,6 +43,23 @@ export const WORKSPACE_SOURCE = "workspace_source";
41
43
  * member it acts for, through `GET /api/ontology/agent/source`. Only a role that names it grants it.
42
44
  */
43
45
  export const WORKSPACE_SOURCE_PERMISSION = `${WORKSPACE_SOURCE}:${READ_VERB}`;
46
+ /**
47
+ * The built-in permissions' entity for the tools the app's agent has of its own, beside the
48
+ * ontology's: `agent_tool:<tool>`. It names no entity: `check` refuses an entity or a toolset of
49
+ * this name, a scoped grant of it, and any verb of it but those of {@link AGENT_TOOL_VERBS}.
50
+ */
51
+ export const AGENT_TOOL = "agent_tool";
52
+ /**
53
+ * The agent's own tools a role may grant. `sandbox`: the shell and file tools in the agent's
54
+ * sandbox, copying a file the caller may read into it, and calling an ontology tool with arguments
55
+ * from a file in it. `web`: fetching pages from the domains the agent's configuration lists. The
56
+ * agent's configuration says which of them the agent has; the roles say which caller gets them.
57
+ */
58
+ export const AGENT_TOOL_VERBS = ["sandbox", "web"];
59
+ /** `agent_tool:sandbox`. */
60
+ export function agentToolPermission(tool) {
61
+ return `${AGENT_TOOL}:${tool}`;
62
+ }
44
63
  /** The built-in user's entity name in permissions. */
45
64
  const USER_ENTITY = "user";
46
65
  /**
@@ -167,9 +186,9 @@ function isUserAdministration(required) {
167
186
  !wildcardEntityCovers(USER_ENTITY, toSnakeCase(wanted.verb)));
168
187
  }
169
188
  /**
170
- * Feedback, the agent's held replies and the workspace's code always need named grants, including
171
- * for pipeline workloads: nothing a pipeline runs approves a reply to a person or reads the code it
172
- * runs from. The workspace's own pipeline code reads sign-in identities, for example to address a
189
+ * Feedback, the agent's held replies, the workspace's code and the agent's own tools always need
190
+ * named grants, including for pipeline workloads: nothing a pipeline runs approves a reply to a
191
+ * person, reads the code it runs from or uses the agent's tools. The workspace's own pipeline code reads sign-in identities, for example to address a
173
192
  * member in a chat, but nothing it runs writes them: only the platform does.
174
193
  */
175
194
  function workloadWildcardCovers(required) {
@@ -179,12 +198,12 @@ function workloadWildcardCovers(required) {
179
198
  }
180
199
  return (!isUserAdministration(required) &&
181
200
  (wanted === undefined ||
182
- !["app_feedback", "app_feedback_file", "agent_review", WORKSPACE_SOURCE].includes(toSnakeCase(wanted.entity))));
201
+ !["app_feedback", "app_feedback_file", "agent_review", WORKSPACE_SOURCE, AGENT_TOOL].includes(toSnakeCase(wanted.entity))));
183
202
  }
184
203
  /**
185
204
  * Whether the principal may do what `required` names: one of its permissions equals it, or covers it
186
205
  * through a wildcard. Workload wildcards exclude user administration, feedback, the agent's held
187
- * replies, the workspace's code and writes of sign-in identities.
206
+ * replies, the workspace's code, the agent's own tools and writes of sign-in identities.
188
207
  */
189
208
  export function isAllowed(required, principal) {
190
209
  return (
@@ -295,3 +314,29 @@ export function rolesGranting(roles, required) {
295
314
  .filter((candidate) => isAllowed(required, { permissions: candidate.permissions ?? [] }))
296
315
  .map((candidate) => candidate.name);
297
316
  }
317
+ /** Whether a role's permission names an agent tool: `agent_tool:<tool>` or `agent_tool:*`. */
318
+ function namesAgentTool(permission) {
319
+ const parsed = parsePermission(permission);
320
+ return parsed !== undefined && toSnakeCase(parsed.entity) === AGENT_TOOL;
321
+ }
322
+ /**
323
+ * Whether one of the ontology's roles, `member` and the roles sign-up gives included, names an agent
324
+ * tool. Only then do the roles alone decide who gets the agent's tools.
325
+ */
326
+ export function namesAgentTools(roles) {
327
+ // `check` reads authored roles, whose permissions may not be a list yet.
328
+ return roles.some((candidate) => Array.isArray(candidate.permissions) && candidate.permissions.some(namesAgentTool));
329
+ }
330
+ /**
331
+ * The agent's own tools a caller holds, as the ontology tells the agent whom it acts for: each of
332
+ * {@link AGENT_TOOL_VERBS} whose `agent_tool:<tool>` the caller's current permissions grant, in
333
+ * that order. `roles` are the ontology's roles.
334
+ */
335
+ export function agentToolsOf(roles, holder) {
336
+ // @legacy ontology.implicit-agent-sandbox
337
+ // Until a role names an agent tool, every caller has the sandbox, as before they were permissions.
338
+ if (!namesAgentTools(roles)) {
339
+ return ["sandbox"];
340
+ }
341
+ return AGENT_TOOL_VERBS.filter((tool) => isAllowed(agentToolPermission(tool), holder));
342
+ }
@@ -6,7 +6,11 @@ export declare const DEFAULT_AGENT_LIMITS: AgentLimits;
6
6
  /** Platform ceilings. Workspace policy can only lower these values. */
7
7
  export declare const PLATFORM_CHANNEL_LIMITS: AgentLimits;
8
8
  export declare function clampChannelLimits(input: ResolveIdentityInput["limits"]): AgentLimits;
9
- /** Only trusted runtimes submit limits; channel-app callers omit them and reuse the latest policy. */
9
+ /**
10
+ * Only trusted runtimes submit limits; channel-app callers omit them and reuse the latest policy.
11
+ * The agent sends guest limits only from its web channel, so limits without `guest` keep the guest
12
+ * limits stored before.
13
+ */
10
14
  export declare function effectiveChannelLimits(sql: SqlClient.SqlClient, input?: ResolveIdentityInput["limits"]): Effect.Effect<AgentLimits, never, never>;
11
15
  type Limited = Extract<AgentResolution, {
12
16
  status: "limited";
@@ -6,6 +6,7 @@ export const DEFAULT_AGENT_LIMITS = Object.freeze({
6
6
  perSender: Object.freeze({ turnsPerMinute: 6, turnsPerDay: 80 }),
7
7
  newUsersPerHour: 30,
8
8
  workspaceTurnsPerDay: 3000,
9
+ guest: Object.freeze({ turnsPerDay: 20, workspaceTurnsPerDay: 1000 }),
9
10
  });
10
11
  /** Platform ceilings. Workspace policy can only lower these values. */
11
12
  export const PLATFORM_CHANNEL_LIMITS = DEFAULT_AGENT_LIMITS;
@@ -13,6 +14,11 @@ const Limits = Schema.Struct({
13
14
  perSender: Schema.Struct({ turnsPerMinute: Schema.Int, turnsPerDay: Schema.Int }),
14
15
  newUsersPerHour: Schema.Int,
15
16
  workspaceTurnsPerDay: Schema.Int,
17
+ // Absent from limits an SDK before guests kept.
18
+ guest: Schema.optionalKey(Schema.Struct({
19
+ turnsPerDay: Schema.optionalKey(Schema.Int),
20
+ workspaceTurnsPerDay: Schema.optionalKey(Schema.Int),
21
+ })),
16
22
  });
17
23
  export function clampChannelLimits(input) {
18
24
  const clamp = (value, ceiling) => Number.isSafeInteger(value) && value > 0 ? Math.min(value, ceiling) : ceiling;
@@ -23,21 +29,30 @@ export function clampChannelLimits(input) {
23
29
  },
24
30
  newUsersPerHour: clamp(input?.newUsersPerHour, PLATFORM_CHANNEL_LIMITS.newUsersPerHour),
25
31
  workspaceTurnsPerDay: clamp(input?.workspaceTurnsPerDay, PLATFORM_CHANNEL_LIMITS.workspaceTurnsPerDay),
32
+ guest: {
33
+ turnsPerDay: clamp(input?.guest?.turnsPerDay, PLATFORM_CHANNEL_LIMITS.guest.turnsPerDay),
34
+ workspaceTurnsPerDay: clamp(input?.guest?.workspaceTurnsPerDay, PLATFORM_CHANNEL_LIMITS.guest.workspaceTurnsPerDay),
35
+ },
26
36
  };
27
37
  }
28
- /** Only trusted runtimes submit limits; channel-app callers omit them and reuse the latest policy. */
38
+ /**
39
+ * Only trusted runtimes submit limits; channel-app callers omit them and reuse the latest policy.
40
+ * The agent sends guest limits only from its web channel, so limits without `guest` keep the guest
41
+ * limits stored before.
42
+ */
29
43
  export function effectiveChannelLimits(sql, input) {
30
44
  return Effect.gen(function* () {
45
+ const [stored] = yield* sql.unsafe(`SELECT "limits" FROM "${CHANNEL_LIMITS_TABLE}" WHERE "id"`);
46
+ const kept = stored === undefined ? undefined : Schema.decodeUnknownSync(Limits)(stored.limits);
31
47
  if (input !== undefined) {
32
- const limits = clampChannelLimits(input);
48
+ const limits = clampChannelLimits(input.guest === undefined && kept?.guest !== undefined
49
+ ? { ...input, guest: kept.guest }
50
+ : input);
33
51
  yield* sql.unsafe(`INSERT INTO "${CHANNEL_LIMITS_TABLE}" ("id", "limits") VALUES (true, $1::jsonb)
34
52
  ON CONFLICT ("id") DO UPDATE SET "limits" = EXCLUDED."limits"`, [JSON.stringify(limits)]);
35
53
  return limits;
36
54
  }
37
- const [stored] = yield* sql.unsafe(`SELECT "limits" FROM "${CHANNEL_LIMITS_TABLE}" WHERE "id"`);
38
- return stored === undefined
39
- ? DEFAULT_AGENT_LIMITS
40
- : clampChannelLimits(Schema.decodeUnknownSync(Limits)(stored.limits));
55
+ return kept === undefined ? DEFAULT_AGENT_LIMITS : clampChannelLimits(kept);
41
56
  }).pipe(Effect.orDie);
42
57
  }
43
58
  const Counter = Schema.Struct({ count: Schema.Int, retry_after: Schema.Int });
@@ -2,15 +2,18 @@ import { Effect } from "effect";
2
2
  import type { SqlClient } from "effect/unstable/sql";
3
3
  import type { Ontology } from "../ontology.js";
4
4
  import type { AgentResolution, AgentWebStore } from "../service/runtime-contract.js";
5
- /**
6
- * Agent tokens in the ontology's OAuth tables, as channel sessions are: one standing grant per
7
- * member and resource for the first-party client `agent-web`, and a new access token on each
8
- * request. Blocking or deactivating the member revokes the grant with every other one of theirs.
9
- */
10
- /** How many new website visitors one network address may start an hour. */
5
+ /** How many new website visitors one network address may sign up an hour. */
11
6
  export declare const VISITORS_PER_CLIENT_PER_HOUR = 10;
7
+ /** How many new guests one network address may start an hour. */
8
+ export declare const GUESTS_PER_CLIENT_PER_HOUR = 10;
12
9
  export interface AgentWebAdmission {
13
10
  /** Admits a new visitor on `web` as `signUp` admits a channel account: their user, or why not. */
14
11
  readonly signUp: (visitorId: string) => Effect.Effect<AgentResolution>;
15
12
  }
13
+ /**
14
+ * Agent tokens in the ontology's OAuth tables, as channel sessions are: one standing grant per
15
+ * member and resource for the first-party client `agent-web`, and a new access token on each
16
+ * request. Blocking or deactivating the member revokes the grant with every other one of theirs.
17
+ * A guest's grant names no user: its id is the guest's, and it lives while its refresh token does.
18
+ */
16
19
  export declare function sqlAgentWebStore(ontology: Ontology, sql: SqlClient.SqlClient, admission: AgentWebAdmission): AgentWebStore;