@segmentstream/ontology 0.130.0 → 0.131.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,31 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.131.1
4
+
5
+ A provider that does not answer a connection call within its 30-second deadline is reported as
6
+ such, apart from a platform fault. The ontology SDK's `ConnectionError` has `reason: "timeout"`
7
+ for it, with SegmentStream's explanation as its message, where it had `reason: "unavailable"` and
8
+ "Connections are temporarily unavailable". `segmentstream exec` and pipelines raise
9
+ `RuntimeContextUnavailableError` with SegmentStream's explanation of a server-side failure instead
10
+ of a generic message. A provider that timed out may have received the request: retry a write only
11
+ with an idempotency key.
12
+
13
+ ## 0.131.0
14
+
15
+ Members can send a reply the agent held for review back with a note on what to change.
16
+
17
+ - **The action.** `agent_review.revise({ review, note })` sends a pending reply back. It needs the permission `agent_review:revise`.
18
+ - **The redraft.** The agent writes the reply again in a session of its own, never in the person's chat session. That session acts as the person, reads only and has none of the agent's own tools. It starts from the chat, what the turn that wrote the reply looked up, and the draft, ahead of the note.
19
+ - **The result.** The new draft becomes a pending review whose `revises` names the reply, which becomes `superseded`. A member approves, edits, rejects or sends it back again.
20
+ - **Learning from it.** The review keeps the member's `note` and `notedBy` for the workspace's own learning. Neither the person nor the agent's chat with them sees the note. Workflows can react with `after(...)` on `AgentReview.actions.revise`, and the hold triggers fire for the redraft.
21
+
22
+ The person's own session learns only that the reply was not sent, and that a rewritten one waits or was sent.
23
+
24
+ - **Agent.** The agent serves `POST /eve/segmentstream/v1/reviews/revise`, which only the deployment's own functions call. It narrows its ontology requests with `X-SegmentStream-Agent-Scope: ontology:read`, which the ontology now accepts from the agent as an OAuth grant of that scope.
25
+ - **App.** `useInboxChat` gains `revise(reply, note)`. Each held reply now carries `revision` (`redrafting` or `failed`) and `revises`.
26
+
27
+ Action required: give the roles that review replies `agent_review:revise` to let them send replies back; `*:*` does not grant it. Redrafting needs both this ontology and this agent release.
28
+
3
29
  ## 0.130.0
4
30
 
5
31
  Reply review now gives the workspace what it needs to learn from staff decisions, and gives the agent what became of its replies.
@@ -23,6 +23,16 @@ export declare const AGENT_REVIEW_STATUSES: readonly [{
23
23
  }, {
24
24
  readonly value: "rejected";
25
25
  readonly description: "Rejected: the person never sees it.";
26
+ }, {
27
+ readonly value: "superseded";
28
+ readonly description: "Redrafted at a member's request: the review that revises it replaces it.";
29
+ }];
30
+ export declare const AGENT_REVIEW_REVISION_STATES: readonly [{
31
+ readonly value: "requested";
32
+ readonly description: "A member asked the agent to redraft it; it is redrafting.";
33
+ }, {
34
+ readonly value: "failed";
35
+ readonly description: "The agent could not redraft it; it still waits as it is.";
26
36
  }];
27
37
  export declare const AGENT_REVIEW_MODES: readonly [{
28
38
  readonly value: "always";
@@ -35,6 +45,8 @@ export declare const AGENT_REVIEW_MODES: readonly [{
35
45
  export declare const AGENT_REVIEW_TEXT_LIMIT = 20000;
36
46
  /** The longest reason a member gives for rejecting a reply. */
37
47
  export declare const AGENT_REVIEW_REASON_LIMIT = 2000;
48
+ /** The longest note a member gives the agent for redrafting a reply. */
49
+ export declare const AGENT_REVIEW_NOTE_LIMIT = 2000;
38
50
  export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
39
51
  readonly key: import("./property.js").Property<string, false, true>;
40
52
  readonly provider: import("./property.js").Property<string, false, false>;
@@ -47,15 +59,20 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
47
59
  readonly sessionId: import("./property.js").Property<string, false, false>;
48
60
  readonly draft: import("./property.js").Property<string, false, false>;
49
61
  readonly text: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
50
- readonly status: import("./property.js").Property<"pending" | "sent" | "uncertain" | "failed" | "rejected", false, false>;
62
+ readonly status: import("./property.js").Property<"pending" | "sent" | "uncertain" | "failed" | "rejected" | "superseded", false, false>;
51
63
  readonly mode: import("./property.js").Property<"always" | "whenUnsure", false, false>;
52
64
  readonly confidence: Schema.optionalKey<import("./property.js").Property<number, false, false>>;
53
65
  readonly messageId: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
54
66
  readonly decidedAt: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
55
67
  readonly reason: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
68
+ readonly note: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
69
+ readonly revision: Schema.optionalKey<import("./property.js").Property<string, false, false>>;
70
+ readonly revisionState: Schema.optionalKey<import("./property.js").Property<"failed" | "requested", false, false>>;
56
71
  }, {
57
72
  readonly person: import("./relationship.js").OneRelationship<false, false, "user">;
58
73
  readonly decidedBy: import("./relationship.js").OneRelationship<true, false, "user">;
74
+ readonly notedBy: import("./relationship.js").OneRelationship<true, false, "user">;
75
+ readonly revises: import("./relationship.js").OneRelationship<true, false, "agent_review">;
59
76
  readonly agentChat: import("./relationship.js").OneRelationship<true, false, "agent_chat">;
60
77
  }, import("./entity.js").InvocableActions<{
61
78
  readonly approve: import("./action.js").Action<Schema.Struct<{
@@ -74,6 +91,14 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
74
91
  review: string;
75
92
  status: "rejected";
76
93
  }>;
94
+ readonly revise: import("./action.js").Action<Schema.Struct<{
95
+ readonly review: Schema.Codec<string, string, never, never>;
96
+ readonly note: import("./property.js").Property<string, false, false>;
97
+ }>, {
98
+ review: string;
99
+ revision: string;
100
+ status: "requested";
101
+ }>;
77
102
  }, "agent_review", {
78
103
  readonly id: string;
79
104
  readonly createdAt: string;
@@ -91,14 +116,19 @@ export declare const AgentReview: import("./entity.js").Entity<"agent_review", {
91
116
  readonly sessionId: string;
92
117
  readonly draft: string;
93
118
  readonly text: string | null;
94
- readonly status: "pending" | "sent" | "uncertain" | "failed" | "rejected";
119
+ readonly status: "pending" | "sent" | "uncertain" | "failed" | "rejected" | "superseded";
95
120
  readonly mode: "always" | "whenUnsure";
96
121
  readonly confidence: number | null;
97
122
  readonly messageId: string | null;
98
123
  readonly decidedAt: string | null;
99
124
  readonly reason: string | null;
125
+ readonly note: string | null;
126
+ readonly revision: string | null;
127
+ readonly revisionState: "failed" | "requested" | null;
100
128
  readonly personId: string;
101
129
  readonly decidedById: string | null;
130
+ readonly notedById: string | null;
131
+ readonly revisesId: string | null;
102
132
  readonly agentChatId: string | null;
103
133
  }>, Readonly<Record<never, never>>, "actions">;
104
134
  export type AgentReview = typeof AgentReview.Type;
@@ -23,6 +23,14 @@ export const AGENT_REVIEW_STATUSES = [
23
23
  },
24
24
  { value: "failed", description: "Approved; the provider refused it, and nothing was sent." },
25
25
  { value: "rejected", description: "Rejected: the person never sees it." },
26
+ {
27
+ value: "superseded",
28
+ description: "Redrafted at a member's request: the review that revises it replaces it.",
29
+ },
30
+ ];
31
+ export const AGENT_REVIEW_REVISION_STATES = [
32
+ { value: "requested", description: "A member asked the agent to redraft it; it is redrafting." },
33
+ { value: "failed", description: "The agent could not redraft it; it still waits as it is." },
26
34
  ];
27
35
  export const AGENT_REVIEW_MODES = [
28
36
  { value: "always", description: "Every reply in the chat waits for a member." },
@@ -35,6 +43,8 @@ export const AGENT_REVIEW_MODES = [
35
43
  export const AGENT_REVIEW_TEXT_LIMIT = 20_000;
36
44
  /** The longest reason a member gives for rejecting a reply. */
37
45
  export const AGENT_REVIEW_REASON_LIMIT = 2_000;
46
+ /** The longest note a member gives the agent for redrafting a reply. */
47
+ export const AGENT_REVIEW_NOTE_LIMIT = 2_000;
38
48
  export const AgentReview = entity("agent_review", {
39
49
  id: "ent_agent_review",
40
50
  label: "Agent reply review",
@@ -118,7 +128,7 @@ export const AgentReview = entity("agent_review", {
118
128
  optional: true,
119
129
  managed: true,
120
130
  label: "Decided",
121
- description: "When a member approved or rejected the reply.",
131
+ description: "When a member approved, rejected or had the reply redrafted.",
122
132
  }),
123
133
  reason: p.text({
124
134
  optional: true,
@@ -128,6 +138,26 @@ export const AgentReview = entity("agent_review", {
128
138
  description: "Why the member rejected the reply, when they said: for the workspace's own review of " +
129
139
  "the agent's replies. The person and the agent's chat with them never see it.",
130
140
  }),
141
+ note: p.text({
142
+ optional: true,
143
+ managed: true,
144
+ maxLength: AGENT_REVIEW_NOTE_LIMIT,
145
+ display: "multiline",
146
+ description: "What the member asked the agent to change when they asked it to redraft the reply. " +
147
+ "Only the redraft reads it; the person and the agent's chat with them never see it.",
148
+ }),
149
+ revision: p.text({
150
+ optional: true,
151
+ managed: true,
152
+ maxLength: 64,
153
+ description: "The redraft last asked for, by its id: only its result replaces the reply.",
154
+ }),
155
+ revisionState: p.select(AGENT_REVIEW_REVISION_STATES, {
156
+ optional: true,
157
+ managed: true,
158
+ label: "Revision",
159
+ description: "Whether the agent is redrafting the reply, or could not.",
160
+ }),
131
161
  },
132
162
  relationships: {
133
163
  // By name, so that an ontology rebuilt with the deployed `user` still resolves it.
@@ -142,7 +172,21 @@ export const AgentReview = entity("agent_review", {
142
172
  inverse: "decidedAgentReviews",
143
173
  onDelete: "setNull",
144
174
  phrase: ["was decided by", "decided"],
145
- description: "The member who approved or rejected the reply.",
175
+ description: "The member who approved, rejected or had the reply redrafted.",
176
+ }),
177
+ notedBy: rel.one("user", {
178
+ optional: true,
179
+ inverse: "notedAgentReviews",
180
+ onDelete: "setNull",
181
+ phrase: ["was sent back by", "sent back"],
182
+ description: "The member who last asked the agent to redraft the reply.",
183
+ }),
184
+ revises: rel.one("agent_review", {
185
+ optional: true,
186
+ inverse: "revisions",
187
+ onDelete: "setNull",
188
+ phrase: ["revises", "is revised by"],
189
+ description: "The reply this one redrafts at a member's request.",
146
190
  }),
147
191
  agentChat: rel.one("agent_chat", {
148
192
  optional: true,
@@ -234,4 +278,36 @@ export const AgentReview = entity("agent_review", {
234
278
  return { review: review.id, status: "rejected" };
235
279
  }),
236
280
  }),
281
+ revise: action({
282
+ description: "Ask the agent to redraft a reply it held for review, with what to change in note, in the " +
283
+ "member's words. The agent writes it again in a session of its own, which reads the chat " +
284
+ "and what it looked up for the reply but changes nothing; the new draft replaces this one " +
285
+ "as a review that waits for a member. The person and the agent's chat with them never see " +
286
+ "the note. Only a reply that still waits can be redrafted.",
287
+ hints: { destructive: false, irreversible: false, idempotent: false },
288
+ input: Schema.Struct({
289
+ review: self.ref,
290
+ note: p.text({
291
+ maxLength: AGENT_REVIEW_NOTE_LIMIT,
292
+ description: "What the agent should change, in the member's words.",
293
+ }),
294
+ }),
295
+ connections: [],
296
+ prepare: ({ input }) => Effect.gen(function* () {
297
+ const delivery = yield* Effect.serviceOption(ChatDelivery);
298
+ const revise = Option.isSome(delivery) ? delivery.value.reviseReview : undefined;
299
+ if (revise === undefined) {
300
+ return yield* new ActionRejected({
301
+ message: "Redrafting a reply requires the authenticated ontology service.",
302
+ });
303
+ }
304
+ return yield* revise({ review: String(input.review), note: input.note.trim() });
305
+ }),
306
+ // The request is recorded before the agent is asked, so that its result always finds it.
307
+ handler: ({ input, prepared }) => Effect.succeed({
308
+ review: String(input.review),
309
+ revision: prepared.revision,
310
+ status: "requested",
311
+ }),
312
+ }),
237
313
  }));
package/dist/chat.d.ts CHANGED
@@ -62,16 +62,32 @@ export interface ReviewSendResult {
62
62
  readonly messageId: string | null;
63
63
  readonly duplicate: boolean;
64
64
  }
65
+ /** A member's request that the agent redraft a reply it held for review. */
66
+ export interface ReviewReviseInput {
67
+ /** The `agent_review` record's id. */
68
+ readonly review: string;
69
+ /** What the agent should change, in the member's words. */
70
+ readonly note: string;
71
+ }
72
+ /** The redraft the agent started: its result replaces the review only while it is the last one. */
73
+ export interface ReviewReviseResult {
74
+ readonly revision: string;
75
+ }
65
76
  declare const ChatDelivery_base: Context.ServiceClass<ChatDelivery, "@segmentstream/ontology/ChatDelivery", {
66
77
  readonly preview: (input: ChatPostInput) => Effect.Effect<ChatPreview, ActionError>;
67
78
  readonly validate: (input: ChatPostInput) => Effect.Effect<void, ActionError>;
68
79
  readonly post: (input: ChatPostInput) => Effect.Effect<ChatPostResult, ActionError>;
69
80
  /** Sends a reply a member approved, as the agent and without attribution, at most once. */
70
81
  readonly sendReview?: (input: ReviewSendInput) => Effect.Effect<ReviewSendResult, ActionError>;
82
+ /** Asks the agent to redraft a reply it held for review, in a session of its own. */
83
+ readonly reviseReview?: (input: ReviewReviseInput) => Effect.Effect<ReviewReviseResult, ActionError>;
71
84
  /** The channels whose private chats staff may take over, as the ontology's inbox lists them. */
72
85
  readonly takeoverChannels?: ReadonlySet<string>;
73
86
  }>;
74
- /** Deliver the exact Markdown source through the channel renderer, without invoking an agent. */
87
+ /**
88
+ * Deliver the exact Markdown source through the channel renderer, without invoking an agent; and
89
+ * hand a reply the agent held for review back to the agent to redraft.
90
+ */
75
91
  export declare class ChatDelivery extends ChatDelivery_base {
76
92
  }
77
93
  export {};
package/dist/chat.js CHANGED
@@ -29,6 +29,9 @@ export const chatPreviewDigest = (preview) => chatProtocolDigest([
29
29
  preview.finalText,
30
30
  preview.replyTo,
31
31
  ]);
32
- /** Deliver the exact Markdown source through the channel renderer, without invoking an agent. */
32
+ /**
33
+ * Deliver the exact Markdown source through the channel renderer, without invoking an agent; and
34
+ * hand a reply the agent held for review back to the agent to redraft.
35
+ */
33
36
  export class ChatDelivery extends Context.Service()("@segmentstream/ontology/ChatDelivery") {
34
37
  }
package/dist/index.d.ts CHANGED
@@ -66,7 +66,7 @@ export { AppFeedback, AppFeedbackFile, APP_FEEDBACK_ENTITIES, APP_FEEDBACK_FILE_
66
66
  export { ChatDelivery, 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
- export type { InboxOptions, ReviewSendInput, ReviewSendResult } from "./chat.js";
69
+ export type { InboxOptions, ReviewReviseInput, ReviewReviseResult, ReviewSendInput, ReviewSendResult, } from "./chat.js";
70
70
  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";
71
71
  export type { EntityQuerySchemas, FieldFilter, FilterOperator, JsonRecord, ListFilterOperator, ManyFilter, QueryField, QueryLink, StorageType, Where, } from "./query.js";
72
72
  export { InvalidQuery, InvalidValues, MemberNotFound, PrincipalRejected, StoredRecordMismatch, UnknownAction, UnknownRole, ValidationIssue, UndeclaredWrite, WriteOutsideAction, } from "./runtime/errors.js";