@builder.io/ai-utils 0.75.4 → 0.76.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/ai-utils",
3
- "version": "0.75.4",
3
+ "version": "0.76.0",
4
4
  "description": "Builder.io AI utils",
5
5
  "files": [
6
6
  "src"
package/src/claw.d.ts CHANGED
@@ -1,4 +1,16 @@
1
1
  import type { NewBranch, Project, MemorySummary } from "./projects";
2
+ import type { UserSource } from "./codegen";
3
+ /**
4
+ * Derives a human-readable sender name from a resolved UserSource.
5
+ * Prefers "Name <email>", falling back to name, email, then the platform user id.
6
+ */
7
+ export declare function formatUserSourceDisplayName(userSource: UserSource): string | undefined;
8
+ /**
9
+ * Extracts the Builder user id from any UserSource variant. For builder.io
10
+ * sources the `userId` already is the Builder user id; integration sources
11
+ * carry it as `builderUserId` (resolved by matching the external user).
12
+ */
13
+ export declare function getBuilderUserId(userSource: UserSource): string | undefined;
2
14
  export interface OrgTreeUser {
3
15
  userId: string;
4
16
  name?: string;
@@ -21,7 +33,10 @@ export interface OrgTreeMessage {
21
33
  channelId?: string;
22
34
  direction?: "incoming" | "outgoing";
23
35
  senderDisplayName?: string;
24
- senderId?: string;
36
+ /** Platform-native sender id (e.g. Slack/Telegram user id), not the Builder user. */
37
+ platformSenderId?: string;
38
+ /** Builder user id of the sender, when known. */
39
+ userId?: string;
25
40
  source?: string;
26
41
  channelType?: string;
27
42
  }
@@ -54,8 +69,44 @@ export interface ParsedChannelId {
54
69
  * "jira/comment/cloud-id/PROJ-123" → { platform: "jira", type: "comment", ids: ["cloud-id", "PROJ-123"] }
55
70
  * "builder/branch/proj-id/my-branch" → { platform: "builder", type: "branch", ids: ["proj-id", "my-branch"] }
56
71
  * "inbox/user/builder-user-id" → { platform: "inbox", type: "user", ids: ["builder-user-id"] }
72
+ * "inbox/user/builder-user-id/thread-id" → { platform: "inbox", type: "user", ids: ["builder-user-id", "thread-id"] }
73
+ * "inbox/channel/general" → { platform: "inbox", type: "channel", ids: ["general"] }
74
+ * "inbox/channel/general/thread-id" → { platform: "inbox", type: "channel", ids: ["general", "thread-id"] }
57
75
  */
58
76
  export declare function parseChannelId(channelId: string): ParsedChannelId;
77
+ /**
78
+ * Platforms the org-agent can send messages to. The `platform` segment of a
79
+ * channelId (e.g. `slack/thread/...`). This is the single source of truth —
80
+ * the typed dispatch and message logging derive their unions from here.
81
+ */
82
+ export declare const KNOWN_PLATFORMS: readonly ["slack", "jira", "telegram", "whatsapp", "builder", "inbox", "internal"];
83
+ export type KnownPlatform = (typeof KNOWN_PLATFORMS)[number];
84
+ export declare function isKnownPlatform(p: string): p is KnownPlatform;
85
+ /**
86
+ * Valid channel sub-types per platform — the `type` segment of a channelId
87
+ * (e.g. `slack/thread/...`). Declared `satisfies Record<KnownPlatform, ...>`
88
+ * so every platform must enumerate its types; the literal values drive the
89
+ * `ChannelType<P>` unions used by the dispatch handlers.
90
+ */
91
+ export declare const CHANNEL_TYPES: {
92
+ readonly slack: readonly ["thread", "channel", "dm"];
93
+ readonly jira: readonly ["comment"];
94
+ readonly telegram: readonly ["chat"];
95
+ readonly whatsapp: readonly ["chat"];
96
+ readonly builder: readonly ["branch"];
97
+ readonly inbox: readonly ["user", "channel"];
98
+ readonly internal: readonly ["support", "feedback"];
99
+ };
100
+ export type ChannelType<P extends KnownPlatform> = (typeof CHANNEL_TYPES)[P][number];
101
+ /** Union of every channel sub-type across all platforms. */
102
+ export type AnyChannelType = ChannelType<KnownPlatform>;
103
+ export declare function isChannelType<P extends KnownPlatform>(platform: P, type: string): type is ChannelType<P>;
104
+ /** Platform recorded on a logged message; "unknown" when the channelId fails to parse. */
105
+ export type ChannelSource = KnownPlatform | "unknown";
106
+ /** Channel sub-type recorded on a logged message; "unknown" when parsing fails. */
107
+ export type LoggedChannelType = AnyChannelType | "unknown";
108
+ /** Delivery status reported alongside an outbound org-agent message. */
109
+ export type SendMessageStatus = "starting" | "question" | "will-follow-up" | "done:success" | "done:error";
59
110
  /**
60
111
  * Converts a Builder channel_id URI to a clickable URL for the
61
112
  * corresponding platform (Slack, Jira, etc.).
@@ -111,8 +162,6 @@ export interface WorkerMessageOptions {
111
162
  export declare function formatWorkerReport(opts: WorkerReportOptions): string;
112
163
  export declare function formatWorkerMessage(opts: WorkerMessageOptions): string;
113
164
  export interface SystemMessageOptions {
114
- /** Identifier of the system sender (e.g. "cron:daily_check"). */
115
- senderId?: string;
116
165
  /** Human-readable display name (e.g. "Cron Job Trigger: daily_check"). */
117
166
  senderDisplayName?: string;
118
167
  /** Pre-formatted timestamp string. */
@@ -138,6 +187,8 @@ export interface IncomingMessageOptions {
138
187
  dmId?: string;
139
188
  /** Display name of the sender. */
140
189
  sender?: string;
190
+ /** Resolved Builder user id of the sender, when known. */
191
+ builderUserId?: string;
141
192
  /** Pre-formatted timestamp string. */
142
193
  timestamp: string;
143
194
  /** The message body. */
package/src/claw.js CHANGED
@@ -1,4 +1,31 @@
1
1
  // ── Org Tree types (shared between service endpoint and CLI) ──
2
+ /**
3
+ * Derives a human-readable sender name from a resolved UserSource.
4
+ * Prefers "Name <email>", falling back to name, email, then the platform user id.
5
+ */
6
+ export function formatUserSourceDisplayName(userSource) {
7
+ var _a, _b;
8
+ const name = (_a = userSource.userName) === null || _a === void 0 ? void 0 : _a.trim();
9
+ const email = "userEmail" in userSource ? (_b = userSource.userEmail) === null || _b === void 0 ? void 0 : _b.trim() : undefined;
10
+ if (name && email) {
11
+ return `${name} <${email}>`;
12
+ }
13
+ return name || email || userSource.userId || undefined;
14
+ }
15
+ /**
16
+ * Extracts the Builder user id from any UserSource variant. For builder.io
17
+ * sources the `userId` already is the Builder user id; integration sources
18
+ * carry it as `builderUserId` (resolved by matching the external user).
19
+ */
20
+ export function getBuilderUserId(userSource) {
21
+ if (userSource.source === "agent") {
22
+ return undefined;
23
+ }
24
+ if (userSource.source === "builder.io") {
25
+ return userSource.userId;
26
+ }
27
+ return userSource.builderUserId;
28
+ }
2
29
  /**
3
30
  * Parses a URI-style channelId into its components.
4
31
  *
@@ -7,6 +34,9 @@
7
34
  * "jira/comment/cloud-id/PROJ-123" → { platform: "jira", type: "comment", ids: ["cloud-id", "PROJ-123"] }
8
35
  * "builder/branch/proj-id/my-branch" → { platform: "builder", type: "branch", ids: ["proj-id", "my-branch"] }
9
36
  * "inbox/user/builder-user-id" → { platform: "inbox", type: "user", ids: ["builder-user-id"] }
37
+ * "inbox/user/builder-user-id/thread-id" → { platform: "inbox", type: "user", ids: ["builder-user-id", "thread-id"] }
38
+ * "inbox/channel/general" → { platform: "inbox", type: "channel", ids: ["general"] }
39
+ * "inbox/channel/general/thread-id" → { platform: "inbox", type: "channel", ids: ["general", "thread-id"] }
10
40
  */
11
41
  export function parseChannelId(channelId) {
12
42
  const parts = channelId.split("/");
@@ -16,6 +46,41 @@ export function parseChannelId(channelId) {
16
46
  const [platform, type, ...ids] = parts;
17
47
  return { platform, type, ids };
18
48
  }
49
+ /**
50
+ * Platforms the org-agent can send messages to. The `platform` segment of a
51
+ * channelId (e.g. `slack/thread/...`). This is the single source of truth —
52
+ * the typed dispatch and message logging derive their unions from here.
53
+ */
54
+ export const KNOWN_PLATFORMS = [
55
+ "slack",
56
+ "jira",
57
+ "telegram",
58
+ "whatsapp",
59
+ "builder",
60
+ "inbox",
61
+ "internal",
62
+ ];
63
+ export function isKnownPlatform(p) {
64
+ return KNOWN_PLATFORMS.includes(p);
65
+ }
66
+ /**
67
+ * Valid channel sub-types per platform — the `type` segment of a channelId
68
+ * (e.g. `slack/thread/...`). Declared `satisfies Record<KnownPlatform, ...>`
69
+ * so every platform must enumerate its types; the literal values drive the
70
+ * `ChannelType<P>` unions used by the dispatch handlers.
71
+ */
72
+ export const CHANNEL_TYPES = {
73
+ slack: ["thread", "channel", "dm"],
74
+ jira: ["comment"],
75
+ telegram: ["chat"],
76
+ whatsapp: ["chat"],
77
+ builder: ["branch"],
78
+ inbox: ["user", "channel"],
79
+ internal: ["support", "feedback"],
80
+ };
81
+ export function isChannelType(platform, type) {
82
+ return CHANNEL_TYPES[platform].includes(type);
83
+ }
19
84
  /**
20
85
  * Converts a Builder channel_id URI to a clickable URL for the
21
86
  * corresponding platform (Slack, Jira, etc.).
@@ -142,9 +207,6 @@ export function formatWorkerMessage(opts) {
142
207
  */
143
208
  export function formatSystemMessage(opts) {
144
209
  let xml = `<system_message>\n`;
145
- if (opts.senderId) {
146
- xml += `<sender_id>${opts.senderId}</sender_id>\n`;
147
- }
148
210
  if (opts.senderDisplayName) {
149
211
  xml += `<sender>${opts.senderDisplayName}</sender>\n`;
150
212
  }
@@ -181,6 +243,9 @@ export function formatIncomingMessage(opts) {
181
243
  if (opts.sender) {
182
244
  result += `<sender>${opts.sender}</sender>\n`;
183
245
  }
246
+ if (opts.builderUserId) {
247
+ result += `<builder_user_id>${opts.builderUserId}</builder_user_id>\n`;
248
+ }
184
249
  result += `<timestamp>${opts.timestamp}</timestamp>\n`;
185
250
  result += `<content>\n${opts.content.trim()}\n</content>\n`;
186
251
  result += `</incoming_message>\n`;
package/src/codegen.d.ts CHANGED
@@ -3060,6 +3060,8 @@ export interface GenerateCompletionStepDone {
3060
3060
  planPath: string | undefined;
3061
3061
  stopReason: CompletionStopReason;
3062
3062
  hasChanges: boolean;
3063
+ /** True when this turn was a compaction pass run on an internal model. */
3064
+ compact: boolean;
3063
3065
  }
3064
3066
  export interface GenerateCompletionStepFusionConfigPatch {
3065
3067
  type: "fusion-config-patch";
@@ -3738,6 +3740,8 @@ export interface GenerateCodeEventDone {
3738
3740
  autoContinue: boolean;
3739
3741
  model: string;
3740
3742
  promptVersion: string | undefined;
3743
+ /** True when this turn was a compaction pass run on an internal model. */
3744
+ compact: boolean;
3741
3745
  }
3742
3746
  export interface GenerateCodeEventError {
3743
3747
  type: "error";
package/src/events.d.ts CHANGED
@@ -758,7 +758,6 @@ export type ClawMessageSentV1 = FusionEventVariant<"claw.message.sent", {
758
758
  branchName: string;
759
759
  content: string;
760
760
  senderType: "user" | "sub-agent" | "system";
761
- senderId?: string;
762
761
  correlationId?: string;
763
762
  channelId?: string;
764
763
  /** Optional clickable URL for channelId. */
@@ -1022,7 +1021,6 @@ export interface SendMessageToOrgAgentInput {
1022
1021
  channelName?: string;
1023
1022
  senderDisplayName?: string;
1024
1023
  messageContext?: string;
1025
- senderId?: string;
1026
1024
  dmId?: string;
1027
1025
  userSource?: UserSource;
1028
1026
  attachments?: FileUpload[];
package/src/messages.d.ts CHANGED
@@ -172,6 +172,7 @@ export interface ContentMessageItemToolSearchToolResult {
172
172
  };
173
173
  cache?: boolean;
174
174
  }
175
+ export type ContentMessageItemFromTool = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemResource;
175
176
  export type ContentMessageItem = ContentMessageItemText | ContentMessageItemImage | ContentMessageItemResource | ContentMessageItemDocument | ContentMessageItemVideo | ContentMessageItemThinking | ContentMessageItemRedactedThinking | ContentMessageItemToolUse | ContentMessageItemToolResult | ContentMessageItemWebSearchToolResult | ContentMessageItemServerToolUse | ContentMessageItemMCPToolUse | ContentMessageItemMCPToolResult | ContentMessageItemContainerUpload | ContentMessageItemCodeExecutionToolResult | ContentMessageItemToolSearchToolResult;
176
177
  export type ContentMessage = ContentMessageItem[];
177
178
  export interface SystemMessageParam {
package/src/projects.d.ts CHANGED
@@ -1605,57 +1605,4 @@ export declare const GetDeploysResponseSchema: z.ZodObject<{
1605
1605
  }, z.core.$strip>>;
1606
1606
  }, z.core.$strip>;
1607
1607
  export type GetDeploysResponse = z.infer<typeof GetDeploysResponseSchema>;
1608
- export declare const UpdateHostingRequestSchema: z.ZodObject<{
1609
- projectId: z.ZodString;
1610
- customDomain: z.ZodOptional<z.ZodString>;
1611
- buildCommand: z.ZodOptional<z.ZodString>;
1612
- autoDeploy: z.ZodOptional<z.ZodBoolean>;
1613
- environment: z.ZodOptional<z.ZodObject<{
1614
- build: z.ZodOptional<z.ZodArray<z.ZodObject<{
1615
- key: z.ZodString;
1616
- value: z.ZodString;
1617
- isSecret: z.ZodBoolean;
1618
- placeholder: z.ZodOptional<z.ZodBoolean>;
1619
- explanation: z.ZodOptional<z.ZodString>;
1620
- }, z.core.$strip>>>;
1621
- prod: z.ZodOptional<z.ZodArray<z.ZodObject<{
1622
- key: z.ZodString;
1623
- value: z.ZodString;
1624
- isSecret: z.ZodBoolean;
1625
- placeholder: z.ZodOptional<z.ZodBoolean>;
1626
- explanation: z.ZodOptional<z.ZodString>;
1627
- }, z.core.$strip>>>;
1628
- }, z.core.$strip>>;
1629
- deleteEnvironmentVariableKeys: z.ZodOptional<z.ZodObject<{
1630
- build: z.ZodOptional<z.ZodArray<z.ZodString>>;
1631
- prod: z.ZodOptional<z.ZodArray<z.ZodString>>;
1632
- }, z.core.$strip>>;
1633
- }, z.core.$strip>;
1634
- export type UpdateHostingRequest = z.infer<typeof UpdateHostingRequestSchema>;
1635
- export declare const UpdateHostingResponseSchema: z.ZodObject<{
1636
- slug: z.ZodOptional<z.ZodString>;
1637
- customDomain: z.ZodOptional<z.ZodString>;
1638
- buildConfig: z.ZodOptional<z.ZodObject<{
1639
- buildCommand: z.ZodOptional<z.ZodString>;
1640
- buildOutputDir: z.ZodOptional<z.ZodString>;
1641
- nodeVersion: z.ZodOptional<z.ZodString>;
1642
- }, z.core.$strip>>;
1643
- environment: z.ZodOptional<z.ZodOptional<z.ZodObject<{
1644
- build: z.ZodOptional<z.ZodArray<z.ZodObject<{
1645
- key: z.ZodString;
1646
- value: z.ZodString;
1647
- isSecret: z.ZodBoolean;
1648
- placeholder: z.ZodOptional<z.ZodBoolean>;
1649
- explanation: z.ZodOptional<z.ZodString>;
1650
- }, z.core.$strip>>>;
1651
- prod: z.ZodOptional<z.ZodArray<z.ZodObject<{
1652
- key: z.ZodString;
1653
- value: z.ZodString;
1654
- isSecret: z.ZodBoolean;
1655
- placeholder: z.ZodOptional<z.ZodBoolean>;
1656
- explanation: z.ZodOptional<z.ZodString>;
1657
- }, z.core.$strip>>>;
1658
- }, z.core.$strip>>>;
1659
- }, z.core.$strip>;
1660
- export type UpdateHostingResponse = z.infer<typeof UpdateHostingResponseSchema>;
1661
1608
  export {};
package/src/projects.js CHANGED
@@ -507,27 +507,3 @@ export const GetDeploysRequestSchema = z.object({
507
507
  export const GetDeploysResponseSchema = z.object({
508
508
  deploys: z.array(DeployListItemSchema),
509
509
  });
510
- export const UpdateHostingRequestSchema = z.object({
511
- projectId: z.string(),
512
- customDomain: z.string().optional(),
513
- buildCommand: z.string().optional(),
514
- autoDeploy: z.boolean().optional(),
515
- environment: z
516
- .object({
517
- build: z.array(EnvironmentVariableSchema).optional(),
518
- prod: z.array(EnvironmentVariableSchema).optional(),
519
- })
520
- .optional(),
521
- deleteEnvironmentVariableKeys: z
522
- .object({
523
- build: z.array(z.string()).optional(),
524
- prod: z.array(z.string()).optional(),
525
- })
526
- .optional(),
527
- });
528
- export const UpdateHostingResponseSchema = z.object({
529
- slug: z.string().optional(),
530
- customDomain: z.string().optional(),
531
- buildConfig: ProjectHostingBuildConfigSchema.optional(),
532
- environment: ProjectHostingSchema.shape.environment.optional(),
533
- });