@agent-native/core 0.213.1 → 0.216.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 (169) hide show
  1. package/dist/action.js +54 -1
  2. package/dist/agent/actions/disconnect-chatgpt-subscription.js +5 -0
  3. package/dist/agent/actions/get-agentkit-capabilities.js +3 -3
  4. package/dist/agent/actions/manage-builder-connection.js +5 -0
  5. package/dist/agent/actions/manage-provider-key-policy.js +5 -0
  6. package/dist/agent/actions/manage-provider-models.js +5 -0
  7. package/dist/agent/actions/manage-service-providers.js +5 -0
  8. package/dist/agent/actions/select-chatgpt-subscription-account.js +5 -0
  9. package/dist/agent/context-xray/actions/context-evict.js +5 -0
  10. package/dist/agent/context-xray/actions/context-pin.js +5 -0
  11. package/dist/agent/context-xray/actions/context-report.js +5 -0
  12. package/dist/agent/context-xray/actions/context-restore.js +5 -0
  13. package/dist/agent/execution-fence.d.ts +1 -0
  14. package/dist/agent/execution-fence.js +5 -0
  15. package/dist/agent/production-agent.d.ts +35 -2
  16. package/dist/agent/production-agent.js +629 -32
  17. package/dist/agent/run-manager.d.ts +2 -0
  18. package/dist/agent/run-manager.js +397 -115
  19. package/dist/agent/run-slot-lock.d.ts +2 -0
  20. package/dist/agent/run-slot-lock.js +6 -0
  21. package/dist/agent/run-store.d.ts +5 -0
  22. package/dist/agent/run-store.js +423 -156
  23. package/dist/agent/thread-data-builder.js +27 -5
  24. package/dist/agent/types.d.ts +6 -12
  25. package/dist/agentkit/capabilities.d.ts +1 -1
  26. package/dist/appearance/actions/get-theme-family.d.ts +8 -0
  27. package/dist/appearance/actions/get-theme-family.js +38 -0
  28. package/dist/appearance/actions/set-theme-family.d.ts +7 -0
  29. package/dist/appearance/actions/set-theme-family.js +33 -0
  30. package/dist/appearance/theme-family.d.ts +13 -0
  31. package/dist/appearance/theme-family.js +38 -0
  32. package/dist/application-state/store.d.ts +5 -0
  33. package/dist/application-state/store.js +26 -0
  34. package/dist/chat-threads/schema-migrations.js +17 -0
  35. package/dist/chat-threads/store.d.ts +21 -1
  36. package/dist/chat-threads/store.js +223 -41
  37. package/dist/cli/skills-content/turn-into-app-skill.d.ts +1 -1
  38. package/dist/cli/skills-content/turn-into-app-skill.js +20 -18
  39. package/dist/cli/templates-meta.js +14 -0
  40. package/dist/client/analytics.js +167 -17
  41. package/dist/client/chat/agentkit-agent-native.js +79 -3
  42. package/dist/client/chat/agentkit-protocol.js +80 -42
  43. package/dist/client/chat/runtime.d.ts +5 -1
  44. package/dist/client/chat/runtime.js +46 -3
  45. package/dist/client/consent.d.ts +36 -0
  46. package/dist/client/consent.js +283 -0
  47. package/dist/client/review/use-review.d.ts +2 -0
  48. package/dist/client/review/use-review.js +28 -1
  49. package/dist/client/sharing/useResourceAccessGate.d.ts +3 -2
  50. package/dist/client/sharing/useResourceAccessGate.js +9 -1
  51. package/dist/client/theme-family.d.ts +35 -0
  52. package/dist/client/theme-family.js +223 -0
  53. package/dist/client/theme.d.ts +1 -1
  54. package/dist/client/theme.js +5 -2
  55. package/dist/client/ui/index.d.ts +1 -0
  56. package/dist/client/ui/index.js +1 -0
  57. package/dist/client/use-chat-thread-list.d.ts +2 -0
  58. package/dist/client/use-chat-thread-list.js +12 -2
  59. package/dist/client/use-chat-threads.d.ts +1 -0
  60. package/dist/client/use-chat-threads.js +2 -0
  61. package/dist/connections/catalog.d.ts +5 -5
  62. package/dist/connections/catalog.js +22 -3
  63. package/dist/data-widgets/index.d.ts +374 -5
  64. package/dist/data-widgets/index.js +242 -11
  65. package/dist/db/migrations.js +4 -1
  66. package/dist/db/schema-snapshot.generated.js +8 -1
  67. package/dist/feature-flags/actions/set-feature-flag.js +5 -0
  68. package/dist/feature-flags/index.d.ts +1 -1
  69. package/dist/feature-flags/index.js +1 -1
  70. package/dist/feature-flags/store.d.ts +12 -0
  71. package/dist/feature-flags/store.js +79 -7
  72. package/dist/file-upload/actions/manage-file-storage.js +5 -0
  73. package/dist/file-upload/actions/upload-image.js +5 -0
  74. package/dist/framework-tools.js +2 -0
  75. package/dist/history/actions/create-resource-version.js +5 -0
  76. package/dist/history/actions/restore-resource-version.js +5 -0
  77. package/dist/ingestion/index.d.ts +1 -1
  78. package/dist/ingestion/index.js +1 -1
  79. package/dist/ingestion/pptx.d.ts +11 -0
  80. package/dist/ingestion/pptx.js +81 -1
  81. package/dist/integrations/actions/manage-messaging-channel.js +5 -0
  82. package/dist/jobs/scheduler.js +17 -1
  83. package/dist/labs/actions/set-lab.js +5 -0
  84. package/dist/localization/actions/set-localization-preference.js +5 -0
  85. package/dist/mcp/screen-memory-stdio.d.ts +7 -7
  86. package/dist/observability/actions/save-observability-instruction-update.js +5 -0
  87. package/dist/observability/actions/save-observability-review-summary.js +5 -0
  88. package/dist/provider-api/actions/custom-provider-registration.d.ts +19 -19
  89. package/dist/provider-api/actions/provider-api.d.ts +10 -10
  90. package/dist/provider-api/index.js +9 -2
  91. package/dist/review/actions/consume-review-feedback.js +5 -0
  92. package/dist/review/actions/create-review-comment.js +5 -0
  93. package/dist/review/actions/delete-review-comment.js +5 -0
  94. package/dist/review/actions/react-to-review-comment.js +5 -0
  95. package/dist/review/actions/reply-review-comment.js +5 -0
  96. package/dist/review/actions/resolve-review-thread.js +5 -0
  97. package/dist/review/actions/send-review-thread-to-agent.js +5 -0
  98. package/dist/review/actions/set-review-status.js +5 -0
  99. package/dist/review/actions/set-review-thread-muted.js +5 -0
  100. package/dist/review/actions/set-review-thread-unread.js +5 -0
  101. package/dist/review/actions/set-review-threads-unread.js +5 -0
  102. package/dist/review/actions/update-review-comment-anchor.js +5 -0
  103. package/dist/review/actions/update-review-comment.js +5 -0
  104. package/dist/review/suggestions/actions.js +60 -21
  105. package/dist/review/suggestions/store.d.ts +2 -0
  106. package/dist/review/suggestions/store.js +28 -0
  107. package/dist/secrets/actions/delete-api-key.js +5 -0
  108. package/dist/secrets/routes.d.ts +10 -10
  109. package/dist/server/action-discovery.js +8 -0
  110. package/dist/server/agent-chat/context-tools.js +105 -2
  111. package/dist/server/agent-chat-plugin.d.ts +2 -0
  112. package/dist/server/agent-chat-plugin.js +242 -54
  113. package/dist/server/agent-engine-default-model-route.d.ts +1 -1
  114. package/dist/server/agent-engine-ollama-models-route.d.ts +1 -1
  115. package/dist/server/application-state-maintenance.d.ts +2 -0
  116. package/dist/server/application-state-maintenance.js +2 -0
  117. package/dist/server/attribution.d.ts +14 -0
  118. package/dist/server/attribution.js +62 -2
  119. package/dist/server/auth.js +7 -0
  120. package/dist/server/consent-route.d.ts +41 -0
  121. package/dist/server/consent-route.js +102 -0
  122. package/dist/server/first-touch-route.d.ts +39 -0
  123. package/dist/server/first-touch-route.js +115 -0
  124. package/dist/server/index.d.ts +1 -0
  125. package/dist/server/index.js +1 -0
  126. package/dist/server/queued-submission-inbox-drain.d.ts +9 -0
  127. package/dist/server/queued-submission-inbox-drain.js +12 -0
  128. package/dist/server/request-origin.d.ts +6 -0
  129. package/dist/server/request-origin.js +12 -0
  130. package/dist/settings/org-settings.d.ts +2 -1
  131. package/dist/settings/org-settings.js +4 -1
  132. package/dist/settings/store.d.ts +8 -0
  133. package/dist/settings/store.js +14 -5
  134. package/dist/shared/consent.d.ts +31 -0
  135. package/dist/shared/consent.js +145 -0
  136. package/dist/shared/first-touch-persistence.d.ts +31 -0
  137. package/dist/shared/first-touch-persistence.js +53 -0
  138. package/dist/sharing/actions/list-resource-shares.d.ts +1 -1
  139. package/dist/sharing/actions/set-resource-visibility.js +5 -0
  140. package/dist/sharing/actions/share-resource.js +5 -0
  141. package/dist/sharing/actions/unshare-resource.js +5 -0
  142. package/dist/templates/chat/.agents/skills/actions/references/action-fields.md +1 -1
  143. package/dist/templates/default/.agents/skills/actions/references/action-fields.md +1 -1
  144. package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +36 -80
  145. package/dist/templates/factory/.agents/skills/review-latest-feedback/references/channel-inventory.md +54 -16
  146. package/dist/templates/factory/.agents/skills/review-latest-feedback/references/slack-reaction-replies.md +50 -73
  147. package/dist/templates/headless/.agents/skills/actions/references/action-fields.md +1 -1
  148. package/dist/templates/workspace-core/.agents/skills/actions/references/action-fields.md +1 -1
  149. package/dist/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +20 -18
  150. package/dist/usage/actions/get-usage-metrics.js +27 -4
  151. package/dist/usage/actions/manage-usage-alert.js +5 -0
  152. package/dist/vite/client.js +8 -6
  153. package/dist/workspace-connections/actions/bulk-update-workspace-user-groups.js +5 -0
  154. package/dist/workspace-connections/actions/delete-workspace-user-group.js +5 -0
  155. package/dist/workspace-connections/actions/upsert-workspace-user-group.js +5 -0
  156. package/docs/content/actions-access-control.mdx +8 -8
  157. package/docs/content/actions-defining.mdx +9 -8
  158. package/docs/content/template-design-developers.mdx +9 -9
  159. package/docs/content/template-design-features.mdx +1 -3
  160. package/docs/content/turn-into-app.mdx +4 -0
  161. package/package.json +4 -3
  162. package/src/templates/chat/.agents/skills/actions/references/action-fields.md +1 -1
  163. package/src/templates/default/.agents/skills/actions/references/action-fields.md +1 -1
  164. package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +36 -80
  165. package/src/templates/factory/.agents/skills/review-latest-feedback/references/channel-inventory.md +54 -16
  166. package/src/templates/factory/.agents/skills/review-latest-feedback/references/slack-reaction-replies.md +50 -73
  167. package/src/templates/headless/.agents/skills/actions/references/action-fields.md +1 -1
  168. package/src/templates/workspace-core/.agents/skills/actions/references/action-fields.md +1 -1
  169. package/src/templates/workspace-core/.agents/skills/turn-into-app/SKILL.md +20 -18
@@ -1329,6 +1329,22 @@ export function claimQueuedMessage(repo, messageId) {
1329
1329
  normalized[CLAIMED_QUEUED_MESSAGE_IDS_KEY] = [...claimed, messageId].slice(-MAX_CLAIMED_QUEUED_MESSAGE_IDS);
1330
1330
  return pruneClaimedQueuedMessages(normalized);
1331
1331
  }
1332
+ function reconcileDirectSubmissionQueue(repo, userCustom) {
1333
+ if (!userCustom ||
1334
+ typeof userCustom !== "object" ||
1335
+ Array.isArray(userCustom)) {
1336
+ return repo;
1337
+ }
1338
+ const messageId = userCustom.agentKitMessageId;
1339
+ if (typeof messageId !== "string" ||
1340
+ !Array.isArray(repo?.queuedMessages) ||
1341
+ !repo.queuedMessages.some((message) => message &&
1342
+ typeof message === "object" &&
1343
+ message.id === messageId)) {
1344
+ return repo;
1345
+ }
1346
+ return claimQueuedMessage(repo, messageId);
1347
+ }
1332
1348
  export function applySubmittedUserMessage(repo, userMessage, queuedMessage) {
1333
1349
  const userCustom = userMessage.metadata.custom;
1334
1350
  const wasSubmitted = queuedMessage && Array.isArray(repo?.messages)
@@ -1370,7 +1386,10 @@ export function applySubmittedUserMessage(repo, userMessage, queuedMessage) {
1370
1386
  custom.submittedRunId === submittedRunId);
1371
1387
  });
1372
1388
  if (wasDirectlySubmitted) {
1373
- return { status: "already_submitted", repo };
1389
+ return {
1390
+ status: "already_submitted",
1391
+ repo: reconcileDirectSubmissionQueue(repo, userCustom),
1392
+ };
1374
1393
  }
1375
1394
  if (userCustom &&
1376
1395
  Object.prototype.hasOwnProperty.call(userCustom, AGENT_NATIVE_SUBMISSION_EXPIRES_AT_METADATA_KEY)) {
@@ -1382,7 +1401,10 @@ export function applySubmittedUserMessage(repo, userMessage, queuedMessage) {
1382
1401
  }
1383
1402
  }
1384
1403
  if (!queuedMessage) {
1385
- return { status: "submitted", repo: upsertUserMessage(repo, userMessage) };
1404
+ return {
1405
+ status: "submitted",
1406
+ repo: upsertUserMessage(reconcileDirectSubmissionQueue(repo, userCustom), userMessage),
1407
+ };
1386
1408
  }
1387
1409
  if (hasClaimedQueuedMessage(repo, queuedMessage.id)) {
1388
1410
  return { status: "already_claimed" };
@@ -2978,9 +3000,9 @@ export function mergeThreadDataForClientSave(existingRepo, incomingRepo, options
2978
3000
  }
2979
3001
  }
2980
3002
  }
2981
- // Queue mutations are the only writer of the queue and opt out here. Any
2982
- // other save carries a queue it read earlier, and letting that copy win drops
2983
- // a promotion claim or an append that landed in between.
3003
+ // Queue mutations own the queue; a submitted-message marker can remove its
3004
+ // matching row. Other saves carry a queue they read earlier, and letting
3005
+ // that copy win drops a promotion claim or an append that landed in between.
2984
3006
  if (preserveExistingQueuedMessages) {
2985
3007
  if (existingNormalized?.queuedMessages !== undefined) {
2986
3008
  merged.queuedMessages = existingNormalized.queuedMessages;
@@ -1,4 +1,4 @@
1
- import type { AgentSubmissionPayload, AgentSuggestion } from "@agent-native/agentkit/protocol";
1
+ import type { AgentSubmissionReference, AgentSubmissionPayload, AgentRunOptions, AgentSuggestion } from "@agent-native/agentkit/protocol";
2
2
  import type { A2AAgentActivitySnapshot } from "../a2a/activity.js";
3
3
  import type { ActionChatUIConfig } from "../action-ui.js";
4
4
  import type { WriteReceipt } from "../action.js";
@@ -84,17 +84,7 @@ export interface AgentChatStructuredMessage {
84
84
  role: "user" | "assistant";
85
85
  content: AgentChatStructuredContentPart[];
86
86
  }
87
- export interface AgentChatReference {
88
- type: "file" | "skill" | "mention" | "agent" | "custom-agent";
89
- path: string;
90
- name: string;
91
- source: string;
92
- refType?: string;
93
- refId?: string;
94
- slotKey?: string;
95
- slotLabel?: string;
96
- metadata?: Record<string, unknown>;
97
- }
87
+ export type AgentChatReference = AgentSubmissionReference;
98
88
  export type MentionItemMedia = {
99
89
  type: "text";
100
90
  text: string;
@@ -144,6 +134,8 @@ export interface MentionProvider {
144
134
  export interface AgentChatAttachment {
145
135
  type: string;
146
136
  name: string;
137
+ id?: string;
138
+ mediaType?: string;
147
139
  displayOnly?: boolean;
148
140
  data?: string;
149
141
  url?: string;
@@ -153,6 +145,7 @@ export interface AgentChatAttachment {
153
145
  storageRequired?: boolean;
154
146
  storageUploadFailed?: boolean;
155
147
  contentType?: string;
148
+ referenceUrl?: string;
156
149
  text?: string;
157
150
  }
158
151
  export interface AgentChatScope {
@@ -169,6 +162,7 @@ export interface AgentChatRequest {
169
162
  agentKitMessageId?: string;
170
163
  /** Original queue-shaped submit used for idempotent direct/queued admission. */
171
164
  submissionPayload?: AgentSubmissionPayload;
165
+ options?: AgentRunOptions;
172
166
  actionScope?: AgentActionScope;
173
167
  queuedMessageId?: string;
174
168
  queuedMessageClaimId?: string;
@@ -1,5 +1,5 @@
1
1
  import type { CredentialContext } from "../credentials/index.js";
2
- export type AgentKitCapabilityAppId = "design" | "slides";
2
+ export type AgentKitCapabilityAppId = "design" | "slides" | "slides-2";
3
3
  export interface AgentKitIntegrationCapability {
4
4
  id: string;
5
5
  label: string;
@@ -0,0 +1,8 @@
1
+ import { type ThemeFamily } from "../theme-family.js";
2
+ export interface ThemeFamilyPreference {
3
+ family: ThemeFamily;
4
+ source: "default" | "user-setting";
5
+ appId: string | null;
6
+ }
7
+ declare const _default: import("../../action.js").ActionDefinition<Record<string, never>, ThemeFamilyPreference>;
8
+ export default _default;
@@ -0,0 +1,38 @@
1
+ import { z } from "zod";
2
+ import { defineAction, fail } from "../../action.js";
3
+ import { getUserSetting } from "../../settings/user-settings.js";
4
+ import { DEFAULT_THEME_FAMILY, THEME_FAMILIES, themeFamilySettingKey, } from "../theme-family.js";
5
+ export default defineAction({
6
+ description: "Read the current app's saved theme family, which is independent of light or dark color mode.",
7
+ schema: z.object({}),
8
+ http: { method: "GET" },
9
+ readOnly: true,
10
+ agentTool: false,
11
+ run: async (_args, ctx) => {
12
+ const email = ctx?.userEmail;
13
+ if (!email)
14
+ fail("Not authenticated.", { statusCode: 401 });
15
+ const stored = await getUserSetting(email, themeFamilySettingKey(ctx?.appId));
16
+ if (stored === null) {
17
+ return {
18
+ family: DEFAULT_THEME_FAMILY,
19
+ source: "default",
20
+ appId: ctx?.appId ?? null,
21
+ };
22
+ }
23
+ const parsed = z
24
+ .object({ family: z.enum(THEME_FAMILIES) })
25
+ .safeParse(stored);
26
+ if (!parsed.success) {
27
+ fail("The saved theme family setting is invalid and could not be read.", {
28
+ errorCode: "theme_family_setting_invalid",
29
+ statusCode: 500,
30
+ });
31
+ }
32
+ return {
33
+ family: parsed.data.family,
34
+ source: "user-setting",
35
+ appId: ctx?.appId ?? null,
36
+ };
37
+ },
38
+ });
@@ -0,0 +1,7 @@
1
+ declare const _default: import("../../action.js").ActionDefinition<{
2
+ family: "agent-native" | "original";
3
+ }, {
4
+ family: "agent-native" | "original";
5
+ appId: string;
6
+ }>;
7
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { z } from "zod";
2
+ import { defineAction, fail } from "../../action.js";
3
+ import { writeAppState } from "../../application-state/script-helpers.js";
4
+ import { putUserSetting } from "../../settings/user-settings.js";
5
+ import { THEME_FAMILIES, themeFamilyAppStateKey, themeFamilySettingKey, } from "../theme-family.js";
6
+ export default defineAction({
7
+ description: "Set the current app's theme family to agent-native or original. This is separate from light or dark color mode.",
8
+ schema: z.object({
9
+ family: z
10
+ .enum(THEME_FAMILIES)
11
+ .describe("Theme family: agent-native or original."),
12
+ }),
13
+ http: { method: "POST" },
14
+ mcpAnnotations: {
15
+ readOnlyHint: false,
16
+ destructiveHint: false,
17
+ openWorldHint: false,
18
+ },
19
+ run: async ({ family }, ctx) => {
20
+ const email = ctx?.userEmail;
21
+ if (!email)
22
+ fail("Not authenticated.", { statusCode: 401 });
23
+ const settingKey = themeFamilySettingKey(ctx?.appId);
24
+ await putUserSetting(email, settingKey, { family });
25
+ try {
26
+ await writeAppState(themeFamilyAppStateKey(ctx?.appId), { family });
27
+ }
28
+ catch {
29
+ fail("The theme family was saved, but the open app could not be synchronized.", { errorCode: "theme_family_sync_failed", statusCode: 503 });
30
+ }
31
+ return { family, appId: ctx?.appId ?? null };
32
+ },
33
+ });
@@ -0,0 +1,13 @@
1
+ export declare const THEME_FAMILIES: readonly ["agent-native", "original"];
2
+ export type ThemeFamily = (typeof THEME_FAMILIES)[number];
3
+ export declare const DEFAULT_THEME_FAMILY: ThemeFamily;
4
+ export declare const THEME_FAMILY_STORAGE_KEY = "theme-family";
5
+ export declare const THEME_FAMILY_ATTRIBUTE = "data-theme-family";
6
+ export declare const THEME_FAMILY_STATUS_ATTRIBUTE = "data-theme-family-status";
7
+ export declare const THEME_FAMILY_APP_STATE_KEY = "theme-family";
8
+ export declare const THEME_FAMILY_SETTING_PREFIX = "theme-family";
9
+ export declare function isThemeFamily(value: unknown): value is ThemeFamily;
10
+ export declare function themeFamilySettingKey(appId?: string): string;
11
+ export declare function themeFamilyStorageKey(appId?: string): string;
12
+ export declare function themeFamilyAppStateKey(appId?: string): string;
13
+ export declare function getThemeFamilyInitScript(appId?: string | null): string;
@@ -0,0 +1,38 @@
1
+ export const THEME_FAMILIES = ["agent-native", "original"];
2
+ export const DEFAULT_THEME_FAMILY = "original";
3
+ export const THEME_FAMILY_STORAGE_KEY = "theme-family";
4
+ export const THEME_FAMILY_ATTRIBUTE = "data-theme-family";
5
+ export const THEME_FAMILY_STATUS_ATTRIBUTE = "data-theme-family-status";
6
+ export const THEME_FAMILY_APP_STATE_KEY = "theme-family";
7
+ export const THEME_FAMILY_SETTING_PREFIX = "theme-family";
8
+ export function isThemeFamily(value) {
9
+ return value === "agent-native" || value === "original";
10
+ }
11
+ export function themeFamilySettingKey(appId) {
12
+ // Older or standalone action contexts can genuinely omit appId. Keep their
13
+ // setting isolated under one stable fallback rather than borrowing another app's choice.
14
+ if (appId === undefined)
15
+ return `${THEME_FAMILY_SETTING_PREFIX}:__no_app_id__`;
16
+ const normalizedAppId = appId.trim().toLowerCase();
17
+ if (!normalizedAppId) {
18
+ throw new TypeError("Theme family settings require a non-empty appId.");
19
+ }
20
+ return `${THEME_FAMILY_SETTING_PREFIX}:${encodeURIComponent(normalizedAppId)}`;
21
+ }
22
+ export function themeFamilyStorageKey(appId) {
23
+ return themeFamilySettingKey(appId);
24
+ }
25
+ export function themeFamilyAppStateKey(appId) {
26
+ if (appId === undefined)
27
+ return `${THEME_FAMILY_APP_STATE_KEY}:__no_app_id__`;
28
+ const normalizedAppId = appId.trim().toLowerCase();
29
+ if (!normalizedAppId) {
30
+ throw new TypeError("Theme family application state requires a non-empty appId.");
31
+ }
32
+ const encodedAppId = Array.from(normalizedAppId, (character) => character.codePointAt(0).toString(16)).join("_");
33
+ return `${THEME_FAMILY_APP_STATE_KEY}:${encodedAppId}`;
34
+ }
35
+ export function getThemeFamilyInitScript(appId) {
36
+ const storageKey = themeFamilyStorageKey(appId ?? undefined);
37
+ return `(function(){var root=document.documentElement;var fallback=${JSON.stringify(DEFAULT_THEME_FAMILY)};try{var value=window.localStorage.getItem(${JSON.stringify(storageKey)});if(value===null){root.setAttribute(${JSON.stringify(THEME_FAMILY_ATTRIBUTE)},fallback);root.setAttribute(${JSON.stringify(THEME_FAMILY_STATUS_ATTRIBUTE)},'awaiting-app-setting');return}if(value==='agent-native'||value==='original'){root.setAttribute(${JSON.stringify(THEME_FAMILY_ATTRIBUTE)},value);root.removeAttribute(${JSON.stringify(THEME_FAMILY_STATUS_ATTRIBUTE)});return}root.setAttribute(${JSON.stringify(THEME_FAMILY_ATTRIBUTE)},fallback);root.setAttribute(${JSON.stringify(THEME_FAMILY_STATUS_ATTRIBUTE)},'invalid')}catch(e){root.setAttribute(${JSON.stringify(THEME_FAMILY_ATTRIBUTE)},fallback);root.setAttribute(${JSON.stringify(THEME_FAMILY_STATUS_ATTRIBUTE)},'unreadable')}})();`;
38
+ }
@@ -25,4 +25,9 @@ export declare function appStateListByKeyPrefix(keyPrefix: string, limit?: numbe
25
25
  key: string;
26
26
  value: Record<string, unknown>;
27
27
  }>>;
28
+ /** Lists metadata for maintenance keys within the current app namespace. */
29
+ export declare function appStateListKeysByKeySuffixPrefix(suffixPrefix: string, limit?: number): Promise<Array<{
30
+ sessionId: string;
31
+ key: string;
32
+ }>>;
28
33
  export declare function appStateDeleteByPrefix(sessionId: string, keyPrefix: string, options?: StoreWriteOptions): Promise<number>;
@@ -1,3 +1,4 @@
1
+ import { getAppConfig } from "../app-config/index.js";
1
2
  import { getDbExec, isLocalDatabase } from "../db/client.js";
2
3
  import { ensureIndexExists, ensureTableExists } from "../db/ddl-guard.js";
3
4
  import { defineStore } from "../db/store-registry.js";
@@ -227,6 +228,31 @@ export async function appStateListByKeyPrefix(keyPrefix, limit = 100) {
227
228
  value: JSON.parse(row.value),
228
229
  }));
229
230
  }
231
+ /** Lists metadata for maintenance keys within the current app namespace. */
232
+ export async function appStateListKeysByKeySuffixPrefix(suffixPrefix, limit = 100) {
233
+ if (!suffixPrefix || suffixPrefix.startsWith(":")) {
234
+ throw new Error("Cross-session application-state scans require a non-empty key suffix prefix.");
235
+ }
236
+ const keyPrefix = `${getAppStateMaintenanceNamespacePrefix()}${suffixPrefix}`;
237
+ await ensureTable();
238
+ const client = getDbExec();
239
+ const boundedLimit = Math.max(1, Math.min(Math.floor(limit), 2_048));
240
+ const { rows } = await client.execute({
241
+ sql: `SELECT session_id, key FROM application_state WHERE key LIKE ? ESCAPE '!' ORDER BY updated_at ASC LIMIT ?`,
242
+ args: [escapeLike(keyPrefix) + "%", boundedLimit],
243
+ });
244
+ return rows.map((row) => ({
245
+ sessionId: row.session_id,
246
+ key: row.key,
247
+ }));
248
+ }
249
+ function getAppStateMaintenanceNamespacePrefix() {
250
+ const namespace = getAppConfig().app.slug;
251
+ if (!namespace || namespace !== namespace.trim() || namespace.includes(":")) {
252
+ throw new Error("Application-state maintenance requires a configured app namespace.");
253
+ }
254
+ return `${namespace}:`;
255
+ }
230
256
  export async function appStateDeleteByPrefix(sessionId, keyPrefix, options) {
231
257
  await ensureTable();
232
258
  const client = getDbExec();
@@ -109,4 +109,21 @@ export const CHAT_THREAD_SCHEMA_MIGRATIONS = [
109
109
  ADD COLUMN IF NOT EXISTS interrupt_run_id TEXT
110
110
  `,
111
111
  },
112
+ {
113
+ version: 7,
114
+ name: "chat-thread-inbox-thread-order-index",
115
+ sql: `
116
+ CREATE INDEX IF NOT EXISTS agent_chat_submission_inbox_thread_pending_idx
117
+ ON agent_chat_submission_inbox (thread_id, interrupt_active_run DESC, move_to_top_at DESC, queue_order ASC)
118
+ WHERE state = 'queued'
119
+ `,
120
+ },
121
+ {
122
+ version: 8,
123
+ name: "chat-thread-inbox-retry-count",
124
+ sql: `
125
+ ALTER TABLE agent_chat_submission_inbox
126
+ ADD COLUMN IF NOT EXISTS retry_count INTEGER NOT NULL DEFAULT 0
127
+ `,
128
+ },
112
129
  ];
@@ -1,4 +1,4 @@
1
- import { type AgentSubmissionPayload, type AgentRunOptions } from "@agent-native/agentkit/protocol";
1
+ import { type AgentSubmissionReference, type AgentSubmissionPayload, type AgentRunOptions } from "@agent-native/agentkit/protocol";
2
2
  import { type ThreadAnnotationSnapshotConflict } from "../agent/thread-data-builder.js";
3
3
  import { type DbExec } from "../db/client.js";
4
4
  import { type AccessContext } from "../sharing/access.js";
@@ -124,6 +124,9 @@ export declare function ensureChatThreadTables(): Promise<void>;
124
124
  */
125
125
  export declare function hasThreadAccess(userEmail: string | null | undefined, threadId: string | null | undefined, minRole?: ShareRole | "owner", ctx?: Omit<AccessContext, "userEmail">): Promise<boolean>;
126
126
  export declare function resolveThreadAccess(userEmail: string | null | undefined, threadId: string | null | undefined, minRole?: ShareRole | "owner", ctx?: Omit<AccessContext, "userEmail">): Promise<ChatThread | null>;
127
+ export declare function resolveThreadAccessScope(userEmail: string | null | undefined, threadId: string | null | undefined, minRole?: ShareRole | "owner", ctx?: Omit<AccessContext, "userEmail">): Promise<{
128
+ scope: ChatThreadScope | null;
129
+ } | null>;
127
130
  export declare function resolveThreadsAccess(userEmail: string | null | undefined, threadIds: readonly string[], ctx?: Pick<AccessContext, "orgId">): Promise<Map<string, ChatThread>>;
128
131
  export declare function getThread(id: string): Promise<ChatThread | null>;
129
132
  /**
@@ -259,6 +262,7 @@ export interface QueuedMessage {
259
262
  createdAt?: string;
260
263
  attachments?: unknown[];
261
264
  requestAttachments?: unknown[];
265
+ references?: AgentSubmissionReference[];
262
266
  metadata?: Record<string, unknown>;
263
267
  options?: AgentRunOptions;
264
268
  interruptActiveRun?: boolean;
@@ -287,6 +291,7 @@ export interface QueuedSubmissionReceipt {
287
291
  submittedRunId?: string;
288
292
  interruptRunId?: string;
289
293
  retryAfter?: number;
294
+ retryCount: number;
290
295
  createdAt: number;
291
296
  updatedAt: number;
292
297
  }
@@ -299,10 +304,18 @@ export declare function hashQueuedSubmissionPayload(threadId: string, message: Q
299
304
  export declare function queuedSubmissionBehaviorMatches(threadId: string, message: QueuedMessage, identity: AgentSubmissionPayload): boolean;
300
305
  /** Returns the durable admission receipt used to dedupe direct starts and queue retries. */
301
306
  export declare function getQueuedSubmissionReceipt(threadId: string, messageId: string): Promise<QueuedSubmissionReceipt | null>;
307
+ export declare function getQueuedSubmissionReceiptStatus(threadId: string, messageId: string): Promise<{
308
+ state: QueuedSubmissionState;
309
+ submittedRunId?: string;
310
+ } | null>;
311
+ /** Checks the inbox inside a caller's transaction before a fresh run claims its slot. */
312
+ export declare function hasPendingQueuedSubmissionReceipt(tx: DbExec, threadId: string): Promise<boolean>;
302
313
  /** Finds accepted queue rows in priority order for the signed server sweep. */
303
314
  export declare function listQueuedSubmissionReceipts(options?: {
304
315
  limit?: number;
305
316
  now?: number;
317
+ threadId?: string;
318
+ interruptActiveRun?: boolean;
306
319
  }): Promise<QueuedSubmissionReceipt[]>;
307
320
  /** Records a run admission in the same transaction that persists its user message. */
308
321
  export declare function markQueuedSubmissionSubmitted(tx: DbExec, input: {
@@ -316,6 +329,7 @@ export declare function markQueuedSubmissionSubmitted(tx: DbExec, input: {
316
329
  /** Delays a retryable drain failure without releasing the accepted submission. */
317
330
  export declare function retryQueuedSubmissionReceipt(threadId: string, messageId: string, retryAfter: number, options?: {
318
331
  claimId?: string;
332
+ countRetry?: boolean;
319
333
  }): Promise<boolean>;
320
334
  /** Retains but stops automatically promoting a row that can no longer be authorized. */
321
335
  export declare function blockQueuedSubmissionReceipt(threadId: string, messageId: string, options?: {
@@ -349,6 +363,9 @@ export type ThreadQueuedMessageMutation = {
349
363
  } | {
350
364
  type: "remove";
351
365
  messageId: string;
366
+ } | {
367
+ type: "cancel";
368
+ messageId: string;
352
369
  } | {
353
370
  type: "moveToTop";
354
371
  messageId: string;
@@ -365,6 +382,7 @@ export type ThreadQueuedMessageMutation = {
365
382
  messageId: string;
366
383
  retryAfter: number;
367
384
  claimId?: string;
385
+ countRetry?: boolean;
368
386
  } | {
369
387
  type: "blockReceipt";
370
388
  messageId: string;
@@ -393,7 +411,9 @@ export interface ThreadQueuedMessageMutationResult {
393
411
  claimBusy?: boolean;
394
412
  submissionExpired?: boolean;
395
413
  promotionBusy?: boolean;
414
+ receiptManaged?: boolean;
396
415
  receiptUnavailable?: boolean;
416
+ retryDeferred?: boolean;
397
417
  receiptConflict?: boolean;
398
418
  receiptUpdated?: boolean;
399
419
  claimLost?: boolean;