@opengeni/contracts 1.3.0 → 1.4.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.
@@ -174,6 +174,7 @@ export const ToolReviewStatus = z.enum([
174
174
  "cancelled",
175
175
  "expired",
176
176
  "revoked",
177
+ "blocked",
177
178
  "stale",
178
179
  "failed",
179
180
  "unavailable",
@@ -14,7 +14,17 @@ export function toolReviewFieldLabel(key: string): string {
14
14
  const label = key
15
15
  .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
16
16
  .replace(/[_-]+/g, " ")
17
- .replace(/\bids?\b/gi, (word) => (word.length === 3 ? "IDs" : "ID"));
17
+ .replace(/\bids?\b/gi, (word) => (word.length === 3 ? "IDs" : "ID"))
18
+ .replace(
19
+ /\b(api|url|uri|http|https|ip|sql|json|html)(s?)\b/gi,
20
+ (_word, name: string, plural: string) => `${name.toUpperCase()}${plural}`,
21
+ )
22
+ // Sentence case, keeping acronyms: "Working Directory" → "Working directory".
23
+ .replace(
24
+ /(?<=\S\s+)([A-Z])([a-z]+)\b/g,
25
+ (_word, first: string, rest: string) => `${first.toLowerCase()}${rest}`,
26
+ )
27
+ .trim();
18
28
  return label.charAt(0).toUpperCase() + label.slice(1);
19
29
  }
20
30
  export function decodeReviewArguments(value: unknown): Record<string, unknown> | null {
@@ -85,8 +95,35 @@ export function toolReviewFields(
85
95
  (field) =>
86
96
  field.path !== "/contentSha256" && field.path !== "/htmlBody" && field.preview !== "",
87
97
  )
88
- .map((field) => ({ ...field, path: `/$email${field.path}` })),
89
- ...original.fields,
98
+ .map((field) => ({
99
+ ...field,
100
+ label: field.path === "/textBody" ? "Message" : field.label,
101
+ path: `/$email${field.path}`,
102
+ ...(field.path === "/attachments"
103
+ ? {
104
+ preview: context
105
+ .email!.attachments.map((attachment) => attachment.name)
106
+ .join(", ")
107
+ .slice(0, 240),
108
+ }
109
+ : {}),
110
+ })),
111
+ ...original.fields.filter(
112
+ (field) =>
113
+ ![
114
+ "/raw",
115
+ "/expectedContentSha256",
116
+ "/from",
117
+ "/to",
118
+ "/cc",
119
+ "/bcc",
120
+ "/subject",
121
+ "/body",
122
+ "/textBody",
123
+ "/htmlBody",
124
+ "/attachments",
125
+ ].includes(field.path),
126
+ ),
90
127
  ];
91
128
  return {
92
129
  fields: fields.slice(0, 16),
@@ -98,13 +135,26 @@ export function toolReviewFields(
98
135
  fields: entries.slice(0, 16).map(([key, value], index) => {
99
136
  const hidden = protectedReviewField(key, context?.protectedFields);
100
137
  const safe = hidden ? "[Protected value]" : value;
101
- const count = Array.isArray(value) ? value.length : undefined;
138
+ const count = !hidden && Array.isArray(value) ? value.length : undefined;
139
+ const compactList =
140
+ !hidden &&
141
+ Array.isArray(value) &&
142
+ value.length > 0 &&
143
+ value.length <= 4 &&
144
+ value.every(
145
+ (entry) =>
146
+ typeof entry === "string" || typeof entry === "number" || typeof entry === "boolean",
147
+ )
148
+ ? value.map(valueText).join(", ")
149
+ : undefined;
102
150
  const text =
103
- count !== undefined
104
- ? `${count.toLocaleString("en-US")} item${count === 1 ? "" : "s"}`
105
- : safe && typeof safe === "object"
106
- ? `${Object.keys(safe).length} field${Object.keys(safe).length === 1 ? "" : "s"}`
107
- : valueText(safe);
151
+ compactList !== undefined
152
+ ? compactList
153
+ : count !== undefined
154
+ ? `${count.toLocaleString("en-US")} item${count === 1 ? "" : "s"}`
155
+ : safe && typeof safe === "object"
156
+ ? `${Object.keys(safe).length} field${Object.keys(safe).length === 1 ? "" : "s"}`
157
+ : valueText(safe);
108
158
  return {
109
159
  path: fieldPointer(key, index),
110
160
  label: bound(
@@ -115,7 +165,10 @@ export function toolReviewFields(
115
165
  ),
116
166
  preview: bound(text, 240),
117
167
  ...(count !== undefined ? { count } : {}),
118
- truncated: !hidden && (text.length > 240 || (typeof value === "object" && value !== null)),
168
+ truncated:
169
+ !hidden &&
170
+ (text.length > 240 ||
171
+ (compactList === undefined && typeof value === "object" && value !== null)),
119
172
  ...(hidden ? { protected: true } : {}),
120
173
  };
121
174
  }),
@@ -132,7 +185,14 @@ export function toolReviewAction(
132
185
  "title" | "approveLabel" | "effects" | "consequence" | "selectionCount" | "selectionKind"
133
186
  > {
134
187
  const fallback = {
135
- title: context?.title ?? bound(toolReviewFieldLabel(toolName.replace(/^mcp_[^_]+__/, "")), 256),
188
+ title:
189
+ context?.title ??
190
+ bound(
191
+ toolReviewFieldLabel(
192
+ toolName.replace(/^mcp_[^_]+__/, "").replace(/^batch[_-](?=[a-z])/i, ""),
193
+ ),
194
+ 256,
195
+ ),
136
196
  approveLabel: "Approve action",
137
197
  effects: [] as string[],
138
198
  };
@@ -152,8 +212,10 @@ export function toolReviewAction(
152
212
  const selectionCount = ids?.every((id) => typeof id === "string") ? new Set(ids).size : undefined;
153
213
  const noun =
154
214
  selectionCount === undefined
155
- ? selectionKind
156
- : `${selectionCount.toLocaleString("en-US")} ${thread ? "thread" : "message"}${selectionCount === 1 ? "" : "s"}`;
215
+ ? thread
216
+ ? "conversations"
217
+ : "messages"
218
+ : `${selectionCount.toLocaleString("en-US")} ${thread ? "conversation" : "message"}${selectionCount === 1 ? "" : "s"}`;
157
219
  const addValues = toolName.startsWith("label_") ? args.labelIds : args.addLabelIds;
158
220
  const adds = Array.isArray(addValues)
159
221
  ? addValues.filter((v): v is string => typeof v === "string")
@@ -200,7 +262,7 @@ export function toolReviewAction(
200
262
  ...(trash
201
263
  ? { consequence: "Messages stay recoverable in Trash until Gmail deletes them." }
202
264
  : thread
203
- ? { consequence: "Applies to every message in the selected thread." }
265
+ ? { consequence: "Applies to every message in the conversation." }
204
266
  : {}),
205
267
  };
206
268
  }
@@ -12,6 +12,9 @@ export const TranscriptionRecordingErrorCode = z.enum([
12
12
  "too_large",
13
13
  "invalid_audio",
14
14
  "unknown",
15
+ "insufficient_credits",
16
+ "allowance_exhausted",
17
+ "monthly_model_cost_limit",
15
18
  ]);
16
19
  export type TranscriptionRecordingErrorCode = z.infer<typeof TranscriptionRecordingErrorCode>;
17
20