@segmentstream/ontology 0.131.1 → 0.133.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,58 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.133.0
4
+
5
+ Every kind of connection declares verification values, and a connection may hold verification
6
+ values alone.
7
+
8
+ - `OAuth2Connection` and `ClientCredentialsConnection` take `verification={...}` as
9
+ `ApiKeyConnection` does. `uses("client_secret")` declares a verification value that is a secret
10
+ the connection already holds, such as an OAuth application's client secret a provider signs
11
+ its webhooks with; only signature checks read it.
12
+ - An `ApiKeyConnection` with `verification` and no headers, query values or `apis` holds values
13
+ only the platform's checks read: it cannot be called, and it needs its values set.
14
+ `TurnstileConnection(key=...)` is one, holding a Cloudflare Turnstile widget's `secret_key`.
15
+ - The connections manifest moves to schema 25: verification values are a top-level
16
+ `verification` list on every kind of connection, no longer API-key credentials at
17
+ `location: "verification"`.
18
+ - The ontology's guest bot check names a connection's value:
19
+ `guest.botCheck: { scheme: "turnstile", connection: turnstile, input: "secret_key" }`, with
20
+ `connection("turnstile", { description })` listed in `defineOntology({ connections })`.
21
+ `check` refuses an `input` the connection list does not carry and counts the bot check as a
22
+ use of the connection.
23
+
24
+ Action required: a guest bot check that names a workspace secret,
25
+ `guest.botCheck: { scheme: "turnstile", secret: "…" }`, is deprecated and stops working after
26
+ 2026-12-21. Declare `TurnstileConnection(key="turnstile")` in `connections/connections.py`, list
27
+ `connection("turnstile", …)` in the ontology, write
28
+ `botCheck: { scheme: "turnstile", connection: turnstile, input: "secret_key" }`, deploy, and paste
29
+ the widget's secret key on the connection's page.
30
+
31
+ Action required: Cloud reads connections manifests of schema 24, written by the connections SDK
32
+ `0.8.0`, until 2027-01-19. Upgrade `segmentstream-connections` to this release and deploy before
33
+ then.
34
+
35
+ ## 0.132.0
36
+
37
+ `agent_chat.importHistory` imports a chat's messages from before the agent recorded it, such as a
38
+ client's earlier conversation kept in the workspace's own tables or another tool. Name the chat by
39
+ its `agent_chat` record, or by `channel` and `chatId` with its `person`; each message has an `id`,
40
+ `at`, `direction` and `text`. The messages become the chat's earliest: the agent's next session of
41
+ the chat starts with them in its context, and the inbox and chat search show them. Nothing is sent
42
+ and no turn starts. Only messages at least 15 minutes older than the chat's oldest are added, and
43
+ one the chat already holds is a duplicate, so importing again adds nothing. Grant `agent_chat:import_history` to the role
44
+ that imports, such as a workflow's.
45
+
46
+ The agent orders imported history, whose archive sequences are negative, before what it recorded.
47
+
48
+ `agent_chat.takeOver` and `agent_review.revise` work through the ontology service: it handed them no
49
+ chat service, so they were refused as needing one. A member's reply to a registered private chat
50
+ with `agent_chat.postMessage` finds the chat's person again: it was refused as "The chat's person
51
+ could not be read".
52
+
53
+ The agent never gives a running session imported history as new, also when it was stored within the
54
+ minutes the session reads again for late rows.
55
+
3
56
  ## 0.131.1
4
57
 
5
58
  A provider that does not answer a connection call within its 30-second deadline is reported as
package/README.md CHANGED
@@ -441,11 +441,13 @@ export default defineOntology({
441
441
  whose `*` is one whole leftmost label over a domain of at least two labels (`websiteOrigin`,
442
442
  `matchesWebsite`). The manifest carries `sign_in.guest` and the built-in role only when
443
443
  declared; `guestOf(manifest)` reads them.
444
- - `guest.botCheck: { scheme: "turnstile", secret }` makes a new guest's request carry the
445
- website challenge's token as `bot_check`; the ontology has SegmentStream's backend check it with
446
- the challenge's provider under the workspace secret `secret` names, at
447
- `…/secrets/{name}/verify-challenge`, and refuses `bot_check_required`, `bot_check_failed` or
448
- `503 bot_check_unavailable`; each check carries an idempotency key, and a challenge solved on a
444
+ - `guest.botCheck: { scheme: "turnstile", connection, input }` makes a new guest's request carry
445
+ the website challenge's token as `bot_check`; the ontology has SegmentStream's backend check it
446
+ with the challenge's provider under the verification value `input` of the connection it names,
447
+ such as a `TurnstileConnection`'s `secret_key`, at
448
+ `…/connections/{key}/inputs/{field}/verify-challenge` (the older `secret`, a workspace secret
449
+ checked at `…/secrets/{name}/verify-challenge`, is deprecated), and refuses
450
+ `bot_check_required`, `bot_check_failed` or `503 bot_check_unavailable`; each check carries an idempotency key, and a challenge solved on a
449
451
  page whose hostname is not the requesting website's fails. `guest.confirmations: true` answers a
450
452
  guest's introspection with `confirmations: true`, for the agent to put actions that need a
451
453
  confirmation to the guest. Agent limits may cap guests' daily model cost with
@@ -1527,7 +1529,9 @@ both are recorded, moves the members and a missing `purpose` and `whenToUse` to
1527
1529
  deletes the old one. `provider`, `externalId`, `title` and `lastMessageAt` are
1528
1530
  managed. Members set `purpose` and `whenToUse` with the generated
1529
1531
  `agent_chat.update`, the chat's only generated action, which sets no relationship: `handledBy`
1530
- changes only through `agent_chat.takeOver` and `agent_chat.handBack`. Chat read/update permissions remain
1532
+ changes only through `agent_chat.takeOver` and `agent_chat.handBack`. `agent_chat.importHistory`
1533
+ adds a chat's messages from before the agent recorded it as its earliest history, for a caller with
1534
+ `agent_chat:import_history`. Chat read/update permissions remain
1531
1535
  `agent_chat:read` and `agent_chat:update`, granted explicitly; wildcard entity grants do not
1532
1536
  cover this built-in registry.
1533
1537
 
@@ -3,7 +3,7 @@ export declare const TELEGRAM = "telegram";
3
3
  /** Existing chat registry and membership storage; delivery lives in the ontology service. */
4
4
  export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
5
5
  readonly provider: import("./property.js").Property<string, false, false>;
6
- readonly kind: import("./property.js").Property<"group" | "private", true, false>;
6
+ readonly kind: import("./property.js").Property<"private" | "group", true, false>;
7
7
  readonly externalId: import("./property.js").Property<string, false, false>;
8
8
  readonly title: import("./property.js").Property<string, false, false>;
9
9
  readonly recipient: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
@@ -35,6 +35,28 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
35
35
  readonly replyTo: Schema.optionalKey<Schema.String>;
36
36
  readonly idempotencyKey: Schema.String;
37
37
  }>, import("./chat.js").ChatPreview>;
38
+ readonly importHistory: import("./action.js").Action<Schema.Struct<{
39
+ readonly chat: Schema.optionalKey<Schema.String>;
40
+ readonly channel: Schema.optionalKey<Schema.String>;
41
+ readonly chatId: Schema.optionalKey<Schema.String>;
42
+ readonly kind: Schema.optionalKey<Schema.Literals<readonly ["private", "group"]>>;
43
+ readonly thread: Schema.optionalKey<Schema.String>;
44
+ readonly person: Schema.optionalKey<Schema.String>;
45
+ readonly messages: Schema.$Array<Schema.Struct<{
46
+ readonly id: Schema.String;
47
+ readonly at: Schema.String;
48
+ readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
49
+ readonly by: Schema.optionalKey<Schema.Literals<readonly ["human", "agent", "bot"]>>;
50
+ readonly name: Schema.optionalKey<Schema.String>;
51
+ readonly text: Schema.String;
52
+ readonly replyTo: Schema.optionalKey<Schema.String>;
53
+ }>>;
54
+ }>, {
55
+ readonly imported: number;
56
+ readonly duplicates: number;
57
+ readonly skipped: number;
58
+ readonly expired: number;
59
+ }>;
38
60
  readonly postMessage: import("./action.js").Action<Schema.Struct<{
39
61
  readonly chat: Schema.String;
40
62
  readonly text: Schema.String;
@@ -54,7 +76,7 @@ export declare const AgentChat: import("./entity.js").Entity<"agent_chat", {
54
76
  readonly createdBy: string | null;
55
77
  readonly updatedBy: string | null;
56
78
  readonly provider: string;
57
- readonly kind: "group" | "private";
79
+ readonly kind: "private" | "group";
58
80
  readonly externalId: string;
59
81
  readonly title: string;
60
82
  readonly recipient: string | null;
@@ -2,7 +2,7 @@ import { Effect, Option, Schema } from "effect";
2
2
  import { action } from "./action.js";
3
3
  import { entity } from "./entity.js";
4
4
  import { ActionRejected } from "./errors.js";
5
- import { ChatDelivery, ChatPostInput } from "./chat.js";
5
+ import { ChatDelivery, ChatHistoryImportInput, ChatPostInput } from "./chat.js";
6
6
  import { p } from "./property.js";
7
7
  import { rel } from "./relationship.js";
8
8
  export const TELEGRAM = "telegram";
@@ -179,6 +179,27 @@ export const AgentChat = entity("agent_chat", {
179
179
  return yield* delivery.value.preview(input);
180
180
  }),
181
181
  }),
182
+ importHistory: action({
183
+ description: "Import a chat's messages from before the agent recorded it, such as a client's earlier " +
184
+ "conversation kept elsewhere: they become the chat's earliest messages, which the agent's " +
185
+ "next session of the chat, the inbox and chat search read as history. Name the chat by its " +
186
+ "agent_chat record, or by channel and chatId as the channel keys it. Only messages older " +
187
+ "than the chat's oldest message are added; one the chat already holds, by id, is a " +
188
+ "duplicate, so importing again adds nothing. Up to 500 messages a call: import a long chat " +
189
+ "newest first. Nothing is sent and no turn starts.",
190
+ input: ChatHistoryImportInput,
191
+ hints: { destructive: false, irreversible: true, idempotent: true },
192
+ connections: [],
193
+ prepare: ({ input }) => Effect.gen(function* () {
194
+ const delivery = yield* Effect.serviceOption(ChatDelivery);
195
+ if (Option.isNone(delivery) || delivery.value.importHistory === undefined) {
196
+ return yield* new ActionRejected({
197
+ message: "Importing chat history requires the authenticated ontology service.",
198
+ });
199
+ }
200
+ return yield* delivery.value.importHistory(input);
201
+ }),
202
+ }),
182
203
  postMessage: action({
183
204
  description: "Post to an eligible chat ID or exact title. text is Markdown (bold, italic, code, lists, " +
184
205
  "[text](url)); each channel renders it natively and degrades constructs it can't show. " +
@@ -53,7 +53,7 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
53
53
  readonly channel: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
54
54
  readonly chatId: import("./property.js").Property<string, false, false>;
55
55
  readonly recipient: import("./property.js").Property<string, false, false>;
56
- readonly chatKind: import("./property.js").Property<"group" | "private", false, false>;
56
+ readonly chatKind: import("./property.js").Property<"private" | "group", false, false>;
57
57
  readonly threadId: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
58
58
  readonly replyTo: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
59
59
  readonly sessionId: import("./property.js").Property<string, false, false>;
@@ -110,7 +110,7 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
110
110
  readonly channel: string | null;
111
111
  readonly chatId: string;
112
112
  readonly recipient: string;
113
- readonly chatKind: "group" | "private";
113
+ readonly chatKind: "private" | "group";
114
114
  readonly threadId: string | null;
115
115
  readonly replyTo: string | null;
116
116
  readonly sessionId: string;
package/dist/analyze.js CHANGED
@@ -290,7 +290,9 @@ export function analyze(config, options = {}) {
290
290
  scope,
291
291
  checkGrants: options.checkPermissions !== false,
292
292
  });
293
- checkConnectionsUsed(resolved, connections, config.connections ?? [], workflows, report, toolsets);
293
+ checkConnectionsUsed(resolved, connections, config.connections ?? [], workflows, report, toolsets,
294
+ // A connection that only checks what its provider sends is used by the check.
295
+ guest?.resolved.botCheck?.connection === undefined ? [] : [guest.resolved.botCheck.connection]);
294
296
  if (options.checkPermissions !== false) {
295
297
  // Validate authored grants before augmentation can replace a scoped grant with an unscoped
296
298
  // builder grant. Invalid authored scopes must remain errors; generated redundancy needs no warning.
@@ -1326,12 +1328,25 @@ function collectConnections(config, report) {
1326
1328
  });
1327
1329
  return connections;
1328
1330
  }
1329
- /** A listed connection that no action calls is a leftover: it grants the deployment for nothing. */
1330
- function checkConnectionsUsed(entities, connections, declared, workflows, report, toolsets = []) {
1331
+ /**
1332
+ * A listed connection that nothing calls or checks with is a leftover: it grants the deployment
1333
+ * for nothing. A webhook or the guests' bot check that reads a connection's verification value
1334
+ * uses it, such as a connection with verification values alone.
1335
+ */
1336
+ function checkConnectionsUsed(entities, connections, declared, workflows, report, toolsets = [], checks = []) {
1331
1337
  const used = new Set([
1332
1338
  ...entities.flatMap((entity) => entity.actions.flatMap((candidate) => candidate.connections)),
1333
1339
  ...workflows.flatMap((candidate) => candidate.connections),
1334
1340
  ...toolsets.map((candidate) => candidate.connection),
1341
+ ...workflows.flatMap((candidate) => candidate.triggers.flatMap((trigger) => {
1342
+ const webhook = trigger;
1343
+ return webhook.kind === "webhook" &&
1344
+ typeof webhook.connection === "string" &&
1345
+ webhook.signature?.input !== undefined
1346
+ ? [webhook.connection]
1347
+ : [];
1348
+ })),
1349
+ ...checks,
1335
1350
  ]);
1336
1351
  connections.forEach((candidate) => {
1337
1352
  if (!used.has(candidate.key)) {
@@ -1786,7 +1801,7 @@ function guestOptions(config, report) {
1786
1801
  if (!Array.isArray(options.permissions)) {
1787
1802
  report("missing-permissions", "guest.permissions", 'List what every guest may do, such as permissions: ["lead:submit"]; [] grants nothing.');
1788
1803
  }
1789
- const botCheck = guestBotCheck(options.botCheck, report);
1804
+ const botCheck = guestBotCheck(options.botCheck, report, config.connections ?? []);
1790
1805
  if (options.confirmations !== undefined && typeof options.confirmations !== "boolean") {
1791
1806
  report("invalid-sign-in", "guest.confirmations", "confirmations is true to let guests confirm actions in the website's chat, or false.");
1792
1807
  }
@@ -1809,36 +1824,59 @@ function guestOptions(config, report) {
1809
1824
  }
1810
1825
  /**
1811
1826
  * The challenge a new guest passes, as `guest.botCheck` declares it: the provider's scheme and the
1812
- * workspace secret holding its secret key. Every problem is reported.
1827
+ * connection's verification value holding its secret key, or, in the older form, the workspace
1828
+ * secret holding it. Every problem is reported.
1813
1829
  */
1814
- function guestBotCheck(value, report) {
1830
+ function guestBotCheck(value, report, connections) {
1815
1831
  if (value === undefined) {
1816
1832
  return undefined;
1817
1833
  }
1818
- const shape = `guest.botCheck takes { scheme: "${GUEST_BOT_CHECK_SCHEMES[0]}", secret: "<workspace secret>" }: ` +
1819
- "the challenge's provider and the workspace secret holding its secret key.";
1834
+ const shape = `guest.botCheck takes { scheme: "${GUEST_BOT_CHECK_SCHEMES[0]}", connection, input }: the ` +
1835
+ "challenge's provider and the verification value of the connection holding its secret key, " +
1836
+ 'such as a TurnstileConnection\'s "secret_key".';
1820
1837
  if (!isPlainObject(value)) {
1821
1838
  report("invalid-sign-in", "guest.botCheck", shape);
1822
1839
  return undefined;
1823
1840
  }
1824
1841
  for (const key of Object.keys(value)) {
1825
- if (key !== "scheme" && key !== "secret") {
1842
+ if (!["scheme", "connection", "input", "secret"].includes(key)) {
1826
1843
  report("invalid-sign-in", `guest.botCheck.${key}`, `Unknown botCheck key: ${key}. ${shape}`);
1827
1844
  }
1828
1845
  }
1829
- const { scheme, secret } = value;
1830
- if (!isGuestBotCheckScheme(scheme)) {
1846
+ const { scheme, connection, input, secret } = value;
1847
+ let valid = isGuestBotCheckScheme(scheme);
1848
+ if (!valid) {
1831
1849
  report("invalid-sign-in", "guest.botCheck.scheme", `${JSON.stringify(scheme) ?? "undefined"} is not a bot check; use one of ` +
1832
1850
  `${GUEST_BOT_CHECK_SCHEMES.join(", ")}.`);
1833
1851
  }
1834
- if (typeof secret !== "string" || !WORKSPACE_SECRET_NAME.test(secret)) {
1835
- report("invalid-sign-in", "guest.botCheck.secret", `${JSON.stringify(secret) ?? "undefined"} is not a workspace secret name; name the secret ` +
1836
- "that holds the challenge's secret key, such as turnstile-secret-key.");
1852
+ if (secret !== undefined) {
1853
+ // @legacy ontology.guest-bot-check-secret
1854
+ if (connection !== undefined || input !== undefined) {
1855
+ report("invalid-sign-in", "guest.botCheck.secret", `Name a connection or a secret, not both. ${shape}`);
1856
+ valid = false;
1857
+ }
1858
+ else if (typeof secret !== "string" || !WORKSPACE_SECRET_NAME.test(secret)) {
1859
+ report("invalid-sign-in", "guest.botCheck.secret", `${JSON.stringify(secret) ?? "undefined"} is not a workspace secret name. ${shape}`);
1860
+ valid = false;
1861
+ }
1862
+ return valid && typeof secret === "string"
1863
+ ? { scheme: scheme, secret }
1864
+ : undefined;
1865
+ }
1866
+ if (!isConnection(connection)) {
1867
+ report("invalid-sign-in", "guest.botCheck.connection", `connection is a connection handle. ${shape}`);
1868
+ valid = false;
1869
+ }
1870
+ else if (!connections.some((listed) => listed.key === connection.key)) {
1871
+ report("unknown-connection", "guest.botCheck.connection", `the connection ${String(connection.key)} is not listed in defineOntology({ connections }).`);
1872
+ valid = false;
1873
+ }
1874
+ if (typeof input !== "string" || !CONNECTION_INPUT_KEY.test(input)) {
1875
+ report("invalid-sign-in", "guest.botCheck.input", `${JSON.stringify(input) ?? "undefined"} is not a connection's verification value. ${shape}`);
1876
+ valid = false;
1837
1877
  }
1838
- return isGuestBotCheckScheme(scheme) &&
1839
- typeof secret === "string" &&
1840
- WORKSPACE_SECRET_NAME.test(secret)
1841
- ? { scheme, secret }
1878
+ return valid && isConnection(connection) && typeof input === "string"
1879
+ ? { scheme: scheme, connection: connection.key, input }
1842
1880
  : undefined;
1843
1881
  }
1844
1882
  /** Whether a scope's `where` names `me` or a path from it anywhere. */
package/dist/chat.d.ts CHANGED
@@ -48,6 +48,44 @@ export interface ChatPreview {
48
48
  }
49
49
  export declare const chatOperationId: (sessionId: string, callId: string) => string;
50
50
  export declare const chatPreviewDigest: (preview: ChatPreview) => string;
51
+ /** One message of a chat from before the agent's archive recorded it, as the workspace kept it. */
52
+ export declare const ChatHistoryMessage: Schema.Struct<{
53
+ readonly id: Schema.String;
54
+ readonly at: Schema.String;
55
+ readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
56
+ readonly by: Schema.optionalKey<Schema.Literals<readonly ["human", "agent", "bot"]>>;
57
+ readonly name: Schema.optionalKey<Schema.String>;
58
+ readonly text: Schema.String;
59
+ readonly replyTo: Schema.optionalKey<Schema.String>;
60
+ }>;
61
+ export type ChatHistoryMessage = typeof ChatHistoryMessage.Type;
62
+ /** The most messages one import takes. */
63
+ export declare const CHAT_HISTORY_MESSAGES = 500;
64
+ export declare const ChatHistoryImportInput: Schema.Struct<{
65
+ readonly chat: Schema.optionalKey<Schema.String>;
66
+ readonly channel: Schema.optionalKey<Schema.String>;
67
+ readonly chatId: Schema.optionalKey<Schema.String>;
68
+ readonly kind: Schema.optionalKey<Schema.Literals<readonly ["private", "group"]>>;
69
+ readonly thread: Schema.optionalKey<Schema.String>;
70
+ readonly person: Schema.optionalKey<Schema.String>;
71
+ readonly messages: Schema.$Array<Schema.Struct<{
72
+ readonly id: Schema.String;
73
+ readonly at: Schema.String;
74
+ readonly direction: Schema.Literals<readonly ["inbound", "outbound"]>;
75
+ readonly by: Schema.optionalKey<Schema.Literals<readonly ["human", "agent", "bot"]>>;
76
+ readonly name: Schema.optionalKey<Schema.String>;
77
+ readonly text: Schema.String;
78
+ readonly replyTo: Schema.optionalKey<Schema.String>;
79
+ }>>;
80
+ }>;
81
+ export type ChatHistoryImportInput = typeof ChatHistoryImportInput.Type;
82
+ export declare const ChatHistoryImportResult: Schema.Struct<{
83
+ readonly imported: Schema.Number;
84
+ readonly duplicates: Schema.Number;
85
+ readonly skipped: Schema.Number;
86
+ readonly expired: Schema.Number;
87
+ }>;
88
+ export type ChatHistoryImportResult = typeof ChatHistoryImportResult.Type;
51
89
  /** A member's approval of a reply the agent held for review: the draft, or their edit of it. */
52
90
  export interface ReviewSendInput {
53
91
  /** The `agent_review` record's id. */
@@ -81,6 +119,8 @@ declare const ChatDelivery_base: Context.ServiceClass<ChatDelivery, "@segmentstr
81
119
  readonly sendReview?: (input: ReviewSendInput) => Effect.Effect<ReviewSendResult, ActionError>;
82
120
  /** Asks the agent to redraft a reply it held for review, in a session of its own. */
83
121
  readonly reviseReview?: (input: ReviewReviseInput) => Effect.Effect<ReviewReviseResult, ActionError>;
122
+ /** Adds a chat's messages from before the archive recorded it, as its earliest messages. */
123
+ readonly importHistory?: (input: ChatHistoryImportInput) => Effect.Effect<ChatHistoryImportResult, ActionError>;
84
124
  /** The channels whose private chats staff may take over, as the ontology's inbox lists them. */
85
125
  readonly takeoverChannels?: ReadonlySet<string>;
86
126
  }>;
package/dist/chat.js CHANGED
@@ -29,6 +29,45 @@ export const chatPreviewDigest = (preview) => chatProtocolDigest([
29
29
  preview.finalText,
30
30
  preview.replyTo,
31
31
  ]);
32
+ /** One message of a chat from before the agent's archive recorded it, as the workspace kept it. */
33
+ export const ChatHistoryMessage = Schema.Struct({
34
+ id: Identifier.annotate({
35
+ description: "The message's id where the workspace kept it, unique in the chat: the provider's where known, " +
36
+ "so a message the archive already recorded is recognized.",
37
+ }),
38
+ at: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(64)).annotate({
39
+ description: "When it was written: an ISO 8601 time with its offset, no later than now.",
40
+ }),
41
+ direction: Schema.Literals(["inbound", "outbound"]).annotate({
42
+ description: "inbound: the chat's person wrote it; outbound: the workspace's side did.",
43
+ }),
44
+ by: Schema.optionalKey(Schema.Literals(["human", "agent", "bot"]).annotate({
45
+ description: "Who wrote it: a person, the agent, or another program. Default: human for inbound, " +
46
+ "agent for outbound.",
47
+ })),
48
+ name: Schema.optionalKey(Schema.String.check(Schema.isMaxLength(200))),
49
+ text: Schema.String.check(Schema.isMinLength(1), Schema.isMaxLength(100_000)),
50
+ replyTo: Schema.optionalKey(Identifier),
51
+ });
52
+ /** The most messages one import takes. */
53
+ export const CHAT_HISTORY_MESSAGES = 500;
54
+ export const ChatHistoryImportInput = Schema.Struct({
55
+ chat: Schema.optionalKey(Identifier.annotate({ description: "The agent_chat record of the chat, if it has one." })),
56
+ channel: Schema.optionalKey(Identifier.annotate({ description: "Without chat: the channel's name, such as whatsapp." })),
57
+ chatId: Schema.optionalKey(Identifier.annotate({
58
+ description: "Without chat: the chat's id as the channel keys it, as agent_chat externalId shows it.",
59
+ })),
60
+ kind: Schema.optionalKey(Schema.Literals(["private", "group"])),
61
+ thread: Schema.optionalKey(Identifier),
62
+ person: Schema.optionalKey(Identifier.annotate({ description: "Without chat: the user a private chat is with." })),
63
+ messages: Schema.Array(ChatHistoryMessage).check(Schema.isMinLength(1), Schema.isMaxLength(CHAT_HISTORY_MESSAGES)),
64
+ });
65
+ export const ChatHistoryImportResult = Schema.Struct({
66
+ imported: Schema.Number,
67
+ duplicates: Schema.Number,
68
+ skipped: Schema.Number,
69
+ expired: Schema.Number,
70
+ });
32
71
  /**
33
72
  * Deliver the exact Markdown source through the channel renderer, without invoking an agent; and
34
73
  * hand a reply the agent held for review back to the agent to redraft.
package/dist/index.d.ts CHANGED
@@ -49,7 +49,7 @@ export { MAX_WEBHOOK_BODY_BYTES, MAX_META_WEBHOOK_BODY_BYTES, MAX_WEBHOOK_HEADER
49
49
  export type { WebhookDelivery, WebhookHmacFormat, WebhookSignatureScheme, WebhookSignedPart, } from "./webhooks.js";
50
50
  export type { ActionEvent, ActionTrigger, AfterOptions, AnyActionHandle, AnyWorkflow, ChangedBounds, CronOptions, CronProblem, CronTrigger, TriggerFunction, TriggerRecord, WebhookOptions, WebhookSignature, WebhookVerification, WebhookTrigger, Workflow, WorkflowFunction, WorkflowOptions, WorkflowRunContext, WorkflowTrigger, } from "./workflow.js";
51
51
  export { CHANNEL_PROVIDERS, DEFAULT_SIGN_IN_POLICY, SIGN_IN_METHODS, SIGN_IN_POLICIES, SIGN_UP_CHANNELS, GUEST_BOT_CHECK_SCHEMES, GUEST_CHANNELS, matchesWebsite, signUpOrigin, websiteOrigin, } from "./sign-in.js";
52
- export type { ChannelProvider, GuestBotCheck, GuestBotCheckScheme, GuestChannel, GuestOptions, ResolvedGuest, ResolvedSignInOptions, ResolvedSignUp, SignInCheck, SignInMethod, SignInOptions, SignInPolicy, SignUpChannel, SignUpOptions, } from "./sign-in.js";
52
+ export type { ChannelProvider, GuestBotCheck, GuestBotCheckScheme, ResolvedGuestBotCheck, GuestChannel, GuestOptions, ResolvedGuest, ResolvedSignInOptions, ResolvedSignUp, SignInCheck, SignInMethod, SignInOptions, SignInPolicy, SignUpChannel, SignUpOptions, } from "./sign-in.js";
53
53
  export { SIGN_IN_CODE_VALUE } from "./emails.js";
54
54
  export type { EmailDocument, EmailLayout, EmailSection, EmailSectionItem, EmailTemplate, } from "./emails.js";
55
55
  export { EMAIL_MARKUP_VALUES, isEmailDocument, unsafeEmailHtml } from "./emails.js";
@@ -63,7 +63,7 @@ export { AgentReview, AGENT_REVIEW_MODES, AGENT_REVIEW_STATUSES, AGENT_REVIEW_TE
63
63
  export { ATTACHABLE_IDENTITY_PROVIDERS, UserIdentity, USER_IDENTITY_ORIGINS, } from "./user-identity.js";
64
64
  export type { AttachableIdentityProvider, UserIdentityOrigin } from "./user-identity.js";
65
65
  export { AppFeedback, AppFeedbackFile, APP_FEEDBACK_ENTITIES, APP_FEEDBACK_FILE_MAX_BYTES, } from "./app-feedback.js";
66
- export { ChatDelivery, ChatPostInput, ChatPostResult } from "./chat.js";
66
+ export { ChatDelivery, ChatHistoryImportInput, ChatHistoryImportResult, ChatHistoryMessage, ChatPostInput, ChatPostResult, } from "./chat.js";
67
67
  export { CHAT_CHANNEL_KINDS, CHAT_CHANNEL_NAME, CHAT_KINDS, WORKSPACE_CHANNEL_KIND, channelIdentityProvider, } from "./chat-channel.js";
68
68
  export type { ChatChannelKind, ChatKind } from "./chat-channel.js";
69
69
  export type { InboxOptions, ReviewReviseInput, ReviewReviseResult, ReviewSendInput, ReviewSendResult, } from "./chat.js";
package/dist/index.js CHANGED
@@ -37,7 +37,7 @@ export { AgentChat } from "./agent-chat.js";
37
37
  export { AgentReview, AGENT_REVIEW_MODES, AGENT_REVIEW_STATUSES, AGENT_REVIEW_TEXT_LIMIT, } from "./agent-review.js";
38
38
  export { ATTACHABLE_IDENTITY_PROVIDERS, UserIdentity, USER_IDENTITY_ORIGINS, } from "./user-identity.js";
39
39
  export { AppFeedback, AppFeedbackFile, APP_FEEDBACK_ENTITIES, APP_FEEDBACK_FILE_MAX_BYTES, } from "./app-feedback.js";
40
- export { ChatDelivery, ChatPostInput, ChatPostResult } from "./chat.js";
40
+ export { ChatDelivery, ChatHistoryImportInput, ChatHistoryImportResult, ChatHistoryMessage, ChatPostInput, ChatPostResult, } from "./chat.js";
41
41
  export { CHAT_CHANNEL_KINDS, CHAT_CHANNEL_NAME, CHAT_KINDS, WORKSPACE_CHANNEL_KIND, channelIdentityProvider, } from "./chat-channel.js";
42
42
  // The query language of `find` and of the service's list, query and traversal routes.
43
43
  export { DEFAULT_QUERY_LIMIT, entityQueryResultSchema, entityQuerySchema, entityQuerySchemas, entityRecordSchema, FILTER_OPERATORS, LIST_FILTER_OPERATORS, MANY_QUANTIFIERS, MAX_IN_VALUES, MAX_QUERY_LIMIT, OrderBy, Query, queryFields, queryJsonSchema, queryLinks, QueryResult, queryResultJsonSchema, queryResultSchema, SortDirection, WHERE_COMBINATORS, } from "./query.js";
@@ -795,7 +795,11 @@ export declare const GuestManifest: Schema.encodeKeys<Schema.Struct<{
795
795
  /** The challenge a new guest passes, and the workspace secret holding its secret key. */
796
796
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
797
797
  readonly scheme: Schema.String;
798
- readonly secret: Schema.String;
798
+ /** The connection holding the challenge's secret key, and its verification value. */
799
+ readonly connection: Schema.optionalKey<Schema.String>;
800
+ readonly input: Schema.optionalKey<Schema.String>;
801
+ /** The workspace secret holding it: the older form. */
802
+ readonly secret: Schema.optionalKey<Schema.String>;
799
803
  }>>;
800
804
  /** Guests may confirm actions that need a confirmation. */
801
805
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
@@ -828,7 +832,11 @@ export declare const SignInManifest: Schema.encodeKeys<Schema.Struct<{
828
832
  /** The challenge a new guest passes, and the workspace secret holding its secret key. */
829
833
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
830
834
  readonly scheme: Schema.String;
831
- readonly secret: Schema.String;
835
+ /** The connection holding the challenge's secret key, and its verification value. */
836
+ readonly connection: Schema.optionalKey<Schema.String>;
837
+ readonly input: Schema.optionalKey<Schema.String>;
838
+ /** The workspace secret holding it: the older form. */
839
+ readonly secret: Schema.optionalKey<Schema.String>;
832
840
  }>>;
833
841
  /** Guests may confirm actions that need a confirmation. */
834
842
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
@@ -1197,7 +1205,11 @@ export declare const OntologyManifestWire: Schema.encodeKeys<Schema.Struct<{
1197
1205
  /** The challenge a new guest passes, and the workspace secret holding its secret key. */
1198
1206
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
1199
1207
  readonly scheme: Schema.String;
1200
- readonly secret: Schema.String;
1208
+ /** The connection holding the challenge's secret key, and its verification value. */
1209
+ readonly connection: Schema.optionalKey<Schema.String>;
1210
+ readonly input: Schema.optionalKey<Schema.String>;
1211
+ /** The workspace secret holding it: the older form. */
1212
+ readonly secret: Schema.optionalKey<Schema.String>;
1201
1213
  }>>;
1202
1214
  /** Guests may confirm actions that need a confirmation. */
1203
1215
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
@@ -1717,7 +1729,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
1717
1729
  readonly origins: readonly string[];
1718
1730
  readonly botCheck?: {
1719
1731
  readonly scheme: string;
1720
- readonly secret: string;
1732
+ readonly connection?: string | undefined;
1733
+ readonly input?: string | undefined;
1734
+ readonly secret?: string | undefined;
1721
1735
  } | undefined;
1722
1736
  readonly confirmations?: boolean | undefined;
1723
1737
  } | undefined;
@@ -2068,7 +2082,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2068
2082
  readonly origins: readonly string[];
2069
2083
  readonly botCheck?: {
2070
2084
  readonly scheme: string;
2071
- readonly secret: string;
2085
+ readonly connection?: string | undefined;
2086
+ readonly input?: string | undefined;
2087
+ readonly secret?: string | undefined;
2072
2088
  } | undefined;
2073
2089
  readonly confirmations?: boolean | undefined;
2074
2090
  } | undefined;
@@ -2496,7 +2512,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2496
2512
  readonly confirmations?: boolean | undefined;
2497
2513
  readonly bot_check?: {
2498
2514
  readonly scheme: string;
2499
- readonly secret: string;
2515
+ readonly connection?: string | undefined;
2516
+ readonly input?: string | undefined;
2517
+ readonly secret?: string | undefined;
2500
2518
  } | undefined;
2501
2519
  } | undefined;
2502
2520
  readonly browser?: {
@@ -2771,7 +2789,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
2771
2789
  readonly confirmations?: boolean | undefined;
2772
2790
  readonly bot_check?: {
2773
2791
  readonly scheme: string;
2774
- readonly secret: string;
2792
+ readonly connection?: string | undefined;
2793
+ readonly input?: string | undefined;
2794
+ readonly secret?: string | undefined;
2775
2795
  } | undefined;
2776
2796
  } | undefined;
2777
2797
  readonly browser?: {
@@ -3086,7 +3106,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3086
3106
  /** The challenge a new guest passes, and the workspace secret holding its secret key. */
3087
3107
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
3088
3108
  readonly scheme: Schema.String;
3089
- readonly secret: Schema.String;
3109
+ /** The connection holding the challenge's secret key, and its verification value. */
3110
+ readonly connection: Schema.optionalKey<Schema.String>;
3111
+ readonly input: Schema.optionalKey<Schema.String>;
3112
+ /** The workspace secret holding it: the older form. */
3113
+ readonly secret: Schema.optionalKey<Schema.String>;
3090
3114
  }>>;
3091
3115
  /** Guests may confirm actions that need a confirmation. */
3092
3116
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
@@ -3558,7 +3582,11 @@ export declare const OntologyManifest: Schema.declareConstructor<{
3558
3582
  /** The challenge a new guest passes, and the workspace secret holding its secret key. */
3559
3583
  readonly botCheck: Schema.optionalKey<Schema.Struct<{
3560
3584
  readonly scheme: Schema.String;
3561
- readonly secret: Schema.String;
3585
+ /** The connection holding the challenge's secret key, and its verification value. */
3586
+ readonly connection: Schema.optionalKey<Schema.String>;
3587
+ readonly input: Schema.optionalKey<Schema.String>;
3588
+ /** The workspace secret holding it: the older form. */
3589
+ readonly secret: Schema.optionalKey<Schema.String>;
3562
3590
  }>>;
3563
3591
  /** Guests may confirm actions that need a confirmation. */
3564
3592
  readonly confirmations: Schema.optionalKey<Schema.Boolean>;
@@ -4070,7 +4098,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4070
4098
  readonly origins: readonly string[];
4071
4099
  readonly botCheck?: {
4072
4100
  readonly scheme: string;
4073
- readonly secret: string;
4101
+ readonly connection?: string | undefined;
4102
+ readonly input?: string | undefined;
4103
+ readonly secret?: string | undefined;
4074
4104
  } | undefined;
4075
4105
  readonly confirmations?: boolean | undefined;
4076
4106
  } | undefined;
@@ -4421,7 +4451,9 @@ export declare const OntologyManifest: Schema.declareConstructor<{
4421
4451
  readonly origins: readonly string[];
4422
4452
  readonly botCheck?: {
4423
4453
  readonly scheme: string;
4424
- readonly secret: string;
4454
+ readonly connection?: string | undefined;
4455
+ readonly input?: string | undefined;
4456
+ readonly secret?: string | undefined;
4425
4457
  } | undefined;
4426
4458
  readonly confirmations?: boolean | undefined;
4427
4459
  } | undefined;
@@ -4778,7 +4810,9 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
4778
4810
  readonly origins: readonly string[];
4779
4811
  readonly botCheck?: {
4780
4812
  readonly scheme: string;
4781
- readonly secret: string;
4813
+ readonly connection?: string | undefined;
4814
+ readonly input?: string | undefined;
4815
+ readonly secret?: string | undefined;
4782
4816
  } | undefined;
4783
4817
  readonly confirmations?: boolean | undefined;
4784
4818
  } | undefined;
@@ -5129,7 +5163,9 @@ export declare const decodeManifestDocument: (value: unknown) => Effect.Effect<{
5129
5163
  readonly origins: readonly string[];
5130
5164
  readonly botCheck?: {
5131
5165
  readonly scheme: string;
5132
- readonly secret: string;
5166
+ readonly connection?: string | undefined;
5167
+ readonly input?: string | undefined;
5168
+ readonly secret?: string | undefined;
5133
5169
  } | undefined;
5134
5170
  readonly confirmations?: boolean | undefined;
5135
5171
  } | undefined;