@agent-native/core 0.232.0 → 0.233.0-nightly-20261124004026

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 (119) hide show
  1. package/dist/a2a/handlers.js +60 -1
  2. package/dist/a2a/server.js +9 -0
  3. package/dist/action-call-classification.d.ts +9 -0
  4. package/dist/action-call-classification.js +18 -0
  5. package/dist/action-conformance.d.ts +81 -0
  6. package/dist/action-conformance.js +392 -0
  7. package/dist/action.d.ts +18 -0
  8. package/dist/action.js +68 -5
  9. package/dist/agent/execution-fence.d.ts +3 -1
  10. package/dist/agent/execution-fence.js +13 -2
  11. package/dist/agent/production-agent.d.ts +3 -0
  12. package/dist/agent/production-agent.js +301 -145
  13. package/dist/agent/run-store.js +11 -0
  14. package/dist/agent/thread-data-builder.d.ts +2 -0
  15. package/dist/agent/thread-data-builder.js +5 -1
  16. package/dist/app-config/schema.d.ts +24 -1
  17. package/dist/application-state/handlers.d.ts +1 -1
  18. package/dist/application-state/navigate-write-guard.d.ts +4 -1
  19. package/dist/application-state/navigate-write-guard.js +15 -1
  20. package/dist/cli/design-connect.js +5 -1
  21. package/dist/cli/matched-check.d.ts +1 -0
  22. package/dist/cli/matched-check.js +76 -0
  23. package/dist/client/agent-chat/index.d.ts +1 -1
  24. package/dist/client/agent-chat/index.js +1 -1
  25. package/dist/client/analytics/index.d.ts +1 -1
  26. package/dist/client/analytics.d.ts +13 -1
  27. package/dist/client/analytics.js +5 -2
  28. package/dist/client/application-state.d.ts +11 -0
  29. package/dist/client/application-state.js +219 -23
  30. package/dist/client/chat/agentkit-agent-native.js +52 -11
  31. package/dist/client/chat/agentkit-protocol.js +23 -2
  32. package/dist/client/chat-first-state.d.ts +6 -0
  33. package/dist/client/chat-first-state.js +36 -1
  34. package/dist/client/feature-flags/use-feature-flag.js +14 -6
  35. package/dist/client/navigation/index.d.ts +2 -0
  36. package/dist/client/navigation/index.js +2 -0
  37. package/dist/client/route-state.js +60 -18
  38. package/dist/client/screen-settled.d.ts +71 -1
  39. package/dist/client/screen-settled.js +221 -3
  40. package/dist/client/sse-event-processor.d.ts +1 -0
  41. package/dist/client/sse-event-processor.js +89 -10
  42. package/dist/client/theme.d.ts +6 -0
  43. package/dist/client/theme.js +7 -1
  44. package/dist/client/use-action.js +32 -10
  45. package/dist/client/use-session.js +36 -18
  46. package/dist/collab/struct-routes.d.ts +1 -1
  47. package/dist/db/client.js +2 -2
  48. package/dist/db/errors.d.ts +2 -0
  49. package/dist/db/errors.js +38 -6
  50. package/dist/feature-flags/actions/get-feature-flags.js +9 -2
  51. package/dist/file-upload/actions/upload-image.d.ts +2 -2
  52. package/dist/framework-package-versions.json +8 -8
  53. package/dist/ingestion/index.d.ts +1 -0
  54. package/dist/ingestion/index.js +1 -0
  55. package/dist/ingestion/matched-capture.d.ts +173 -0
  56. package/dist/ingestion/matched-capture.js +574 -0
  57. package/dist/ingestion/pptx.d.ts +1 -0
  58. package/dist/ingestion/pptx.js +4 -2
  59. package/dist/labs/store.d.ts +3 -1
  60. package/dist/labs/store.js +8 -4
  61. package/dist/manifest/index.d.ts +142 -3
  62. package/dist/manifest/index.js +249 -19
  63. package/dist/mcp/build-server.d.ts +2 -0
  64. package/dist/mcp/build-server.js +8 -1
  65. package/dist/mcp/server.js +3 -1
  66. package/dist/notifications/routes.d.ts +3 -3
  67. package/dist/observability/metrics.d.ts +2 -0
  68. package/dist/observability/metrics.js +7 -0
  69. package/dist/org/index.d.ts +1 -1
  70. package/dist/provider-api/actions/custom-provider-registration.d.ts +10 -10
  71. package/dist/provider-api/actions/provider-api.d.ts +14 -14
  72. package/dist/server/action-routes.js +9 -0
  73. package/dist/server/agent-chat/prompt-resources.js +107 -83
  74. package/dist/server/agent-run-context.d.ts +3 -0
  75. package/dist/server/agent-run-context.js +7 -0
  76. package/dist/server/builder-oauth.d.ts +1 -0
  77. package/dist/server/builder-oauth.js +40 -2
  78. package/dist/server/filesystem-action-entry.js +5 -0
  79. package/dist/server/first-touch-route.d.ts +2 -2
  80. package/dist/server/index.d.ts +2 -2
  81. package/dist/server/index.js +2 -2
  82. package/dist/server/open-route.js +10 -4
  83. package/dist/server/poll.d.ts +3 -0
  84. package/dist/server/poll.js +74 -14
  85. package/dist/server/request-context.d.ts +16 -6
  86. package/dist/server/request-context.js +4 -0
  87. package/dist/server/transcribe-voice.d.ts +1 -1
  88. package/dist/shared/analytics-events.d.ts +7 -0
  89. package/dist/shared/viewport-mode.d.ts +2 -0
  90. package/dist/shared/viewport-mode.js +9 -0
  91. package/dist/templates/chat/.agents/skills/actions/SKILL.md +1 -0
  92. package/dist/templates/chat/.agents/skills/build-an-app/SKILL.md +38 -17
  93. package/dist/templates/chat/.agents/skills/shadcn-ui/SKILL.md +3 -2
  94. package/dist/templates/default/.agents/skills/actions/SKILL.md +1 -0
  95. package/dist/templates/default/.agents/skills/build-an-app/SKILL.md +38 -17
  96. package/dist/templates/default/.agents/skills/shadcn-ui/SKILL.md +3 -2
  97. package/dist/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +3 -2
  98. package/dist/templates/headless/.agents/skills/actions/SKILL.md +1 -0
  99. package/dist/templates/workspace-core/.agents/skills/actions/SKILL.md +1 -0
  100. package/dist/templates/workspace-core/.agents/skills/build-an-app/SKILL.md +38 -17
  101. package/dist/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +3 -2
  102. package/dist/testing.d.ts +1 -0
  103. package/dist/testing.js +1 -0
  104. package/dist/tracking/action-lifecycle.d.ts +2 -0
  105. package/dist/tracking/action-lifecycle.js +16 -5
  106. package/docs/content/actions-defining.mdx +7 -0
  107. package/docs/content/custom-design-system.mdx +4 -2
  108. package/package.json +3 -3
  109. package/src/templates/chat/.agents/skills/actions/SKILL.md +1 -0
  110. package/src/templates/chat/.agents/skills/build-an-app/SKILL.md +38 -17
  111. package/src/templates/chat/.agents/skills/shadcn-ui/SKILL.md +3 -2
  112. package/src/templates/default/.agents/skills/actions/SKILL.md +1 -0
  113. package/src/templates/default/.agents/skills/build-an-app/SKILL.md +38 -17
  114. package/src/templates/default/.agents/skills/shadcn-ui/SKILL.md +3 -2
  115. package/src/templates/factory/.agents/skills/review-latest-feedback/SKILL.md +3 -2
  116. package/src/templates/headless/.agents/skills/actions/SKILL.md +1 -0
  117. package/src/templates/workspace-core/.agents/skills/actions/SKILL.md +1 -0
  118. package/src/templates/workspace-core/.agents/skills/build-an-app/SKILL.md +38 -17
  119. package/src/templates/workspace-core/.agents/skills/shadcn-ui/SKILL.md +3 -2
@@ -6,18 +6,71 @@ export declare const navigationModeSchema: z.ZodEnum<{
6
6
  }>;
7
7
  export type NavigationMode = z.infer<typeof navigationModeSchema>;
8
8
  export declare const APP_CAPABILITIES_META_KEY = "agent-native/app-capabilities";
9
+ declare const manifestScreenSchema: z.ZodObject<{
10
+ route: z.ZodString;
11
+ action: z.ZodString;
12
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
13
+ supportsViewOverlay: z.ZodOptional<z.ZodBoolean>;
14
+ }, z.core.$strip>;
15
+ declare const manifestEntitySchema: z.ZodObject<{
16
+ screen: z.ZodOptional<z.ZodString>;
17
+ route: z.ZodOptional<z.ZodString>;
18
+ idParam: z.ZodOptional<z.ZodString>;
19
+ label: z.ZodOptional<z.ZodString>;
20
+ }, z.core.$strip>;
21
+ declare const manifestViewPolicySchema: z.ZodObject<{
22
+ defaultMode: z.ZodOptional<z.ZodEnum<{
23
+ keep: "keep";
24
+ open: "open";
25
+ reveal: "reveal";
26
+ }>>;
27
+ allowBackgroundNavigation: z.ZodOptional<z.ZodBoolean>;
28
+ fallbackScreen: z.ZodOptional<z.ZodString>;
29
+ }, z.core.$strip>;
30
+ declare const suggestableCapabilitySchema: z.ZodObject<{
31
+ type: z.ZodString;
32
+ action: z.ZodString;
33
+ description: z.ZodOptional<z.ZodString>;
34
+ }, z.core.$strip>;
9
35
  declare const v1AppCapabilityManifestSchema: z.ZodObject<{
10
- version: z.ZodLiteral<1>;
36
+ version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>;
11
37
  screens: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
12
38
  route: z.ZodString;
13
39
  action: z.ZodString;
40
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
41
+ supportsViewOverlay: z.ZodOptional<z.ZodBoolean>;
14
42
  }, z.core.$strip>>>;
15
43
  suggestions: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
16
44
  "ai-split-filter": "ai-split-filter";
17
45
  automation: "automation";
18
46
  "saved-view": "saved-view";
19
47
  }> & z.core.$partial, z.ZodString>>;
48
+ entities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
49
+ screen: z.ZodOptional<z.ZodString>;
50
+ route: z.ZodOptional<z.ZodString>;
51
+ idParam: z.ZodOptional<z.ZodString>;
52
+ label: z.ZodOptional<z.ZodString>;
53
+ }, z.core.$strip>>>;
54
+ viewPolicy: z.ZodOptional<z.ZodObject<{
55
+ defaultMode: z.ZodOptional<z.ZodEnum<{
56
+ keep: "keep";
57
+ open: "open";
58
+ reveal: "reveal";
59
+ }>>;
60
+ allowBackgroundNavigation: z.ZodOptional<z.ZodBoolean>;
61
+ fallbackScreen: z.ZodOptional<z.ZodString>;
62
+ }, z.core.$strip>>;
63
+ suggestableCapabilities: z.ZodOptional<z.ZodArray<z.ZodObject<{
64
+ type: z.ZodString;
65
+ action: z.ZodString;
66
+ description: z.ZodOptional<z.ZodString>;
67
+ }, z.core.$strip>>>;
68
+ supportsViewOverlay: z.ZodOptional<z.ZodBoolean>;
20
69
  }, z.core.$strip>;
70
+ export type AppCapabilityManifestScreen = z.infer<typeof manifestScreenSchema>;
71
+ export type AppCapabilityManifestEntity = z.infer<typeof manifestEntitySchema>;
72
+ export type AppCapabilityManifestViewPolicy = z.infer<typeof manifestViewPolicySchema>;
73
+ export type AppCapabilitySuggestableCapability = z.infer<typeof suggestableCapabilitySchema>;
21
74
  export interface LegacyAppManifestInput {
22
75
  version?: undefined;
23
76
  id: string;
@@ -27,26 +80,55 @@ export interface LegacyAppManifestInput {
27
80
  definitions?: Record<string, {
28
81
  show?: {
29
82
  route?: string;
83
+ action?: string;
84
+ supportsViewOverlay?: boolean;
30
85
  };
31
86
  }>;
32
87
  };
88
+ entities?: Record<string, AppCapabilityManifestEntity>;
89
+ viewPolicy?: AppCapabilityManifestViewPolicy;
90
+ supportsViewOverlay?: boolean;
33
91
  suggestableCapabilities?: ReadonlyArray<{
34
92
  type?: string;
35
93
  action?: string;
94
+ description?: string;
36
95
  }>;
37
96
  [key: string]: unknown;
38
97
  }
39
98
  export declare const appCapabilityManifestSchema: z.ZodPreprocess<z.ZodObject<{
40
- version: z.ZodLiteral<1>;
99
+ version: z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>;
41
100
  screens: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
42
101
  route: z.ZodString;
43
102
  action: z.ZodString;
103
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
104
+ supportsViewOverlay: z.ZodOptional<z.ZodBoolean>;
44
105
  }, z.core.$strip>>>;
45
106
  suggestions: z.ZodOptional<z.ZodRecord<z.ZodEnum<{
46
107
  "ai-split-filter": "ai-split-filter";
47
108
  automation: "automation";
48
109
  "saved-view": "saved-view";
49
110
  }> & z.core.$partial, z.ZodString>>;
111
+ entities: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
112
+ screen: z.ZodOptional<z.ZodString>;
113
+ route: z.ZodOptional<z.ZodString>;
114
+ idParam: z.ZodOptional<z.ZodString>;
115
+ label: z.ZodOptional<z.ZodString>;
116
+ }, z.core.$strip>>>;
117
+ viewPolicy: z.ZodOptional<z.ZodObject<{
118
+ defaultMode: z.ZodOptional<z.ZodEnum<{
119
+ keep: "keep";
120
+ open: "open";
121
+ reveal: "reveal";
122
+ }>>;
123
+ allowBackgroundNavigation: z.ZodOptional<z.ZodBoolean>;
124
+ fallbackScreen: z.ZodOptional<z.ZodString>;
125
+ }, z.core.$strip>>;
126
+ suggestableCapabilities: z.ZodOptional<z.ZodArray<z.ZodObject<{
127
+ type: z.ZodString;
128
+ action: z.ZodString;
129
+ description: z.ZodOptional<z.ZodString>;
130
+ }, z.core.$strip>>>;
131
+ supportsViewOverlay: z.ZodOptional<z.ZodBoolean>;
50
132
  }, z.core.$strip>>;
51
133
  export type AppCapabilityManifest = z.infer<typeof v1AppCapabilityManifestSchema>;
52
134
  export declare function defineAppManifest(input: AppCapabilityManifest | LegacyAppManifestInput): AppCapabilityManifest;
@@ -61,13 +143,70 @@ export declare function resolveAppCapabilities(discovery: {
61
143
  }[];
62
144
  _meta?: Record<string, unknown>;
63
145
  }, mount: URL): {
64
- version: 1;
146
+ version: 1 | 2;
65
147
  screens?: {
66
148
  [k: string]: {
67
149
  readonly action: string;
68
150
  readonly url: string;
151
+ readonly route?: string | undefined;
152
+ readonly params?: Record<string, string> | undefined;
153
+ readonly supportsViewOverlay?: boolean | undefined;
69
154
  };
70
155
  } | undefined;
71
156
  suggestions?: Partial<Record<"ai-split-filter" | "automation" | "saved-view", string>> | undefined;
157
+ entities?: Record<string, {
158
+ screen?: string | undefined;
159
+ route?: string | undefined;
160
+ idParam?: string | undefined;
161
+ label?: string | undefined;
162
+ }> | undefined;
163
+ viewPolicy?: {
164
+ defaultMode?: "keep" | "open" | "reveal" | undefined;
165
+ allowBackgroundNavigation?: boolean | undefined;
166
+ fallbackScreen?: string | undefined;
167
+ } | undefined;
168
+ suggestableCapabilities?: {
169
+ type: string;
170
+ action: string;
171
+ description?: string | undefined;
172
+ }[] | undefined;
173
+ supportsViewOverlay?: boolean | undefined;
72
174
  } | undefined;
175
+ /** Matches a concrete path against a manifest route template containing optional `:param` segments. */
176
+ export declare function matchManifestRoute(template: string, candidatePath: string): {
177
+ matched: true;
178
+ params: Record<string, string>;
179
+ } | {
180
+ matched: false;
181
+ };
182
+ /** Expands a manifest route template's `:param` placeholders from `params`, returning leftover query params. */
183
+ export declare function expandManifestRoute(template: string, params?: Record<string, string | number | boolean>): {
184
+ path: string;
185
+ remainingParams: Record<string, string | number | boolean>;
186
+ } | {
187
+ error: string;
188
+ };
189
+ /** Validates a requested app-relative path against declared screen and entity route templates. */
190
+ export declare function validateAppManifestPath(manifest: AppCapabilityManifest, candidatePath: string): {
191
+ valid: true;
192
+ screenId?: string;
193
+ params?: Record<string, string>;
194
+ } | {
195
+ valid: false;
196
+ validTemplates: Array<{
197
+ screenId: string;
198
+ route: string;
199
+ }>;
200
+ };
201
+ /** Resolves `{ screen, params }` against a manifest's declared screen templates. */
202
+ export declare function resolveManifestScreenPath(manifest: AppCapabilityManifest, screenId: string, params?: Record<string, string | number | boolean>): {
203
+ path: string;
204
+ remainingParams: Record<string, string | number | boolean>;
205
+ } | {
206
+ error: string;
207
+ validScreens: Array<{
208
+ screenId: string;
209
+ route: string;
210
+ }>;
211
+ };
73
212
  export {};
@@ -2,21 +2,62 @@ import { z } from "zod";
2
2
  export const navigationModeSchema = z.enum(["open", "reveal", "keep"]);
3
3
  export const APP_CAPABILITIES_META_KEY = "agent-native/app-capabilities";
4
4
  const actionName = z.string().trim().min(1);
5
+ const ROUTE_PARAM_SEGMENT_RE = /^:[A-Za-z][A-Za-z0-9_-]*$/;
5
6
  const route = z
6
7
  .string()
7
- .regex(/^\/(?:[A-Za-z0-9._~-]+\/)*[A-Za-z0-9._~-]*$/)
8
- .refine((path) => !path.split("/").some((part) => part === "." || part === ".."));
8
+ .regex(/^\/(?:(?:[A-Za-z0-9._~-]+|:[A-Za-z][A-Za-z0-9_-]*)\/)*(?:[A-Za-z0-9._~-]+|:[A-Za-z][A-Za-z0-9_-]*)?$/)
9
+ .refine((path) => {
10
+ const parts = path.split("/");
11
+ if (parts.some((part) => part === "." || part === ".."))
12
+ return false;
13
+ const seenParams = new Set();
14
+ for (const part of parts) {
15
+ if (!part.startsWith(":"))
16
+ continue;
17
+ if (!ROUTE_PARAM_SEGMENT_RE.test(part))
18
+ return false;
19
+ const paramName = part.slice(1);
20
+ if (seenParams.has(paramName))
21
+ return false;
22
+ seenParams.add(paramName);
23
+ }
24
+ return true;
25
+ });
9
26
  const suggestionTypeSchema = z.enum([
10
27
  "saved-view",
11
28
  "automation",
12
29
  "ai-split-filter",
13
30
  ]);
31
+ const manifestScreenSchema = z.object({
32
+ route,
33
+ action: actionName,
34
+ params: z.record(z.string().min(1), z.string().min(1)).optional(),
35
+ supportsViewOverlay: z.boolean().optional(),
36
+ });
37
+ const manifestEntitySchema = z.object({
38
+ screen: z.string().trim().min(1).optional(),
39
+ route: route.optional(),
40
+ idParam: z.string().trim().min(1).optional(),
41
+ label: z.string().trim().min(1).optional(),
42
+ });
43
+ const manifestViewPolicySchema = z.object({
44
+ defaultMode: navigationModeSchema.optional(),
45
+ allowBackgroundNavigation: z.boolean().optional(),
46
+ fallbackScreen: z.string().trim().min(1).optional(),
47
+ });
48
+ const suggestableCapabilitySchema = z.object({
49
+ type: z.string().trim().min(1),
50
+ action: actionName,
51
+ description: z.string().trim().min(1).optional(),
52
+ });
14
53
  const v1AppCapabilityManifestSchema = z.object({
15
- version: z.literal(1),
16
- screens: z
17
- .record(z.string().min(1), z.object({ route, action: actionName }))
18
- .optional(),
54
+ version: z.union([z.literal(1), z.literal(2)]),
55
+ screens: z.record(z.string().min(1), manifestScreenSchema).optional(),
19
56
  suggestions: z.partialRecord(suggestionTypeSchema, actionName).optional(),
57
+ entities: z.record(z.string().min(1), manifestEntitySchema).optional(),
58
+ viewPolicy: manifestViewPolicySchema.optional(),
59
+ suggestableCapabilities: z.array(suggestableCapabilitySchema).optional(),
60
+ supportsViewOverlay: z.boolean().optional(),
20
61
  });
21
62
  function adaptLegacyAppManifest(input) {
22
63
  if (!input || typeof input !== "object" || "version" in input) {
@@ -42,30 +83,68 @@ function adaptLegacyAppManifest(input) {
42
83
  if (!id || !def || typeof def !== "object")
43
84
  continue;
44
85
  const show = def.show;
45
- const rawRoute = show && typeof show === "object"
46
- ? show.route
86
+ const showRecord = show && typeof show === "object"
87
+ ? show
47
88
  : undefined;
89
+ const rawRoute = showRecord?.route;
90
+ const rawAction = typeof showRecord?.action === "string" && showRecord.action.trim()
91
+ ? showRecord.action.trim()
92
+ : "navigate";
48
93
  if (typeof rawRoute === "string" && route.safeParse(rawRoute).success) {
49
- screens[id] = { route: rawRoute, action: "navigate" };
94
+ screens[id] = {
95
+ route: rawRoute,
96
+ action: rawAction,
97
+ ...(typeof showRecord?.supportsViewOverlay === "boolean"
98
+ ? { supportsViewOverlay: showRecord.supportsViewOverlay }
99
+ : {}),
100
+ };
50
101
  }
51
102
  }
52
103
  const suggestions = {};
104
+ const suggestableCapabilities = [];
53
105
  if (Array.isArray(legacy.suggestableCapabilities)) {
54
106
  for (const cap of legacy.suggestableCapabilities) {
55
107
  if (!cap || typeof cap !== "object")
56
108
  continue;
57
- const { type, action } = cap;
58
- if (suggestionTypeSchema.safeParse(type).success &&
59
- typeof action === "string" &&
60
- action.trim().length > 0) {
61
- suggestions[type] = action.trim();
109
+ const { type, action, description } = cap;
110
+ if (typeof type === "string" && typeof action === "string") {
111
+ const trimmedType = type.trim();
112
+ const trimmedAction = action.trim();
113
+ if (trimmedType && trimmedAction) {
114
+ suggestableCapabilities.push({
115
+ type: trimmedType,
116
+ action: trimmedAction,
117
+ ...(typeof description === "string" && description.trim()
118
+ ? { description: description.trim() }
119
+ : {}),
120
+ });
121
+ if (suggestionTypeSchema.safeParse(trimmedType).success) {
122
+ suggestions[trimmedType] = trimmedAction;
123
+ }
124
+ }
62
125
  }
63
126
  }
64
127
  }
128
+ const parsedEntities = z
129
+ .record(z.string().min(1), manifestEntitySchema)
130
+ .safeParse(legacy.entities);
131
+ const parsedViewPolicy = manifestViewPolicySchema.safeParse(legacy.viewPolicy);
132
+ const supportsViewOverlay = typeof legacy.supportsViewOverlay === "boolean"
133
+ ? legacy.supportsViewOverlay
134
+ : undefined;
65
135
  return {
66
136
  version: 1,
67
137
  ...(Object.keys(screens).length > 0 ? { screens } : {}),
68
138
  ...(Object.keys(suggestions).length > 0 ? { suggestions } : {}),
139
+ ...(parsedEntities.success && Object.keys(parsedEntities.data).length > 0
140
+ ? { entities: parsedEntities.data }
141
+ : {}),
142
+ ...(parsedViewPolicy.success ? { viewPolicy: parsedViewPolicy.data } : {}),
143
+ ...(suggestableCapabilities.length > 0 &&
144
+ suggestableCapabilities.length !== Object.keys(suggestions).length
145
+ ? { suggestableCapabilities }
146
+ : {}),
147
+ ...(supportsViewOverlay !== undefined ? { supportsViewOverlay } : {}),
69
148
  };
70
149
  }
71
150
  export const appCapabilityManifestSchema = z.preprocess(adaptLegacyAppManifest, v1AppCapabilityManifestSchema);
@@ -79,14 +158,24 @@ export function projectAppManifest(manifest, tools) {
79
158
  const allowed = new Set(tools.map(({ name }) => name));
80
159
  const screens = Object.entries(manifest.screens ?? {}).filter(([, screen]) => allowed.has(screen.action));
81
160
  const suggestions = Object.entries(manifest.suggestions ?? {}).filter(([, action]) => allowed.has(action));
82
- if (screens.length === 0 && suggestions.length === 0)
161
+ const suggestableCapabilities = (manifest.suggestableCapabilities ?? []).filter((cap) => allowed.has(cap.action));
162
+ if (screens.length === 0 &&
163
+ suggestions.length === 0 &&
164
+ suggestableCapabilities.length === 0) {
83
165
  return undefined;
166
+ }
84
167
  return {
85
- version: 1,
168
+ version: manifest.version,
86
169
  ...(screens.length > 0 && { screens: Object.fromEntries(screens) }),
87
170
  ...(suggestions.length > 0 && {
88
171
  suggestions: Object.fromEntries(suggestions),
89
172
  }),
173
+ ...(manifest.entities ? { entities: manifest.entities } : {}),
174
+ ...(manifest.viewPolicy ? { viewPolicy: manifest.viewPolicy } : {}),
175
+ ...(suggestableCapabilities.length > 0 ? { suggestableCapabilities } : {}),
176
+ ...(manifest.supportsViewOverlay !== undefined
177
+ ? { supportsViewOverlay: manifest.supportsViewOverlay }
178
+ : {}),
90
179
  };
91
180
  }
92
181
  /** Use discovery from the selected registration and its trusted runtime mount. */
@@ -99,13 +188,154 @@ export function resolveAppCapabilities(discovery, mount) {
99
188
  return undefined;
100
189
  const base = mount.pathname.replace(/\/+$/, "");
101
190
  const screens = Object.entries(manifest.screens ?? {}).map(([id, screen]) => {
102
- const url = new URL(mount.origin);
103
- url.pathname = base + screen.route;
104
- return [id, { action: screen.action, url: url.href }];
191
+ const href = `${mount.origin}${base}${screen.route}`;
192
+ return [
193
+ id,
194
+ {
195
+ action: screen.action,
196
+ url: href,
197
+ ...(manifest.version >= 2 ? { route: screen.route } : {}),
198
+ ...(screen.params ? { params: screen.params } : {}),
199
+ ...(screen.supportsViewOverlay !== undefined
200
+ ? { supportsViewOverlay: screen.supportsViewOverlay }
201
+ : {}),
202
+ },
203
+ ];
105
204
  });
106
205
  return {
107
206
  version: manifest.version,
108
207
  ...(screens.length > 0 && { screens: Object.fromEntries(screens) }),
109
208
  ...(manifest.suggestions && { suggestions: manifest.suggestions }),
209
+ ...(manifest.entities && { entities: manifest.entities }),
210
+ ...(manifest.viewPolicy && { viewPolicy: manifest.viewPolicy }),
211
+ ...(manifest.suggestableCapabilities && {
212
+ suggestableCapabilities: manifest.suggestableCapabilities,
213
+ }),
214
+ ...(manifest.supportsViewOverlay !== undefined && {
215
+ supportsViewOverlay: manifest.supportsViewOverlay,
216
+ }),
110
217
  };
111
218
  }
219
+ function normalizePathSegments(rawPath) {
220
+ const withoutHash = rawPath.split("#", 1)[0] ?? rawPath;
221
+ const pathname = withoutHash.split("?", 1)[0] ?? withoutHash;
222
+ return pathname.split("/").filter(Boolean);
223
+ }
224
+ /** Matches a concrete path against a manifest route template containing optional `:param` segments. */
225
+ export function matchManifestRoute(template, candidatePath) {
226
+ const templateSegments = normalizePathSegments(template);
227
+ const candidateSegments = normalizePathSegments(candidatePath);
228
+ if (templateSegments.length !== candidateSegments.length) {
229
+ return { matched: false };
230
+ }
231
+ const params = {};
232
+ for (let i = 0; i < templateSegments.length; i += 1) {
233
+ const tSeg = templateSegments[i];
234
+ const cSeg = candidateSegments[i];
235
+ if (!tSeg || !cSeg)
236
+ return { matched: false };
237
+ if (ROUTE_PARAM_SEGMENT_RE.test(tSeg)) {
238
+ try {
239
+ params[tSeg.slice(1)] = decodeURIComponent(cSeg);
240
+ }
241
+ catch {
242
+ // coercion-ok: malformed percent sequence falls back to raw segment.
243
+ params[tSeg.slice(1)] = cSeg;
244
+ }
245
+ continue;
246
+ }
247
+ if (tSeg !== cSeg)
248
+ return { matched: false };
249
+ }
250
+ return { matched: true, params };
251
+ }
252
+ /** Expands a manifest route template's `:param` placeholders from `params`, returning leftover query params. */
253
+ export function expandManifestRoute(template, params) {
254
+ const remainingParams = {
255
+ ...(params ?? {}),
256
+ };
257
+ const segments = normalizePathSegments(template);
258
+ if (segments.length === 0) {
259
+ return { path: "/", remainingParams };
260
+ }
261
+ const missing = [];
262
+ const resolved = segments.map((seg) => {
263
+ if (!ROUTE_PARAM_SEGMENT_RE.test(seg))
264
+ return seg;
265
+ const paramName = seg.slice(1);
266
+ const hasParam = Object.prototype.hasOwnProperty.call(remainingParams, paramName);
267
+ const raw = hasParam ? remainingParams[paramName] : undefined;
268
+ if (raw === undefined || String(raw).trim() === "") {
269
+ missing.push(paramName);
270
+ return seg;
271
+ }
272
+ delete remainingParams[paramName];
273
+ return encodeURIComponent(String(raw).trim());
274
+ });
275
+ if (missing.length > 0) {
276
+ return {
277
+ error: `Missing required route parameter(s) ${missing.map((m) => `:${m}`).join(", ")} for template "${template}".`,
278
+ };
279
+ }
280
+ return { path: `/${resolved.join("/")}`, remainingParams };
281
+ }
282
+ /** Validates a requested app-relative path against declared screen and entity route templates. */
283
+ export function validateAppManifestPath(manifest, candidatePath) {
284
+ const entries = [];
285
+ for (const [screenId, screen] of Object.entries(manifest.screens ?? {})) {
286
+ entries.push({ screenId, route: screen.route });
287
+ }
288
+ for (const [entityId, entity] of Object.entries(manifest.entities ?? {})) {
289
+ if (entity.route) {
290
+ entries.push({
291
+ screenId: entity.screen ?? entityId,
292
+ route: entity.route,
293
+ });
294
+ }
295
+ }
296
+ if (entries.length === 0) {
297
+ return { valid: true };
298
+ }
299
+ const normalizedSegments = normalizePathSegments(candidatePath);
300
+ if (normalizedSegments.length === 0) {
301
+ const homeEntry = entries.find((entry) => normalizePathSegments(entry.route).length === 0);
302
+ return {
303
+ valid: true,
304
+ ...(homeEntry ? { screenId: homeEntry.screenId, params: {} } : {}),
305
+ };
306
+ }
307
+ for (const entry of entries) {
308
+ const matched = matchManifestRoute(entry.route, candidatePath);
309
+ if (matched.matched) {
310
+ return { valid: true, screenId: entry.screenId, params: matched.params };
311
+ }
312
+ }
313
+ return { valid: false, validTemplates: entries };
314
+ }
315
+ /** Resolves `{ screen, params }` against a manifest's declared screen templates. */
316
+ export function resolveManifestScreenPath(manifest, screenId, params) {
317
+ const screens = manifest.screens ?? {};
318
+ const validScreens = Object.entries(screens).map(([id, s]) => ({
319
+ screenId: id,
320
+ route: s.route,
321
+ }));
322
+ const screen = Object.prototype.hasOwnProperty.call(screens, screenId)
323
+ ? screens[screenId]
324
+ : undefined;
325
+ if (!screen) {
326
+ const list = validScreens
327
+ .map((entry) => `${entry.screenId} (${entry.route})`)
328
+ .join(", ");
329
+ return {
330
+ error: list
331
+ ? `Unknown screen "${screenId}". Valid screens: ${list}.`
332
+ : `Unknown screen "${screenId}".`,
333
+ validScreens,
334
+ };
335
+ }
336
+ const expanded = expandManifestRoute(screen.route, params);
337
+ if ("error" in expanded) {
338
+ return { error: expanded.error, validScreens };
339
+ }
340
+ return expanded;
341
+ }
@@ -174,6 +174,8 @@ export interface MCPRequestMeta {
174
174
  * `run.browserTabId`) so the call does not impersonate an open editor tab.
175
175
  */
176
176
  browserTabId?: string;
177
+ /** Optional viewport mode (`foreground` or `background`) from `x-agent-native-viewport-mode`. */
178
+ viewportMode?: import("../server/request-context.js").ViewportMode;
177
179
  /** Origin verified at the HTTP boundary for a page-grant review link. */
178
180
  approvalOrigin?: string;
179
181
  localAgentTaskClient?: import("../a2a/mcp-task-client.js").McpAgentTaskClient;
@@ -2738,8 +2738,15 @@ export async function createMCPServerForRequest(config, identity, requestMeta) {
2738
2738
  const browserTabTarget = hasVerifiedMcpUserIdentity(effectiveIdentity)
2739
2739
  ? createBrowserTabTargetSlot(requestMeta?.browserTabId)
2740
2740
  : undefined;
2741
+ const viewportMode = requestMeta?.viewportMode;
2741
2742
  const authUserId = await resolveCallerAuthUserId();
2742
- const result = await runWithMcpChatTurnCall(effectiveIdentity, toolName, turnGrantExcluded, () => withCallerContext(fn, mcpRequestId, authUserId, browserTabTarget ? { browserTabTarget } : undefined, timezone, "UTC"));
2743
+ const runContext = browserTabTarget || viewportMode
2744
+ ? {
2745
+ ...(browserTabTarget ? { browserTabTarget } : {}),
2746
+ ...(viewportMode ? { viewportMode } : {}),
2747
+ }
2748
+ : undefined;
2749
+ const result = await runWithMcpChatTurnCall(effectiveIdentity, toolName, turnGrantExcluded, () => withCallerContext(fn, mcpRequestId, authUserId, runContext, timezone, "UTC"));
2743
2750
  return withBrowserTabTargetNote(result, browserTabTarget);
2744
2751
  }
2745
2752
  const actionCallContext = {
@@ -1,7 +1,7 @@
1
1
  import { defineEventHandler, setResponseStatus, setResponseHeader, getMethod, getQuery, getRequestHeader, } from "h3";
2
2
  import { getAppConfig } from "../app-config/store.js";
3
3
  import { registerRecurringSweepHandler } from "../jobs/sweep-hooks.js";
4
- import { readBrowserTabIdHeader } from "../server/agent-run-context.js";
4
+ import { readBrowserTabIdHeader, readViewportModeHeader, } from "../server/agent-run-context.js";
5
5
  import { getConfiguredAppBasePath } from "../server/app-base-path.js";
6
6
  import { describeBearerCredentialRefusal, } from "../server/bearer-credential-refusal.js";
7
7
  import { CREDENTIAL_MEMBERSHIP_UNAVAILABLE_MESSAGE } from "../server/credential-membership-unavailable.js";
@@ -63,10 +63,12 @@ function deriveRequestMeta(event) {
63
63
  const basePath = getConfiguredAppBasePath();
64
64
  const turnGrant = getRequestHeader(event, MCP_TURN_GRANT_HEADER);
65
65
  const browserTabId = readBrowserTabIdHeader(event);
66
+ const viewportMode = readViewportModeHeader(event);
66
67
  return {
67
68
  origin,
68
69
  ...(turnGrant !== undefined ? { turnGrant } : {}),
69
70
  ...(browserTabId ? { browserTabId } : {}),
71
+ ...(viewportMode ? { viewportMode } : {}),
70
72
  ...(isAgentTurnGrantContext() ? { turnGrantExcluded: true } : {}),
71
73
  ...(basePath ? { basePath } : {}),
72
74
  target,
@@ -1,12 +1,12 @@
1
1
  export declare function createNotificationsHandler(): import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<"" | import("./types.js").Notification[] | {
2
- error?: undefined;
3
2
  count: number;
4
3
  updated?: undefined;
4
+ error?: undefined;
5
5
  ok?: undefined;
6
6
  } | {
7
7
  count?: undefined;
8
- error?: undefined;
9
8
  updated: number;
9
+ error?: undefined;
10
10
  ok?: undefined;
11
11
  } | {
12
12
  count?: undefined;
@@ -15,7 +15,7 @@ export declare function createNotificationsHandler(): import("h3").EventHandlerW
15
15
  ok?: undefined;
16
16
  } | {
17
17
  count?: undefined;
18
- error?: undefined;
19
18
  updated?: undefined;
19
+ error?: undefined;
20
20
  ok: boolean;
21
21
  }>>;
@@ -64,6 +64,8 @@ export type TraceWriteStage = "spans" | "summary" | "thread_org" | "write";
64
64
  export declare function recordTraceWriteFailure(stage: TraceWriteStage, error: unknown): void;
65
65
  /** Counted once per write whose durable change marker did not persist. */
66
66
  export declare function recordActionChangeMarkerFailure(error: unknown): void;
67
+ /** Counted once per sync event a poll skipped as unreadable, by cause. */
68
+ export declare function recordUnreadableSyncEvent(cause: string): void;
67
69
  export declare function __resetFlushFailureLogForTests(): void;
68
70
  export declare const METRICS_FLUSH_MIN_INTERVAL_MS = 10000;
69
71
  /**
@@ -85,6 +85,9 @@ function instruments() {
85
85
  actionChangeMarkerFailures: meter.createCounter("agent_native.action_change.marker_failures", {
86
86
  description: "Action writes whose durable change marker did not persist; polling clients were not told about them.",
87
87
  }),
88
+ unreadableSyncEvents: meter.createCounter("agent_native.sync.unreadable_events", {
89
+ description: "Sync events a poll skipped because their access check failed or timed out, or their row could not be read.",
90
+ }),
88
91
  mcpScriptWriteEffects: meter.createCounter("agent_native.mcp.script.write_effects", {
89
92
  description: "MCP script writes entering each effect status: pending when recorded before they run, then committed, not-applied or unknown as they settle.",
90
93
  }),
@@ -233,6 +236,10 @@ export function recordActionChangeMarkerFailure(error) {
233
236
  "error.type": flushErrorType(error),
234
237
  });
235
238
  }
239
+ /** Counted once per sync event a poll skipped as unreadable, by cause. */
240
+ export function recordUnreadableSyncEvent(cause) {
241
+ instruments()?.unreadableSyncEvents.add(1, { cause });
242
+ }
236
243
  function flushErrorType(error) {
237
244
  return error instanceof Error && error.name ? error.name : "unknown";
238
245
  }
@@ -184,9 +184,9 @@ export declare const getMyOrgHandler: import("h3").EventHandlerWithFetch<import(
184
184
  }>>;
185
185
  export declare const createOrgHandler: import("h3").EventHandlerWithFetch<import("h3").EventHandlerRequest, Promise<{
186
186
  success: boolean;
187
- id?: undefined;
188
187
  name?: undefined;
189
188
  role?: undefined;
189
+ id?: undefined;
190
190
  } | {
191
191
  success?: undefined;
192
192
  id: string;