@opengeni/contracts 2.9.2 → 2.11.1-canary.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.
Files changed (41) hide show
  1. package/dist/atlassian.js +11 -11
  2. package/dist/{chunk-AWNGBY5I.js → chunk-6HOHS44G.js} +230 -29
  3. package/dist/chunk-6HOHS44G.js.map +1 -0
  4. package/dist/{chunk-4IVHBXRI.js → chunk-7ABONTXE.js} +42 -2
  5. package/dist/chunk-7ABONTXE.js.map +1 -0
  6. package/dist/{chunk-7RMTKFJW.js → chunk-7Q6HPDY2.js} +8 -8
  7. package/dist/{chunk-N6GRVXAJ.js → chunk-NPBM4QSK.js} +2 -2
  8. package/dist/connection-authority.js +11 -11
  9. package/dist/editable-artifact-codec-registry.js +2 -2
  10. package/dist/editable-artifact-live.js +2 -2
  11. package/dist/editable-artifact-serialized-commit.js +3 -3
  12. package/dist/editable-artifacts.js +13 -13
  13. package/dist/github-repository-contracts.d.ts +36 -0
  14. package/dist/github-repository-contracts.js +59 -0
  15. package/dist/github-repository-contracts.js.map +1 -0
  16. package/dist/github-repository.d.ts +14 -0
  17. package/dist/github-repository.js +36 -0
  18. package/dist/github-repository.js.map +1 -0
  19. package/dist/google-drive.js +12 -12
  20. package/dist/index.d.ts +492 -17
  21. package/dist/index.js +191 -135
  22. package/dist/model-picker-order.d.ts +23 -0
  23. package/dist/model-picker-order.js +42 -0
  24. package/dist/model-picker-order.js.map +1 -0
  25. package/dist/organization-membership-lifecycle.d.ts +17 -0
  26. package/dist/personal-github.js +11 -11
  27. package/dist/session-titles.d.ts +35 -0
  28. package/dist/session-titles.js +9 -3
  29. package/dist/workspace-learning-policy.d.ts +1 -1
  30. package/package.json +13 -1
  31. package/src/github-repository-contracts.ts +85 -0
  32. package/src/github-repository.ts +59 -0
  33. package/src/index.ts +336 -49
  34. package/src/model-picker-order.ts +87 -0
  35. package/src/organization-membership-lifecycle.ts +20 -0
  36. package/src/session-titles.ts +100 -0
  37. package/src/workspace-learning-policy.ts +4 -3
  38. package/dist/chunk-4IVHBXRI.js.map +0 -1
  39. package/dist/chunk-AWNGBY5I.js.map +0 -1
  40. /package/dist/{chunk-7RMTKFJW.js.map → chunk-7Q6HPDY2.js.map} +0 -0
  41. /package/dist/{chunk-N6GRVXAJ.js.map → chunk-NPBM4QSK.js.map} +0 -0
@@ -0,0 +1,87 @@
1
+ export type ModelPickerBillingClass =
2
+ | "opengeni_credits"
3
+ | "external"
4
+ | "codex_subscription"
5
+ | "supergrok_subscription"
6
+ | "byok"
7
+ | "organization_byok";
8
+
9
+ // Every closed billing class has a unique first character. Keeping the order
10
+ // as initials avoids duplicating the full public labels in browser bundles.
11
+ const MODEL_PICKER_BILLING_CLASS_ORDER: readonly ModelPickerBillingClass[] = [
12
+ "opengeni_credits",
13
+ "external",
14
+ "codex_subscription",
15
+ "supergrok_subscription",
16
+ "byok",
17
+ "organization_byok",
18
+ ];
19
+
20
+ export type ModelPickerBillingCandidate = {
21
+ source?: string | undefined;
22
+ cost?: "free" | "credits" | "subscription" | "workspace" | "organization" | undefined;
23
+ billing?:
24
+ | {
25
+ upstreamPayer?: string | undefined;
26
+ metering?: string | undefined;
27
+ }
28
+ | undefined;
29
+ credentialSource?:
30
+ | {
31
+ kind?: string | undefined;
32
+ provider?: string | undefined;
33
+ }
34
+ | undefined;
35
+ };
36
+
37
+ export function modelPickerBillingClassFor(
38
+ model: ModelPickerBillingCandidate,
39
+ ): ModelPickerBillingClass {
40
+ if (model.cost === "credits") return "opengeni_credits";
41
+ if (model.cost === "workspace") return "byok";
42
+ if (model.cost === "organization") return "organization_byok";
43
+ const source = model.source;
44
+ const credential = model.credentialSource;
45
+ const payer = model.billing?.upstreamPayer;
46
+ if (model.billing?.metering === "external" && payer === "deployment") {
47
+ return "external";
48
+ }
49
+ if (
50
+ source === "supergrok" ||
51
+ (credential?.kind === "connected_subscription" && credential.provider === "xai")
52
+ ) {
53
+ return "supergrok_subscription";
54
+ }
55
+ if (
56
+ source === "codex" ||
57
+ credential?.kind === "connected_subscription" ||
58
+ payer === "connected_subscription"
59
+ ) {
60
+ return "codex_subscription";
61
+ }
62
+ if (
63
+ source === "workspace_gateway" ||
64
+ credential?.kind === "workspace_connection" ||
65
+ payer === "workspace"
66
+ ) {
67
+ return "byok";
68
+ }
69
+ if (credential?.kind === "organization_connection" || payer === "organization") {
70
+ return "organization_byok";
71
+ }
72
+ return "opengeni_credits";
73
+ }
74
+
75
+ export function compareModelPickerOrder(
76
+ left: { billingClass: ModelPickerBillingClass; selectable: boolean; label: string },
77
+ right: { billingClass: ModelPickerBillingClass; selectable: boolean; label: string },
78
+ ): number {
79
+ const classDelta =
80
+ MODEL_PICKER_BILLING_CLASS_ORDER.indexOf(left.billingClass) -
81
+ MODEL_PICKER_BILLING_CLASS_ORDER.indexOf(right.billingClass);
82
+ return (
83
+ classDelta ||
84
+ +right.selectable - +left.selectable ||
85
+ (left.label < right.label ? -1 : left.label > right.label ? 1 : 0)
86
+ );
87
+ }
@@ -239,6 +239,26 @@ export const CreateOrganizationResponse = z.object({
239
239
  });
240
240
  export type CreateOrganizationResponse = z.infer<typeof CreateOrganizationResponse>;
241
241
 
242
+ export const CreateAdditionalOrganizationRequest = z
243
+ .object({
244
+ name: z.string().trim().min(1).max(120),
245
+ workspaceName: z.string().trim().min(1).max(120),
246
+ operationId: z.string().uuid(),
247
+ })
248
+ .strict();
249
+ export type CreateAdditionalOrganizationRequest = z.infer<
250
+ typeof CreateAdditionalOrganizationRequest
251
+ >;
252
+
253
+ export const CreateAdditionalOrganizationResponse = z.object({
254
+ organization: OrganizationSummary,
255
+ workspaceId: z.string().uuid(),
256
+ personalWorkspaceId: z.string().uuid(),
257
+ });
258
+ export type CreateAdditionalOrganizationResponse = z.infer<
259
+ typeof CreateAdditionalOrganizationResponse
260
+ >;
261
+
242
262
  export const UpdateOrganizationNameRequest = z.object({
243
263
  name: z.string().trim().min(1).max(120),
244
264
  expectedUpdatedAt: z.string().datetime({ offset: true }),
@@ -15,6 +15,14 @@ export const AUTOMATIC_SESSION_TITLE_MAX_GRAPHEMES = 80;
15
15
  */
16
16
  export const AUTOMATIC_SESSION_TITLE_FALLBACK = "New conversation";
17
17
 
18
+ // Session creation accepts a body far larger than a navigation label. Bound
19
+ // the source before any replace/split/normalization so a persisted large prompt
20
+ // cannot amplify memory or CPU on every client render.
21
+ const PROMPT_PREVIEW_SCAN_MAX_CODE_UNITS = 4_096;
22
+
23
+ const SESSION_ID_PATTERN =
24
+ /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/iu;
25
+
18
26
  let titleSegmenter: Intl.Segmenter | null | undefined;
19
27
 
20
28
  const KNOWN_SENSITIVE_VALUE_PATTERNS = [
@@ -329,3 +337,95 @@ export function normalizeAutomaticSessionTitle(value: string): string | null {
329
337
  if (!title || !hasVisibleAutomaticTitleContent(title)) return null;
330
338
  return title;
331
339
  }
340
+
341
+ export type SessionDisplayTitleInput = {
342
+ id?: string | null | undefined;
343
+ title?: string | null | undefined;
344
+ titleSource?: "user" | "agent" | null | undefined;
345
+ initialMessage?: string | null | undefined;
346
+ metadata?: Readonly<Record<string, unknown>> | undefined;
347
+ };
348
+
349
+ export type SessionDisplayTitleOptions = {
350
+ /** Optional metadata fields to try before the opening-prompt preview. */
351
+ metadataKeys?: readonly string[] | undefined;
352
+ };
353
+
354
+ /**
355
+ * Derive a bounded, sensitive-safe preview from the opening prompt.
356
+ *
357
+ * Unsafe leading lines are skipped instead of forcing the whole session back
358
+ * to a generic label. This covers prompts that begin with a pasted URL or
359
+ * identifier followed by an ordinary natural-language request on the next
360
+ * line, without putting the rejected value into navigation surfaces.
361
+ */
362
+ export function deriveAutomaticSessionTitlePreview(value: unknown): string | null {
363
+ if (typeof value !== "string") return null;
364
+
365
+ const lines = value
366
+ .slice(0, PROMPT_PREVIEW_SCAN_MAX_CODE_UNITS)
367
+ .replace(/[\u0000-\u001f\u007f-\u009f]+/gu, "\n")
368
+ .split(/\n+/u);
369
+
370
+ for (const candidate of lines) {
371
+ const line = candidate.trim();
372
+ if (!line || containsSensitiveAutomaticSessionTitleValue(line)) continue;
373
+
374
+ const preview = boundAutomaticSessionTitle(line.replace(/\s+/gu, " "))
375
+ .replace(/[\s.!?,;:\-–—]+$/u, "")
376
+ .trim();
377
+ if (preview) return preview;
378
+ }
379
+
380
+ return null;
381
+ }
382
+
383
+ function automaticSessionReferenceTitle(id: unknown): string {
384
+ const sessionId = typeof id === "string" ? id.trim() : "";
385
+ return SESSION_ID_PATTERN.test(sessionId)
386
+ ? `Conversation ${sessionId.slice(0, 13)}`
387
+ : AUTOMATIC_SESSION_TITLE_FALLBACK;
388
+ }
389
+
390
+ /**
391
+ * Whether the durable title still represents the automatic-title pending state.
392
+ * A user-authored title always wins, even when its literal value is the marker.
393
+ */
394
+ export function sessionTitleIsPending(input: SessionDisplayTitleInput): boolean {
395
+ const title = input.title?.trim() ?? "";
396
+ return input.titleSource !== "user" && (!title || title === AUTOMATIC_SESSION_TITLE_FALLBACK);
397
+ }
398
+
399
+ /**
400
+ * Derive the title a human-facing client should display for a session.
401
+ *
402
+ * A semantic agent title or human rename wins. While automatic naming is still
403
+ * pending, clients show a short, sensitive-safe preview of the opening prompt.
404
+ * If no safe prompt text exists, a UUID-derived reference keeps real sessions
405
+ * distinguishable without exposing prompt bytes. The durable pending marker is
406
+ * therefore an internal lifecycle value rather than the ordinary visible name.
407
+ */
408
+ export function deriveSessionDisplayTitle(
409
+ input: SessionDisplayTitleInput,
410
+ options: SessionDisplayTitleOptions = {},
411
+ ): string {
412
+ const title = input.title?.trim() ?? "";
413
+ if (input.titleSource === "user") {
414
+ return title || automaticSessionReferenceTitle(input.id);
415
+ }
416
+ if (title && !sessionTitleIsPending(input)) {
417
+ return title;
418
+ }
419
+
420
+ for (const key of options.metadataKeys ?? []) {
421
+ const value = input.metadata?.[key];
422
+ if (typeof value === "string" && value.trim().length > 0) {
423
+ return value.trim();
424
+ }
425
+ }
426
+
427
+ return (
428
+ deriveAutomaticSessionTitlePreview(input.initialMessage) ??
429
+ automaticSessionReferenceTitle(input.id)
430
+ );
431
+ }
@@ -4,8 +4,8 @@ export const WORKSPACE_LEARNING_POLICY_MAX_SOURCE_OVERRIDES = 256;
4
4
  export const WORKSPACE_LEARNING_POLICY_SOURCE_KIND_MAX_CHARS = 96;
5
5
  export const WORKSPACE_LEARNING_POLICY_SOURCE_ID_MAX_CHARS = 1_024;
6
6
  export const WORKSPACE_LEARNING_POLICY_REASON_MAX_CHARS = 4_096;
7
- export const WORKSPACE_LEARNING_POLICY_DEFAULT_OFF_REVISION_ID =
8
- "workspace-learning-policy:default-off:v1";
7
+ export const WORKSPACE_LEARNING_POLICY_DEFAULT_SUGGEST_REVISION_ID =
8
+ "workspace-learning-policy:default-suggest:v1";
9
9
 
10
10
  export const WorkspaceLearningMode = z.enum(["off", "suggest", "automatic"]);
11
11
  export type WorkspaceLearningMode = z.infer<typeof WorkspaceLearningMode>;
@@ -220,7 +220,8 @@ export function resolveWorkspaceLearningPolicyEffectiveMode(
220
220
  policyRevision: parsedSnapshot.revision,
221
221
  activationVersion: parsedSnapshot.activationVersion,
222
222
  snapshotId: parsedSnapshot.id,
223
- revisionId: parsedSnapshot.revision?.id ?? WORKSPACE_LEARNING_POLICY_DEFAULT_OFF_REVISION_ID,
223
+ revisionId:
224
+ parsedSnapshot.revision?.id ?? WORKSPACE_LEARNING_POLICY_DEFAULT_SUGGEST_REVISION_ID,
224
225
  snapshotHash: parsedSnapshot.snapshotHash,
225
226
  });
226
227
  }
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/session-titles.ts"],"sourcesContent":["/** Human-authored session titles keep the existing public API ceiling. */\nexport const SESSION_TITLE_MAX_CHARACTERS = 200;\n\n/**\n * Automatic titles are intentionally much shorter than the manual rename\n * ceiling. This is measured in grapheme clusters so emoji and combining text\n * are never split into malformed display strings.\n */\nexport const AUTOMATIC_SESSION_TITLE_MAX_GRAPHEMES = 80;\n\n/**\n * Safe durable title used until semantic generation succeeds. It contains no\n * user prompt bytes, so provider failure/offline operation cannot leak a\n * credential or leave a raw prompt prefix in navigation surfaces.\n */\nexport const AUTOMATIC_SESSION_TITLE_FALLBACK = \"New conversation\";\n\nlet titleSegmenter: Intl.Segmenter | null | undefined;\n\nconst KNOWN_SENSITIVE_VALUE_PATTERNS = [\n /-----BEGIN [A-Z ]*PRIVATE KEY-----/iu,\n /\\bBearer\\s+[A-Za-z0-9._~+/=-]{8,}/iu,\n /\\b(?:sk-(?:proj-)?|gh[oprsu]_|github_pat_|glpat-|xox[baprs]-)[A-Za-z0-9_-]{8,}/iu,\n /\\bAKIA[0-9A-Z]{16}\\b/u,\n /\\bAIza[0-9A-Za-z_-]{20,}\\b/u,\n /\\beyJ[A-Za-z0-9_-]+\\.eyJ[A-Za-z0-9_-]+\\.[A-Za-z0-9_-]+\\b/u,\n /[?&](?:access_token|api_key|apikey|password|secret|token)=[^\\s&#]+/iu,\n] as const;\n\nconst URI_SCHEME_CANDIDATE_PATTERN = /\\b[a-z][a-z0-9+.-]*:\\S+/giu;\nconst WINDOWS_DRIVE_PATH_PATTERN = /^[a-z]:[\\\\/](?![\\\\/])[^:]*$/iu;\n\nconst SCHEMELESS_HOST_CANDIDATE_PATTERN =\n /\\b(?:www\\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?(?::\\d{1,5})?(?:[/?#][^\\s]*)?/giu;\n\nconst SCHEMELESS_LOCAL_NETWORK_PATTERNS = [\n /\\blocalhost(?:(?::\\d{1,5})(?:[/?#][^\\s]*)?|[/?#][^\\s]*)/iu,\n /\\b(?:(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)\\.){3}(?:25[0-5]|2[0-4]\\d|1?\\d?\\d)(?:(?::\\d{1,5})(?:[/?#][^\\s]*)?|[/?#][^\\s]*)/u,\n /\\[(?=[0-9a-f:.]*:[0-9a-f:.]*\\])[0-9a-f:.]+\\](?:(?::\\d{1,5})(?:[/?#][^\\s]*)?|[/?#][^\\s]*)/iu,\n] as const;\n\nconst FILE_LIKE_HOST_SUFFIXES = new Set([\n \"css\",\n \"html\",\n \"js\",\n \"json\",\n \"jsx\",\n \"lock\",\n \"md\",\n \"sql\",\n \"toml\",\n \"ts\",\n \"tsx\",\n \"xml\",\n \"yaml\",\n \"yml\",\n]);\n\n// These authorities are established framework/namespace notation whose exact\n// casing is meaningful. Keep this exception deliberately narrow: generic\n// PascalCase or uppercase authorities remain host-like because an uppercase\n// real domain (for example MICROSOFT.COM/Admin) must not bypass the URL gate.\nconst DOTTED_TECHNOLOGY_PATH_AUTHORITIES = new Set([\n \"ASP.NET\",\n \"AWS.SDK\",\n \"Microsoft.Extensions\",\n \"System.IO\",\n]);\n\nconst SECRET_ASSIGNMENT_CANDIDATE_PATTERN =\n /(?:^|[^A-Za-z0-9])(?:(['\"])([A-Za-z][A-Za-z0-9_. -]*)\\1|([A-Za-z][A-Za-z0-9_.-]*))\\s*[=:]\\s*[^\\s,;]+/gu;\n\nconst SECRET_LABEL_ASSIGNMENT_PATTERN =\n /\\b(?:api[ _-]?key|access[ _-]?token|auth[ _-]?token|credential|credentials|password|passwd|private[ _-]?key|secret|token)\\b\\s*[=:]\\s*[^\\s,;]+/iu;\n\nconst SENSITIVE_ASSIGNMENT_KEY_SUFFIXES = new Set([\n \"credential\",\n \"credentials\",\n \"password\",\n \"passwd\",\n \"secret\",\n \"token\",\n]);\n\nconst COMPACT_SENSITIVE_ASSIGNMENT_KEY_SUFFIXES = [\n \"apikey\",\n \"accesskey\",\n \"accesskeyid\",\n \"accesstoken\",\n \"authtoken\",\n \"credential\",\n \"credentials\",\n \"password\",\n \"passwd\",\n \"privatekey\",\n \"secret\",\n \"secretkey\",\n \"token\",\n] as const;\n\nconst SENSITIVE_ASSIGNMENT_KEY_WORD_SUFFIXES = [\n [\"api\", \"key\"],\n [\"access\", \"key\"],\n [\"access\", \"key\", \"id\"],\n [\"auth\", \"key\"],\n [\"private\", \"key\"],\n [\"secret\", \"key\"],\n] as const;\n\nfunction hasWordSuffix(words: readonly string[], suffix: readonly string[]): boolean {\n if (words.length < suffix.length) return false;\n const offset = words.length - suffix.length;\n return suffix.every((word, index) => words[offset + index] === word);\n}\n\nfunction containsSensitiveAssignment(value: string): boolean {\n for (const match of value.matchAll(SECRET_ASSIGNMENT_CANDIDATE_PATTERN)) {\n const key = match[2] ?? match[3];\n if (!key) continue;\n const words = key\n .replace(/([a-z0-9])([A-Z])/g, \"$1 $2\")\n .replace(/([A-Z]+)([A-Z][a-z])/g, \"$1 $2\")\n .toLowerCase()\n .split(/[^a-z0-9]+/)\n .filter(Boolean);\n const last = words.at(-1);\n if (last && SENSITIVE_ASSIGNMENT_KEY_SUFFIXES.has(last)) return true;\n if (last && COMPACT_SENSITIVE_ASSIGNMENT_KEY_SUFFIXES.some((suffix) => last.endsWith(suffix))) {\n return true;\n }\n if (SENSITIVE_ASSIGNMENT_KEY_WORD_SUFFIXES.some((suffix) => hasWordSuffix(words, suffix))) {\n return true;\n }\n }\n return false;\n}\n\nfunction containsUriScheme(value: string): boolean {\n for (const match of value.matchAll(URI_SCHEME_CANDIDATE_PATTERN)) {\n // A Windows drive path is the one scheme-shaped token accepted here. Keep\n // the exception exact: one separator after the drive letter and no later\n // colon, so x://host and a nested scheme remain rejected.\n if (!WINDOWS_DRIVE_PATH_PATTERN.test(match[0])) return true;\n }\n return false;\n}\n\nfunction isDottedTechnologyPath(candidate: string): boolean {\n if (/[?:#]/u.test(candidate)) return false;\n const [authority, ...pathSegments] = candidate.split(\"/\");\n if (!authority || pathSegments.length === 0 || pathSegments.some((segment) => !segment)) {\n return false;\n }\n if (\n !DOTTED_TECHNOLOGY_PATH_AUTHORITIES.has(authority) ||\n pathSegments.some((segment) => !/^[A-Z][A-Za-z0-9_-]*$/u.test(segment))\n ) {\n return false;\n }\n return true;\n}\n\nfunction containsSchemelessUrl(value: string): boolean {\n if (SCHEMELESS_LOCAL_NETWORK_PATTERNS.some((pattern) => pattern.test(value))) return true;\n\n for (const match of value.matchAll(SCHEMELESS_HOST_CANDIDATE_PATTERN)) {\n const candidate = match[0];\n if (candidate.toLowerCase().startsWith(\"www.\")) return true;\n if (!/[/?#]/u.test(candidate)) continue;\n\n const authority = candidate.split(/[/?#]/u, 1)[0] ?? \"\";\n const hostname = authority.replace(/:\\d{1,5}$/u, \"\");\n const suffix = hostname.split(\".\").at(-1)?.toLowerCase();\n if (suffix && FILE_LIKE_HOST_SUFFIXES.has(suffix)) continue;\n if (isDottedTechnologyPath(candidate)) continue;\n return true;\n }\n return false;\n}\n\nconst OPAQUE_IDENTIFIER_PATTERN =\n /\\b(?=[A-Za-z0-9_-]{32,}\\b)(?=[A-Za-z0-9_-]*[A-Za-z])(?=[A-Za-z0-9_-]*\\d)[A-Za-z0-9_-]+\\b/u;\n\nconst DEFAULT_IGNORABLE_CODE_POINTS = /\\p{Default_Ignorable_Code_Point}+/gu;\nconst ESCAPED_QUOTE_DELIMITERS = /\\\\+(?=[\"'])/gu;\n\nconst TITLE_LABEL_PATTERN =\n /^(?:(?:suggested|generated|concise)\\s+)?(?:(?:session|chat|conversation|task)\\s+)?title\\s*[:\\-–—]\\s*/iu;\n\nconst LEADING_BOILERPLATE_PATTERNS = [\n /^(?:hi|hello|hey)(?:\\s+there)?\\s*[,!:.\\-–—]*\\s*/iu,\n /^(?:i\\s+(?:would\\s+like|want|need)\\s+you\\s+to|i['’]d\\s+like\\s+you\\s+to)\\s+/iu,\n /^(?:please\\s+)?(?:can|could|would|will)\\s+you\\s+/iu,\n /^(?:your|the)\\s+(?:task|job)\\s+is\\s+to\\s+/iu,\n /^(?:please\\s+)?help\\s+me\\s+(?:to\\s+)?/iu,\n /^please(?:\\s*[,!:.\\-–—]+\\s*|\\s+|$)/iu,\n] as const;\n\nfunction automaticTitleDetectionValue(value: string): string {\n // Detection uses a compatibility-normalized shadow value so fullwidth\n // punctuation/letters, invisible token splits, and serialized quote\n // delimiters cannot evade the policy.\n // The accepted title itself stays byte-for-byte in the user's language and\n // emoji form; this shadow is never returned or persisted.\n return value\n .normalize(\"NFKC\")\n .replace(DEFAULT_IGNORABLE_CODE_POINTS, \"\")\n .replace(ESCAPED_QUOTE_DELIMITERS, \"\");\n}\n\nfunction hasVisibleAutomaticTitleContent(value: string): boolean {\n return automaticTitleDetectionValue(value).trim().length > 0;\n}\n\n/**\n * Whether a bounded automatic-title candidate contains a credential, URL, or\n * opaque identifier that must stay out of navigation and other display-title\n * surfaces. Callers handling an unbounded source must bound it before invoking\n * this helper.\n */\nexport function containsSensitiveAutomaticSessionTitleValue(value: string): boolean {\n const detectionValue = automaticTitleDetectionValue(value);\n\n if (KNOWN_SENSITIVE_VALUE_PATTERNS.some((pattern) => pattern.test(detectionValue))) return true;\n if (containsUriScheme(detectionValue)) return true;\n if (containsSchemelessUrl(detectionValue)) return true;\n if (SECRET_LABEL_ASSIGNMENT_PATTERN.test(detectionValue)) return true;\n if (containsSensitiveAssignment(detectionValue)) return true;\n if (OPAQUE_IDENTIFIER_PATTERN.test(detectionValue)) return true;\n return false;\n}\n\nfunction stripAutomaticTitleBoilerplate(value: string): string {\n let title = value;\n for (let pass = 0; pass < 4; pass += 1) {\n const before = title;\n title = title\n .replace(/^(?:```[^\\n]*|[\\s#>*_`\"'“”‘’\\-–—]+)+/u, \"\")\n .replace(TITLE_LABEL_PATTERN, \"\");\n for (const pattern of LEADING_BOILERPLATE_PATTERNS) {\n title = title.replace(pattern, \"\");\n }\n title = title.trim();\n if (title === before) break;\n }\n return title;\n}\n\nfunction automaticTitleGraphemes(value: string): string[] {\n if (titleSegmenter === undefined) {\n titleSegmenter =\n typeof Intl.Segmenter === \"function\"\n ? new Intl.Segmenter(undefined, { granularity: \"grapheme\" })\n : null;\n }\n if (titleSegmenter) {\n return Array.from(titleSegmenter.segment(value), (part) => part.segment);\n }\n\n // Older embedded runtimes may not ship Intl.Segmenter. Preserve surrogate\n // pairs plus common combining/emoji sequences instead of failing module load\n // or slicing UTF-16 code units.\n const graphemes: string[] = [];\n for (const point of value) {\n const prior = graphemes.at(-1);\n if (\n prior &&\n (/^[\\p{Mark}\\u{FE0E}\\u{FE0F}\\p{Emoji_Modifier}]$/u.test(point) ||\n point === \"\\u200d\" ||\n prior.endsWith(\"\\u200d\"))\n ) {\n graphemes[graphemes.length - 1] = `${prior}${point}`;\n } else {\n graphemes.push(point);\n }\n }\n return graphemes;\n}\n\n/** Bound an already-normalized automatic-title candidate without splitting graphemes. */\nexport function boundAutomaticSessionTitle(value: string): string {\n const words = value.split(/\\s+/u);\n const wordBounded = words.length > 10 ? words.slice(0, 10).join(\" \") : value;\n const graphemes = automaticTitleGraphemes(wordBounded);\n if (graphemes.length <= AUTOMATIC_SESSION_TITLE_MAX_GRAPHEMES) return wordBounded;\n\n const prefix = graphemes.slice(0, AUTOMATIC_SESSION_TITLE_MAX_GRAPHEMES).join(\"\");\n const lastWhitespace = prefix.search(/\\s+\\S*$/u);\n return (lastWhitespace >= 16 ? prefix.slice(0, lastWhitespace) : prefix).trimEnd();\n}\n\n/**\n * Normalize a model/system-authored title before it reaches durable session\n * metadata. Human renames intentionally do not use this path.\n *\n * Returns null when the candidate is empty, only boilerplate, or appears to\n * contain a credential/opaque prompt value. Callers should retain the current\n * title (normally {@link AUTOMATIC_SESSION_TITLE_FALLBACK}) in that case.\n */\nexport function normalizeAutomaticSessionTitle(value: string): string | null {\n const firstLine = value\n .replace(/[\\u0000-\\u001f\\u007f-\\u009f]+/gu, \"\\n\")\n .split(/\\n+/u)\n .map((line) => line.trim())\n .find(Boolean);\n if (\n !firstLine ||\n !hasVisibleAutomaticTitleContent(firstLine) ||\n containsSensitiveAutomaticSessionTitleValue(firstLine)\n ) {\n return null;\n }\n\n let title = stripAutomaticTitleBoilerplate(firstLine)\n .replace(/\\s+/gu, \" \")\n .replace(/[\\s.!?,;:\\-–—]+$/u, \"\")\n .trim();\n if (\n !title ||\n !hasVisibleAutomaticTitleContent(title) ||\n containsSensitiveAutomaticSessionTitleValue(title)\n ) {\n return null;\n }\n\n title = boundAutomaticSessionTitle(title)\n .replace(/[\\s.!?,;:\\-–—]+$/u, \"\")\n .trim();\n if (!title || !hasVisibleAutomaticTitleContent(title)) return null;\n return title;\n}\n"],"mappings":";AACO,IAAM,+BAA+B;AAOrC,IAAM,wCAAwC;AAO9C,IAAM,mCAAmC;AAEhD,IAAI;AAEJ,IAAM,iCAAiC;AAAA,EACrC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,+BAA+B;AACrC,IAAM,6BAA6B;AAEnC,IAAM,oCACJ;AAEF,IAAM,oCAAoC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,0BAA0B,oBAAI,IAAI;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAMD,IAAM,qCAAqC,oBAAI,IAAI;AAAA,EACjD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,sCACJ;AAEF,IAAM,kCACJ;AAEF,IAAM,oCAAoC,oBAAI,IAAI;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,4CAA4C;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,IAAM,yCAAyC;AAAA,EAC7C,CAAC,OAAO,KAAK;AAAA,EACb,CAAC,UAAU,KAAK;AAAA,EAChB,CAAC,UAAU,OAAO,IAAI;AAAA,EACtB,CAA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