@segmentstream/agent 0.60.0 → 0.61.1

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.61.1
4
+
5
+ Pins @segmentstream/ontology 0.126.0.
6
+
7
+ ## 0.61.0
8
+
9
+ `"handoff": true` in `agent/segmentstream.json` gives the model `segmentstream__handoff({ reason })`
10
+ in a person's private chat on a messenger, mail or workspace channel. It hands the chat over to the
11
+ workspace's staff with what the person needs, and from the person's next message on the agent
12
+ answers nothing there until a member takes the chat over or hands it back. Where staff cannot take
13
+ the chat over, the tool answers `handedOff: false` and the agent goes on helping. Off when absent.
14
+
15
+ Pins @segmentstream/ontology 0.125.0.
16
+
3
17
  ## 0.60.0
4
18
 
5
19
  The agent stands down in a private chat staff took over. Where the ontology's inbox lets staff take
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- var version = "0.60.0";
7
+ var version = "0.61.1";
8
8
  function agentBuild(environment = process.env) {
9
9
  return {
10
10
  agent: version,
@@ -135,6 +135,13 @@ export interface SegmentStreamAgentConfigInput {
135
135
  * question it could not answer, for the workspace's builders to read. Off when absent.
136
136
  */
137
137
  readonly unanswered?: boolean;
138
+ /**
139
+ * Whether the model gets `segmentstream__handoff`, which hands a person's private chat over to
140
+ * the workspace's staff on a channel the ontology's `inbox.takeover` lists; the agent then
141
+ * answers none of the person's messages until a member takes the chat over or hands it back.
142
+ * Off when absent.
143
+ */
144
+ readonly handoff?: boolean;
138
145
  /**
139
146
  * The web the agent may read: `segmentstream__web_fetch` fetches `https://` pages of these
140
147
  * domains, each also covering its subdomains, for callers who hold `agent_tool:web`. No web
@@ -467,6 +474,11 @@ export interface SegmentStreamAgentConfig extends AdmissionSettings {
467
474
  * {@link SegmentStreamAgentConfigInput.unanswered}.
468
475
  */
469
476
  readonly unanswered?: boolean;
477
+ /**
478
+ * Whether the handoff tool is on; validation sets it only when it is. See
479
+ * {@link SegmentStreamAgentConfigInput.handoff}.
480
+ */
481
+ readonly handoff?: boolean;
470
482
  /** The domains the web tools reach; absent without web tools. See {@link WebSettings}. */
471
483
  readonly web?: WebSettings;
472
484
  /** The agent's browser; absent without the browser tool. See {@link BrowserSettings}. */
@@ -1013,6 +1013,7 @@ function validateConfig(input, options = {}) {
1013
1013
  "sandbox",
1014
1014
  "workspaceSource",
1015
1015
  "unanswered",
1016
+ "handoff",
1016
1017
  "web",
1017
1018
  "browser",
1018
1019
  "sessions",
@@ -1214,6 +1215,11 @@ function validateConfig(input, options = {}) {
1214
1215
  message: "must be true or false",
1215
1216
  path: ["unanswered"]
1216
1217
  });
1218
+ const handoff = root?.handoff ?? false;
1219
+ if (typeof handoff !== "boolean") issues.push({
1220
+ message: "must be true or false",
1221
+ path: ["handoff"]
1222
+ });
1217
1223
  const web = webSettings(root?.web, issues);
1218
1224
  const browser = browserSettings(root?.browser, issues);
1219
1225
  if (root?.browser !== void 0 && sandbox !== true) issues.push({
@@ -1244,6 +1250,7 @@ function validateConfig(input, options = {}) {
1244
1250
  sandbox: sandbox === true,
1245
1251
  ...workspaceSource === true ? { workspaceSource: true } : {},
1246
1252
  ...unanswered === true ? { unanswered: true } : {},
1253
+ ...handoff === true ? { handoff: true } : {},
1247
1254
  ...web === null ? {} : { web },
1248
1255
  ...browser === null ? {} : { browser },
1249
1256
  sessions,
@@ -4,4 +4,4 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- export { t as agentBuild } from "../../_chunks/build-metadata-Bz1thv2O.mjs";
7
+ export { t as agentBuild } from "../../_chunks/build-metadata-tWgFNcVM.mjs";
@@ -105,6 +105,14 @@ export interface AgentChat {
105
105
  /** A person's private chat a member of staff took over: the agent answers none of it. */
106
106
  readonly handled?: true;
107
107
  }
108
+ /** A handoff the ontology recorded, or found waiting, for a person's private chat. */
109
+ export interface ChatHandoff {
110
+ readonly id: string;
111
+ /** When the agent handed the person over; null when a member of staff holds the chat already. */
112
+ readonly handoffAt: string | null;
113
+ /** A member of staff holds the chat already. */
114
+ readonly handled?: true;
115
+ }
108
116
  export interface AgentIdentities {
109
117
  lookup(account: ChatAccount): Promise<IdentityLookup>;
110
118
  /** Server-owned admission; only an older server's route 404 falls back to GET lookup. */
@@ -141,6 +149,17 @@ export interface AgentIdentities {
141
149
  readonly recipient?: string;
142
150
  readonly threadId?: string;
143
151
  }): Promise<AgentChat>;
152
+ /**
153
+ * Hands a person's private chat over to the workspace's staff, saying what they need. Undefined
154
+ * when the ontology answers 404: it hands the chat to no one, because the chat is not
155
+ * registered, not on a channel staff take chats over on, or not the person's.
156
+ */
157
+ handOffChat(input: {
158
+ readonly provider: string;
159
+ readonly externalId: string;
160
+ readonly memberId: string;
161
+ readonly reason: string;
162
+ }): Promise<ChatHandoff | undefined>;
144
163
  }
145
164
  /** The ontology service refused or failed a pairing call. Carries its error code, not its body. */
146
165
  export declare class AgentIdentityError extends Error {
@@ -94,6 +94,17 @@ function resolution(value) {
94
94
  function nullableString(value) {
95
95
  return value === null || typeof value === "string";
96
96
  }
97
+ function chatHandoff(value) {
98
+ if (!isRecord(value) || typeof value.id !== "string" || !nullableString(value.handoffAt)) throw new AgentIdentityError({
99
+ code: "invalid_response",
100
+ message: "The ontology service answered the chat handoff with an invalid body."
101
+ });
102
+ return {
103
+ id: value.id,
104
+ handoffAt: value.handoffAt,
105
+ ...value.handled === true ? { handled: true } : {}
106
+ };
107
+ }
97
108
  function agentChat(value) {
98
109
  if (!isRecord(value) || typeof value.id !== "string" || typeof value.title !== "string" || !nullableString(value.purpose) || !nullableString(value.whenToUse)) throw new AgentIdentityError({
99
110
  code: "invalid_response",
@@ -245,6 +256,12 @@ function agentIdentities(input) {
245
256
  const response = await call("/chats/seen", { body: chat });
246
257
  if (!response.ok) throw await safeRefusal(response, "chat report");
247
258
  return agentChat(await response.json());
259
+ },
260
+ async handOffChat(input) {
261
+ const response = await call("/chats/handoff", { body: input });
262
+ if (response.status === 404) return;
263
+ if (!response.ok) throw await safeRefusal(response, "chat handoff");
264
+ return chatHandoff(await response.json());
248
265
  }
249
266
  };
250
267
  }
@@ -10,7 +10,7 @@ import { groupRoutingHealth } from "../group-routing/health.mjs";
10
10
  import { dispatchStructuredMessage, structuredMessage } from "./structured.mjs";
11
11
  import { handleWorkspaceCallback, isWorkspaceCallback } from "./callbacks.mjs";
12
12
  import { telegramText, withTelegramTexts } from "./texts.mjs";
13
- import { t as agentBuild } from "../../../_chunks/build-metadata-Bz1thv2O.mjs";
13
+ import { t as agentBuild } from "../../../_chunks/build-metadata-tWgFNcVM.mjs";
14
14
  import { attachmentLifecycle } from "./lifecycle.mjs";
15
15
  import { manifestOf } from "../../config.mjs";
16
16
  import { gatewayAttachmentDescriber } from "./attachment-description.mjs";
@@ -4,7 +4,7 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
- import { t as agentBuild } from "../../../_chunks/build-metadata-Bz1thv2O.mjs";
7
+ import { t as agentBuild } from "../../../_chunks/build-metadata-tWgFNcVM.mjs";
8
8
  import { runtimeRequestFailure } from "./runtime-request.mjs";
9
9
  import { GET } from "eve/channels";
10
10
  const HEALTH_ROUTE = "/eve/v1/telegram/health";
@@ -5,7 +5,7 @@ const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
7
  import { E as OntologyActionNotPermitted, Ft as principalRuntimeSource, It as runtimeEnvelope, L as needsConfirmation, Lt as telegramRuntimeSource, W as member, c as currentInboundRequest, j as ontologyTools, k as actionToolName } from "../../../_chunks/principal-TJ6zB2rF.mjs";
8
- import { t as agentBuild } from "../../../_chunks/build-metadata-Bz1thv2O.mjs";
8
+ import { t as agentBuild } from "../../../_chunks/build-metadata-tWgFNcVM.mjs";
9
9
  import { object } from "../confirmation-description.mjs";
10
10
  var AttachmentLifecycleNotPermitted = class extends Error {
11
11
  code = "attachment_lifecycle_not_permitted";
@@ -0,0 +1,13 @@
1
+ import { type AgentIdentities } from "../lib/identities.js";
2
+ /**
3
+ * `segmentstream__handoff`: hands the person's private chat over to the workspace's staff, with
4
+ * what they need. The ontology marks the chat (`agent_chat.handoffAt`, `handoffReason`), so the
5
+ * inbox shows it waiting, and from the person's next message on the agent records what they write
6
+ * and answers nothing, until a member takes the chat over or hands it back. The model tells the
7
+ * person in its own words, in this turn. Offered while `agent/segmentstream.json` sets
8
+ * `"handoff": true`, in a person's private chat on a messenger, mail or workspace channel; the
9
+ * ontology refuses a chat on a channel its `inbox.takeover` does not list, and the tool says so.
10
+ */
11
+ export declare function handoffTool(identities: () => AgentIdentities): import("eve/tools").ToolDefinition<Record<string, unknown>, import("../lib/workflow-serializable.js").WorkflowSerializable>;
12
+ declare const _default: import("eve").DynamicSentinel<import("eve/tools").DynamicToolResult, import("eve").DynamicContext>;
13
+ export default _default;
@@ -0,0 +1,60 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ import segmentstream from "../extension.mjs";
8
+ import { agentTaskIdOf } from "../lib/agent-task.mjs";
9
+ import { stringArgument } from "../lib/attachment-tools.mjs";
10
+ import { _t as chatChannel, gt as chatAddressOf, i as memberIdOf } from "../../_chunks/principal-TJ6zB2rF.mjs";
11
+ import { appOrigin } from "../lib/environment.mjs";
12
+ import { agentIdentities } from "../lib/identities.mjs";
13
+ import { runtimeToken } from "../lib/runtime-token.mjs";
14
+ import { n as workflowToolResult } from "../../_chunks/workflow-serializable-DU7WeCIW.mjs";
15
+ import { defineDynamic, defineTool } from "eve/tools";
16
+ const MAX_REASON = 1e3;
17
+ function handoffChat(principal) {
18
+ const chat = chatAddressOf(principal);
19
+ const memberId = memberIdOf(principal);
20
+ return chat === void 0 || chat.kind !== "private" || chat.provider === "web" || memberId === void 0 || agentTaskIdOf(principal) !== void 0 ? void 0 : {
21
+ provider: chatChannel(chat),
22
+ externalId: chat.chatId,
23
+ memberId
24
+ };
25
+ }
26
+ function handoffTool(identities) {
27
+ return defineTool({
28
+ availableInSubagents: false,
29
+ description: "Hand this conversation over to a person on the workspace's staff: when the person asks for a human, or needs something only staff can do and your instructions say to hand such cases over. Staff see the chat waiting with your reason; from the person's next message on, you answer nothing until staff hand the chat back. After calling it, tell the person in your own words that a colleague will continue here. If it answers handedOff: false, staff cannot take this chat over: keep helping the person yourself.",
30
+ inputSchema: {
31
+ type: "object",
32
+ properties: { reason: {
33
+ type: "string",
34
+ description: "For staff, in a sentence or two: what the person needs and what you already told them."
35
+ } },
36
+ required: ["reason"],
37
+ additionalProperties: false
38
+ },
39
+ async execute(input, ctx) {
40
+ const reason = stringArgument(input ?? {}, "reason").trim().slice(0, MAX_REASON);
41
+ const chat = handoffChat(ctx.session.auth.current);
42
+ if (chat === void 0 || reason === "") return workflowToolResult({ handedOff: false }, ctx);
43
+ const handed = await identities().handOffChat({
44
+ ...chat,
45
+ reason
46
+ });
47
+ return workflowToolResult(handed === void 0 ? { handedOff: false } : handed.handled === true ? {
48
+ handedOff: true,
49
+ staffHoldChat: true
50
+ } : { handedOff: true }, ctx);
51
+ }
52
+ });
53
+ }
54
+ let identities;
55
+ const handoff = handoffTool(() => identities ??= agentIdentities({
56
+ origin: appOrigin(),
57
+ token: runtimeToken
58
+ }));
59
+ var handoff_default = defineDynamic((context) => segmentstream.config.handoff !== true || handoffChat(context.session.auth.current) === void 0 ? null : handoff);
60
+ export { handoff_default as default, handoffTool };
@@ -8,6 +8,7 @@ export { default as attachments_send } from "../extension/tools/attachments_send
8
8
  export { default as attachments_stage } from "../extension/tools/attachments_stage.js";
9
9
  export { default as attachments_table } from "../extension/tools/attachments_table.js";
10
10
  export { default as browser } from "../extension/tools/browser.js";
11
+ export { default as handoff } from "../extension/tools/handoff.js";
11
12
  export { default as no_reply } from "../extension/tools/no_reply.js";
12
13
  export { default as ontology_call_file } from "../extension/tools/ontology_call_file.js";
13
14
  export { default as questions_ask } from "../extension/tools/questions_ask.js";
@@ -12,6 +12,7 @@ import attachments_send_default from "../extension/tools/attachments_send.mjs";
12
12
  import attachments_stage_default from "../extension/tools/attachments_stage.mjs";
13
13
  import attachments_table_default from "../extension/tools/attachments_table.mjs";
14
14
  import browser_default from "../extension/tools/browser.mjs";
15
+ import handoff_default from "../extension/tools/handoff.mjs";
15
16
  import no_reply_default from "../extension/tools/no_reply.mjs";
16
17
  import ontology_call_file_default from "../extension/tools/ontology_call_file.mjs";
17
18
  import questions_ask_default from "../extension/tools/questions_ask.mjs";
@@ -19,4 +20,4 @@ import sandbox_default from "../extension/tools/sandbox.mjs";
19
20
  import unanswered_default from "../extension/tools/unanswered.mjs";
20
21
  import web_fetch_default from "../extension/tools/web_fetch.mjs";
21
22
  import workspace_source_default from "../extension/tools/workspace_source.mjs";
22
- export { attachments_discard_default as attachments_discard, attachments_list_default as attachments_list, attachments_promote_default as attachments_promote, attachments_read_default as attachments_read, attachments_send_default as attachments_send, attachments_stage_default as attachments_stage, attachments_table_default as attachments_table, browser_default as browser, no_reply_default as no_reply, ontology_call_file_default as ontology_call_file, questions_ask_default as questions_ask, sandbox_default as sandbox, unanswered_default as unanswered, web_fetch_default as web_fetch, workspace_source_default as workspace_source };
23
+ export { attachments_discard_default as attachments_discard, attachments_list_default as attachments_list, attachments_promote_default as attachments_promote, attachments_read_default as attachments_read, attachments_send_default as attachments_send, attachments_stage_default as attachments_stage, attachments_table_default as attachments_table, browser_default as browser, handoff_default as handoff, no_reply_default as no_reply, ontology_call_file_default as ontology_call_file, questions_ask_default as questions_ask, sandbox_default as sandbox, unanswered_default as unanswered, web_fetch_default as web_fetch, workspace_source_default as workspace_source };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@segmentstream/agent",
3
- "version": "0.60.0",
3
+ "version": "0.61.1",
4
4
  "description": "The SegmentStream workspace agent: the ontology as tools, acting as the member who writes, and the browser, Telegram, WhatsApp and Slack through the workspace's connections.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "SegmentStream",
@@ -80,7 +80,7 @@
80
80
  "@chat-adapter/state-memory": "4.42.0",
81
81
  "@chat-adapter/telegram": "4.41.0",
82
82
  "@chat-adapter/whatsapp": "4.42.0",
83
- "@segmentstream/ontology": "0.124.0",
83
+ "@segmentstream/ontology": "0.126.0",
84
84
  "@vercel/oidc": "^3.8.4",
85
85
  "ai": "^7.0.172",
86
86
  "chat": "4.42.0",