@segmentstream/ontology 0.141.0 → 0.143.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.143.0
4
+
5
+ Roles can grant the agent's web search: `agent_tool:web_search`. It gives a caller the agent's
6
+ `segmentstream__web_search`, which the agent has while its `web.search` is on, and like every agent
7
+ tool permission only a role that names it, or `agent_tool:*`, grants it. A website's guests may hold
8
+ it in `guest.permissions`, beside `agent_tool:web`; each search is billed to the workspace.
9
+
10
+ ## 0.142.0
11
+
12
+ Every `agent_chat` record has a unique `key`, `<provider>:<externalId>`, such as
13
+ `telegram:-100123` or `web:guest:<id>`, as the chat archive names the chat. The migration that adds
14
+ it keys the chats already recorded, and the agent keys every chat it records from then on. A
15
+ warehouse-backed entity relates to `AgentChat` on it, such as a model of analytics events a
16
+ website tagged with the chat's key: `rel.one(AgentChat, { inverse: "visits", on: { chat: "key" } })`.
17
+
3
18
  ## 0.141.0
4
19
 
5
20
  `chat_history` reads a Slack channel's history, every thread of it, as the archive now keeps a
@@ -1,10 +1,16 @@
1
1
  import { Schema } from "effect";
2
2
  export declare const TELEGRAM = "telegram";
3
+ /**
4
+ * A chat's key: its channel and its id there, `<channel>:<id>`, as the chat archive and the agent's
5
+ * requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
6
+ */
7
+ export declare function agentChatKey(provider: string, externalId: string): string;
3
8
  /** Existing chat registry and membership storage; delivery lives in the ontology service. */
4
9
  export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
5
10
  readonly provider: import("./property.js").Property<string, false, false>;
6
11
  readonly kind: import("./property.js").Property<"private" | "group", true, false>;
7
12
  readonly externalId: import("./property.js").Property<string, false, false>;
13
+ readonly key: Schema.optionalKey<import("./property.js").Property<string, false, true>>;
8
14
  readonly title: import("./property.js").Property<string, false, false>;
9
15
  readonly recipient: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
10
16
  readonly threadId: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
@@ -108,6 +114,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
108
114
  readonly provider: string;
109
115
  readonly kind: "private" | "group";
110
116
  readonly externalId: string;
117
+ readonly key: string | null;
111
118
  readonly title: string;
112
119
  readonly recipient: string | null;
113
120
  readonly threadId: string | null;
@@ -6,6 +6,13 @@ import { ChatDelivery, ChatHistoryImportInput, ChatPostInput, ChatSendInput } fr
6
6
  import { p } from "./property.js";
7
7
  import { rel } from "./relationship.js";
8
8
  export const TELEGRAM = "telegram";
9
+ /**
10
+ * A chat's key: its channel and its id there, `<channel>:<id>`, as the chat archive and the agent's
11
+ * requests name the chat, such as `telegram:-100123` or `web:guest:<id>`.
12
+ */
13
+ export function agentChatKey(provider, externalId) {
14
+ return `${provider}:${externalId}`;
15
+ }
9
16
  /** Existing chat registry and membership storage; delivery lives in the ontology service. */
10
17
  export const AgentChat = entity("agent_chat", {
11
18
  id: "ent_agent_chat",
@@ -27,6 +34,16 @@ export const AgentChat = entity("agent_chat", {
27
34
  description: "Whether the chat is a group chat or a person's private chat with the agent.",
28
35
  }),
29
36
  externalId: p.text({ managed: true, description: "The chat's id at the provider." }),
37
+ // Optional only for the records a deploy before it holds, which the migration that adds it
38
+ // keys: every record has one.
39
+ key: p.text({
40
+ optional: true,
41
+ unique: true,
42
+ managed: true,
43
+ description: "The chat's key, `<provider>:<externalId>`, such as `web:guest:<id>` or " +
44
+ "`telegram:-100123`, as the chat archive names the chat. Analytics events and other " +
45
+ "records tag a chat with it, so a warehouse-backed entity relates to the chat on it.",
46
+ }),
30
47
  title: p.text({
31
48
  managed: true,
32
49
  description: "The chat's name at the provider, kept current by the agent: a private chat's is its " +
package/dist/analyze.js CHANGED
@@ -1965,14 +1965,14 @@ function checkGuestPermissions(input) {
1965
1965
  report("invalid-sign-in", path, `Guests cannot hold ${String(permission)}; name the entities they may use.`);
1966
1966
  continue;
1967
1967
  }
1968
- // A guest may read the agent's listed websites, never run its sandbox or drive its browser:
1969
- // the sandbox reads the records and files of whoever it acts for, the browser acts with the
1970
- // agent's own sign-ins, and anyone opening the website is a guest.
1968
+ // A guest may read the agent's listed websites and search the web, never run its sandbox or
1969
+ // drive its browser: the sandbox reads the records and files of whoever it acts for, the
1970
+ // browser acts with the agent's own sign-ins, and anyone opening the website is a guest.
1971
1971
  if (parsed.entity === AGENT_TOOL &&
1972
1972
  (MEMBER_AGENT_TOOLS.has(parsed.verb) || parsed.verb === WILDCARD)) {
1973
1973
  report("invalid-sign-in", path, `Guests cannot hold ${String(permission)}: the agent's sandbox and browser are never a ` +
1974
- `guest's. Name ${AGENT_TOOL}:web alone for the agent to read the websites web.domains ` +
1975
- "lists for them.");
1974
+ `guest's. Name ${AGENT_TOOL}:web for the agent to read the websites web.domains lists ` +
1975
+ `for them, and ${AGENT_TOOL}:web_search for it to search the web for them.`);
1976
1976
  continue;
1977
1977
  }
1978
1978
  const entity = entities.find((resolved) => resolved.name === parsed.entity);
@@ -2931,7 +2931,7 @@ function knownVerbs(entities, toolsets = []) {
2931
2931
  verbs.set(AGENT_TOOL, new Set(AGENT_TOOL_VERBS));
2932
2932
  return verbs;
2933
2933
  }
2934
- /** `agent_tool:sandbox, agent_tool:web and agent_tool:browser`, for messages. */
2934
+ /** `agent_tool:sandbox, agent_tool:web, agent_tool:browser and agent_tool:web_search`, for messages. */
2935
2935
  function agentToolPermissions() {
2936
2936
  return listed(AGENT_TOOL_VERBS.map((tool) => `${AGENT_TOOL}:${tool}`));
2937
2937
  }
@@ -297,6 +297,19 @@ export function planMigration(input) {
297
297
  ...retainedField(retainedAfter(renamed)),
298
298
  };
299
299
  }
300
+ /**
301
+ * What a property the platform adds to one of its built-in entities holds in the records the entity
302
+ * already has: the agent chat's `key` is its channel and its id there, as the runtime writes it for
303
+ * the chats it records from then on.
304
+ */
305
+ function builtInValues(entity, property) {
306
+ return entity === "agent_chat" && property === "key"
307
+ ? [
308
+ `UPDATE ${quoteIdentifier(tableName(entity))} SET "key" = "provider" || ':' || ` +
309
+ `"external_id" WHERE "key" IS NULL`,
310
+ ]
311
+ : [];
312
+ }
300
313
  /**
301
314
  * A deploy that drops a browser sign-in method is refused while an active member would lose access:
302
315
  * every established email member needs a SegmentStream identity to drop email, and every member with
@@ -1774,6 +1787,7 @@ function planEntityChanges(input) {
1774
1787
  sql: [
1775
1788
  ...(enumStorage === undefined ? [] : [createEnumStatement(enumStorage)]),
1776
1789
  alterTable(table, actions.join(", ")),
1790
+ ...builtInValues(entity, property.name),
1777
1791
  ],
1778
1792
  }));
1779
1793
  }
@@ -47,10 +47,11 @@ export declare const AGENT_TOOL = "agent_tool";
47
47
  * sandbox, copying a file the caller may read into it, and calling an ontology tool with arguments
48
48
  * from a file in it. `web`: fetching pages from the domains the agent's configuration lists.
49
49
  * `browser`: driving the agent's own cloud browser, signed in as the agent, with scripts that run
50
- * in its sandbox, so the agent also needs the sandbox for it. The agent's configuration says which
51
- * of them the agent has; the roles say which caller gets them.
50
+ * in its sandbox, so the agent also needs the sandbox for it. `web_search`: searching the web, each
51
+ * search billed to the workspace. The agent's configuration says which of them the agent has; the
52
+ * roles say which caller gets them.
52
53
  */
53
- export declare const AGENT_TOOL_VERBS: readonly ["sandbox", "web", "browser"];
54
+ export declare const AGENT_TOOL_VERBS: readonly ["sandbox", "web", "browser", "web_search"];
54
55
  export type AgentToolVerb = (typeof AGENT_TOOL_VERBS)[number];
55
56
  /**
56
57
  * The agent tools no guest may hold, whoever opens the website: the sandbox reads the records and
@@ -54,10 +54,11 @@ export const AGENT_TOOL = "agent_tool";
54
54
  * sandbox, copying a file the caller may read into it, and calling an ontology tool with arguments
55
55
  * from a file in it. `web`: fetching pages from the domains the agent's configuration lists.
56
56
  * `browser`: driving the agent's own cloud browser, signed in as the agent, with scripts that run
57
- * in its sandbox, so the agent also needs the sandbox for it. The agent's configuration says which
58
- * of them the agent has; the roles say which caller gets them.
57
+ * in its sandbox, so the agent also needs the sandbox for it. `web_search`: searching the web, each
58
+ * search billed to the workspace. The agent's configuration says which of them the agent has; the
59
+ * roles say which caller gets them.
59
60
  */
60
- export const AGENT_TOOL_VERBS = ["sandbox", "web", "browser"];
61
+ export const AGENT_TOOL_VERBS = ["sandbox", "web", "browser", "web_search"];
61
62
  /**
62
63
  * The agent tools no guest may hold, whoever opens the website: the sandbox reads the records and
63
64
  * files of whoever the agent acts for, and the browser acts with the agent's own sign-ins.
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
3
3
  import { Effect, Option, Schema } from "effect";
4
4
  import { SqlClient } from "effect/unstable/sql";
5
5
  import { action } from "../action.js";
6
- import { AgentChat } from "../agent-chat.js";
6
+ import { AgentChat, agentChatKey } from "../agent-chat.js";
7
7
  import { chatChannelKind } from "../chat-channel.js";
8
8
  import { AgentReview } from "../agent-review.js";
9
9
  import { AGENT_IDENTITIES_TABLE, AGENT_PAIRINGS_TABLE, CHANNEL_USERS_TABLE, IDENTITY_NOTICES_TABLE, USER_TABLE, } from "../migrate/storage.js";
@@ -560,7 +560,7 @@ export function sqlAgentStore(ontology, sql) {
560
560
  found = yield* runtime.update({
561
561
  entity: AgentChat.name,
562
562
  id: String(old.id),
563
- values: { external_id: externalId },
563
+ values: { external_id: externalId, key: agentChatKey(provider, externalId) },
564
564
  });
565
565
  }
566
566
  else if (old !== undefined && found !== undefined) {
@@ -592,7 +592,12 @@ export function sqlAgentStore(ontology, sql) {
592
592
  const chat = found === undefined
593
593
  ? yield* runtime.create({
594
594
  entity: AgentChat.name,
595
- values: { provider, external_id: externalId, ...changes },
595
+ values: {
596
+ provider,
597
+ external_id: externalId,
598
+ key: agentChatKey(provider, externalId),
599
+ ...changes,
600
+ },
596
601
  })
597
602
  : Object.keys(changes).length === 0
598
603
  ? found
@@ -688,6 +693,7 @@ export function sqlAgentStore(ontology, sql) {
688
693
  values: {
689
694
  provider: input.provider,
690
695
  external_id: input.externalId,
696
+ key: agentChatKey(input.provider, input.externalId),
691
697
  kind: "private",
692
698
  ...changes,
693
699
  },
@@ -828,6 +834,7 @@ export function sqlAgentStore(ontology, sql) {
828
834
  values: {
829
835
  provider: WEB_PROVIDER,
830
836
  external_id: externalId,
837
+ key: agentChatKey(WEB_PROVIDER, externalId),
831
838
  kind: "private",
832
839
  title: externalId,
833
840
  last_message_at: now.toISOString(),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/ontology",
3
- "version": "0.141.0",
3
+ "version": "0.143.0",
4
4
  "description": "Define a SegmentStream workspace app's ontology: entities, relationships, roles and actions, written with Effect.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",