@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
package/dist/action.d.ts CHANGED
@@ -708,6 +708,20 @@ interface DefineActionWithSchema<TSchema extends StandardSchemaV1, TReturn = any
708
708
  * approval reads it too: a call it covers gets no "already ran" warning.
709
709
  */
710
710
  retrySafe?: boolean | ((input: StandardSchemaV1.InferInput<TSchema>) => boolean);
711
+ /**
712
+ * Marks a write the app makes on its own, with no user gesture behind it: on
713
+ * page load, on mount, on a timer, or experiment and usage bookkeeping. Its
714
+ * `action_started`, `action_completed`, and `action_failed` events carry
715
+ * `action_kind: "automatic"` instead of `"write"`, so product-use counts
716
+ * leave it out. Only a call the action route sees come from the app's own
717
+ * page can be automatic; a call from an agent, an MCP client, the CLI, or
718
+ * another app is a person asking and stays a write. Pass a predicate when
719
+ * only some UI calls are automatic, such as a background sync the poller calls without `force`;
720
+ * it sees the validated arguments and the call's context. It labels
721
+ * analytics only: a write stays a write everywhere else, so never set
722
+ * `readOnly` to quiet one.
723
+ */
724
+ automatic?: boolean | ((input: StandardSchemaV1.InferOutput<TSchema>, ctx: ActionRunContext) => boolean);
711
725
  /**
712
726
  * How the action reads an ISO date-time argument that names no zone, so an
713
727
  * approval summary can say so: `"calendar"` means in the calendar's own
@@ -851,6 +865,8 @@ interface DefineActionWithParams<TParams extends Record<string, ParameterSchema>
851
865
  parallelSafe?: boolean;
852
866
  /** See `ActionDefinition.retrySafe`. */
853
867
  retrySafe?: boolean | ((input: InferParams<TParams>) => boolean);
868
+ /** See `automatic` on the schema form above. */
869
+ automatic?: boolean | ((input: InferParams<TParams>, ctx: ActionRunContext) => boolean);
854
870
  /** See `ActionDefinition.zonelessTimes`. */
855
871
  zonelessTimes?: "calendar";
856
872
  endsTurn?: boolean;
@@ -914,6 +930,8 @@ export interface ActionDefinition<TInput, TReturn> {
914
930
  readonly changeResource?: (input: TInput, result: TReturn) => ActionChangeResource | null | undefined;
915
931
  readonly parallelSafe?: boolean;
916
932
  readonly retrySafe?: boolean | ((input: TInput) => boolean);
933
+ /** See `automatic` on the action options. */
934
+ readonly automatic?: boolean | ((input: TInput, ctx: ActionRunContext) => boolean);
917
935
  readonly zonelessTimes?: "calendar";
918
936
  readonly endsTurn?: boolean;
919
937
  readonly dedupe?: boolean;
package/dist/action.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { isA2AForegroundCall } from "./a2a/foreground-call-scope.js";
2
2
  import { copyActionArguments, snapshotActionArguments, } from "./action-arguments-identity.js";
3
- import { actionCallIsRetrySafe, actionCallReadOnly, actionOutputEffect, classifyActionCall, isMcpReadOnlyTool, } from "./action-call-classification.js";
3
+ import { actionCallIsAutomatic, actionCallIsRetrySafe, actionCallReadOnly, actionOutputEffect, classifyActionCall, isMcpReadOnlyTool, } from "./action-call-classification.js";
4
4
  import { ACTION_EXECUTION_KEY, actionExecutionStorage, currentActionApproval, currentActionApprovalAskedAt, currentActionOriginCaller, endInvocationEvidence, holdInvocationEvidence, noteObservedWrite, currentInvocationEvidence, runOutsideActionInvocation, takeVouchedEvidence, withoutWriteObservation, } from "./action-frame.js";
5
5
  import { coerceGatewayStringifiedArgs } from "./action-input-coercion.js";
6
6
  import { buildActionMcpOutputContract, describeOutputContractIssue, inputSchemaToJsonSchema, maskedIssuePath, outputSchemaToJsonSchema, } from "./action-output-contract.js";
@@ -699,6 +699,10 @@ export function defineAction(options) {
699
699
  const checkOutput = hasOutputSchema
700
700
  ? outputValidator(options.outputSchema, outputErrorStrategy, options.outputFallback, options.description)
701
701
  : undefined;
702
+ const classificationEntry = {
703
+ ...(readOnly !== undefined ? { readOnly } : {}),
704
+ ...(options.planMode !== undefined ? { planMode: options.planMode } : {}),
705
+ };
702
706
  // Runs inside input validation, so a call is classified from the arguments
703
707
  // `run` receives, defaults applied, and inside audit and tracking, so an
704
708
  // invalid call is still recorded as a failed run.
@@ -709,7 +713,7 @@ export function defineAction(options) {
709
713
  const prepared = takePreparedClassification(ctx, args, executionKey);
710
714
  const callReadOnly = prepared
711
715
  ? prepared.readOnly
712
- : actionCallReadOnly({ readOnly, planMode: options.planMode }, args);
716
+ : actionCallReadOnly(classificationEntry, args);
713
717
  const frame = ownFrame();
714
718
  if (frame) {
715
719
  frame.writes = callReadOnly !== true;
@@ -806,12 +810,62 @@ export function defineAction(options) {
806
810
  const finalRun = resolveAuditAttach(effectiveAuditConfig, readOnly)
807
811
  ? wrapRunWithAudit(run, effectiveAuditConfig, actionIsPrivate)
808
812
  : run;
809
- const trackedRun = wrapRunWithServicePrincipalGrant(wrapRunWithActionTracking(finalRun, readOnly, {
813
+ const automatic = typeof options.automatic === "boolean" ||
814
+ typeof options.automatic === "function"
815
+ ? options.automatic
816
+ : undefined;
817
+ const validatedCopy = async (args) => {
818
+ const copy = copyActionArguments(snapshotActionArguments(args).value);
819
+ if (!hasSchema)
820
+ return copy;
821
+ const value = await validateActionArgs(options.schema, copy, convertedParameters());
822
+ if (typeof args === "object" && args !== null) {
823
+ labelValidatedArgs.set(args, { schema: options.schema, value });
824
+ }
825
+ return copyActionArguments(snapshotActionArguments(value).value);
826
+ };
827
+ const actionKind = async (args, ctx, fromAppUi) => {
828
+ const prepared = preparedRunFor(ctx, args);
829
+ const intent = prepared?.key === executionKey ? prepared.intent : undefined;
830
+ let input;
831
+ const callInput = () => (input ??= intent
832
+ ? Promise.resolve(preparedCallArguments(intent))
833
+ : validatedCopy(args));
834
+ try {
835
+ const callReadOnly = intent
836
+ ? intent.readOnly
837
+ : options.planMode !== undefined &&
838
+ actionCallReadOnly(classificationEntry, await callInput());
839
+ if (callReadOnly === true)
840
+ return "read";
841
+ if (!fromAppUi)
842
+ return "write";
843
+ return actionCallIsAutomatic({ automatic }, typeof automatic === "function" ? await callInput() : args, ctx)
844
+ ? "automatic"
845
+ : "write";
846
+ }
847
+ catch {
848
+ // coercion-ok: invalid or uncopyable arguments stay counted as a write.
849
+ return "write";
850
+ }
851
+ };
852
+ const trackingOptions = {
810
853
  includeOutputId: options.persistInChatHistory !== false,
811
- }));
854
+ actionKind,
855
+ };
856
+ const trackedRun = wrapRunWithServicePrincipalGrant(wrapRunWithActionTracking(async (args, ctx) => {
857
+ try {
858
+ return await finalRun(args, ctx);
859
+ }
860
+ finally {
861
+ if (typeof args === "object" && args !== null) {
862
+ labelValidatedArgs.delete(args);
863
+ }
864
+ }
865
+ }, readOnly, trackingOptions));
812
866
  const invalidCallRun = wrapRunWithActionTracking(resolveAuditAttach(effectiveAuditConfig, readOnly)
813
867
  ? wrapRunWithAudit(throwInvalidCallError, effectiveAuditConfig, actionIsPrivate)
814
- : throwInvalidCallError, readOnly, { includeOutputId: options.persistInChatHistory !== false });
868
+ : throwInvalidCallError, readOnly, trackingOptions);
815
869
  const toolCallable = typeof options.toolCallable === "boolean"
816
870
  ? options.toolCallable
817
871
  : undefined;
@@ -1005,6 +1059,7 @@ export function defineAction(options) {
1005
1059
  : {}),
1006
1060
  ...(typeof parallelSafe === "boolean" ? { parallelSafe } : {}),
1007
1061
  ...(retrySafe !== undefined ? { retrySafe } : {}),
1062
+ ...(automatic !== undefined ? { automatic } : {}),
1008
1063
  ...(zonelessTimes !== undefined ? { zonelessTimes } : {}),
1009
1064
  ...(typeof endsTurn === "boolean" ? { endsTurn } : {}),
1010
1065
  ...(typeof dedupe === "boolean" ? { dedupe } : {}),
@@ -1661,6 +1716,7 @@ function extractNavigationIntent(args) {
1661
1716
  return typeof intent === "string" ? intent : undefined;
1662
1717
  }
1663
1718
  const preparedRuns = new WeakMap();
1719
+ const labelValidatedArgs = new WeakMap();
1664
1720
  function preparedRunHolder(ctx, args) {
1665
1721
  if (args !== null && typeof args === "object" && preparedRuns.has(args)) {
1666
1722
  return args;
@@ -2164,6 +2220,13 @@ function wrapWithValidation(schema, run, toolParameters, privateAction) {
2164
2220
  return async (args, ctx) => {
2165
2221
  if (preparedRunFor(ctx, args)?.schema === schema)
2166
2222
  return run(args, ctx);
2223
+ const labelled = typeof args === "object" && args !== null
2224
+ ? labelValidatedArgs.get(args)
2225
+ : undefined;
2226
+ if (labelled?.schema === schema) {
2227
+ labelValidatedArgs.delete(args);
2228
+ return run(labelled.value, ctx);
2229
+ }
2167
2230
  let validated;
2168
2231
  try {
2169
2232
  validated = await validateActionArgs(schema, args, toolParameters());
@@ -44,7 +44,9 @@ export declare function lockAndAssertCurrentExecutionFences(tx: DbExec, ignoredF
44
44
  * and stay strict. Locking the lease row first orders this read after any
45
45
  * revoke that committed and before any that has not.
46
46
  */
47
- export declare function ownsLapsedTurnLease(tx: DbExec, fence: ExecutionFence): Promise<boolean>;
47
+ export declare function ownsLapsedTurnLease(tx: DbExec, fence: ExecutionFence, options?: {
48
+ lapsedWithinMs?: number;
49
+ }): Promise<boolean>;
48
50
  export declare function withFencedExecutionWrite<T>(write: (tx: DbExec) => Promise<T>, scope?: {
49
51
  runId?: string;
50
52
  threadId?: string;
@@ -113,7 +113,8 @@ export async function lockAndAssertCurrentExecutionFences(tx, ignoredFence) {
113
113
  * and stay strict. Locking the lease row first orders this read after any
114
114
  * revoke that committed and before any that has not.
115
115
  */
116
- export async function ownsLapsedTurnLease(tx, fence) {
116
+ export async function ownsLapsedTurnLease(tx, fence, options) {
117
+ const lapsedWithinMs = options?.lapsedWithinMs ?? null;
117
118
  const lease = await tx.execute({
118
119
  sql: `SELECT generation
119
120
  FROM agent_execution_leases
@@ -122,8 +123,18 @@ export async function ownsLapsedTurnLease(tx, fence) {
122
123
  AND owner_run_id = ?
123
124
  AND generation = CAST(? AS BIGINT)
124
125
  AND lease_expires_at >= updated_at + INTERVAL '1 second'
126
+ AND (CAST(? AS BIGINT) IS NULL
127
+ OR lease_expires_at > clock_timestamp() -
128
+ (CAST(? AS BIGINT) * INTERVAL '1 millisecond'))
125
129
  FOR UPDATE`,
126
- args: [fence.threadId, fence.turnId, fence.runId, fence.generation],
130
+ args: [
131
+ fence.threadId,
132
+ fence.turnId,
133
+ fence.runId,
134
+ fence.generation,
135
+ lapsedWithinMs,
136
+ lapsedWithinMs,
137
+ ],
127
138
  timeoutMs: LAPSED_LEASE_STATEMENT_TIMEOUT_MS,
128
139
  maxAttempts: 1,
129
140
  });
@@ -171,6 +171,7 @@ export interface ActionEntry {
171
171
  access?: import("../authorization/check-action.js").ActionAccessConfig;
172
172
  fileMutationProof?: (args: unknown) => AgentFileMutationProof | undefined;
173
173
  schema?: unknown;
174
+ outputSchema?: import("@standard-schema/spec").StandardSchemaV1;
174
175
  /** The input schema agents are shown, when `defineAction` was given one
175
176
  * narrower than `schema`. */
176
177
  agentInputSchema?: unknown;
@@ -396,6 +397,8 @@ export interface ProductionAgentOptions {
396
397
  message: string;
397
398
  attachments?: AgentChatAttachment[];
398
399
  queuedMessageId?: string;
400
+ /** A promoted queued message's claim; saving it checks the claim. */
401
+ queuedMessageClaimId?: string;
399
402
  agentKitMessageId?: string;
400
403
  submissionExpiresAt?: unknown;
401
404
  retryContext: RefusedTurnRetryContext;