@agent-native/core 0.49.26 → 0.50.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 (98) hide show
  1. package/dist/agent/harness/ai-sdk-adapter.d.ts +13 -0
  2. package/dist/agent/harness/ai-sdk-adapter.d.ts.map +1 -0
  3. package/dist/agent/harness/ai-sdk-adapter.js +232 -0
  4. package/dist/agent/harness/ai-sdk-adapter.js.map +1 -0
  5. package/dist/agent/harness/background.d.ts +15 -0
  6. package/dist/agent/harness/background.d.ts.map +1 -0
  7. package/dist/agent/harness/background.js +233 -0
  8. package/dist/agent/harness/background.js.map +1 -0
  9. package/dist/agent/harness/builtin.d.ts +2 -0
  10. package/dist/agent/harness/builtin.d.ts.map +1 -0
  11. package/dist/agent/harness/builtin.js +24 -0
  12. package/dist/agent/harness/builtin.js.map +1 -0
  13. package/dist/agent/harness/index.d.ts +9 -0
  14. package/dist/agent/harness/index.d.ts.map +1 -0
  15. package/dist/agent/harness/index.js +8 -0
  16. package/dist/agent/harness/index.js.map +1 -0
  17. package/dist/agent/harness/registry.d.ts +15 -0
  18. package/dist/agent/harness/registry.d.ts.map +1 -0
  19. package/dist/agent/harness/registry.js +70 -0
  20. package/dist/agent/harness/registry.js.map +1 -0
  21. package/dist/agent/harness/runner.d.ts +21 -0
  22. package/dist/agent/harness/runner.d.ts.map +1 -0
  23. package/dist/agent/harness/runner.js +86 -0
  24. package/dist/agent/harness/runner.js.map +1 -0
  25. package/dist/agent/harness/store.d.ts +46 -0
  26. package/dist/agent/harness/store.d.ts.map +1 -0
  27. package/dist/agent/harness/store.js +304 -0
  28. package/dist/agent/harness/store.js.map +1 -0
  29. package/dist/agent/harness/translate.d.ts +5 -0
  30. package/dist/agent/harness/translate.d.ts.map +1 -0
  31. package/dist/agent/harness/translate.js +120 -0
  32. package/dist/agent/harness/translate.js.map +1 -0
  33. package/dist/agent/harness/types.d.ts +127 -0
  34. package/dist/agent/harness/types.d.ts.map +1 -0
  35. package/dist/agent/harness/types.js +2 -0
  36. package/dist/agent/harness/types.js.map +1 -0
  37. package/dist/agent/production-agent.d.ts.map +1 -1
  38. package/dist/agent/production-agent.js +2 -0
  39. package/dist/agent/production-agent.js.map +1 -1
  40. package/dist/cli/create.d.ts.map +1 -1
  41. package/dist/cli/create.js +10 -1
  42. package/dist/cli/create.js.map +1 -1
  43. package/dist/cli/pr-visual-recap-workflow.d.ts +1 -1
  44. package/dist/cli/pr-visual-recap-workflow.d.ts.map +1 -1
  45. package/dist/cli/pr-visual-recap-workflow.js +1 -1
  46. package/dist/cli/pr-visual-recap-workflow.js.map +1 -1
  47. package/dist/cli/skills.d.ts +1 -1
  48. package/dist/cli/skills.d.ts.map +1 -1
  49. package/dist/cli/skills.js +8 -1
  50. package/dist/cli/skills.js.map +1 -1
  51. package/dist/client/blocks/library/wireframe.d.ts.map +1 -1
  52. package/dist/client/blocks/library/wireframe.js +0 -1
  53. package/dist/client/blocks/library/wireframe.js.map +1 -1
  54. package/dist/client/resources/use-resources.d.ts.map +1 -1
  55. package/dist/client/resources/use-resources.js +4 -2
  56. package/dist/client/resources/use-resources.js.map +1 -1
  57. package/dist/code-agents/background-run.d.ts +6 -4
  58. package/dist/code-agents/background-run.d.ts.map +1 -1
  59. package/dist/code-agents/background-run.js.map +1 -1
  60. package/dist/coding-tools/run-code.js +6 -4
  61. package/dist/coding-tools/run-code.js.map +1 -1
  62. package/dist/file-upload/builder.d.ts.map +1 -1
  63. package/dist/file-upload/builder.js +115 -56
  64. package/dist/file-upload/builder.js.map +1 -1
  65. package/dist/provider-api/index.d.ts +20 -12
  66. package/dist/provider-api/index.d.ts.map +1 -1
  67. package/dist/provider-api/index.js +157 -37
  68. package/dist/provider-api/index.js.map +1 -1
  69. package/dist/provider-api/quota-governor.d.ts +53 -0
  70. package/dist/provider-api/quota-governor.d.ts.map +1 -0
  71. package/dist/provider-api/quota-governor.js +395 -0
  72. package/dist/provider-api/quota-governor.js.map +1 -0
  73. package/dist/provider-api/staging.d.ts.map +1 -1
  74. package/dist/provider-api/staging.js +16 -0
  75. package/dist/provider-api/staging.js.map +1 -1
  76. package/dist/server/agent-chat-plugin.d.ts.map +1 -1
  77. package/dist/server/agent-chat-plugin.js +34 -10
  78. package/dist/server/agent-chat-plugin.js.map +1 -1
  79. package/dist/templates/workspace-core/.agents/skills/harness-agents/SKILL.md +98 -0
  80. package/dist/workspace-files/index.d.ts +0 -1
  81. package/dist/workspace-files/index.d.ts.map +1 -1
  82. package/dist/workspace-files/index.js +0 -1
  83. package/dist/workspace-files/index.js.map +1 -1
  84. package/dist/workspace-files/store.d.ts +14 -9
  85. package/dist/workspace-files/store.d.ts.map +1 -1
  86. package/dist/workspace-files/store.js +89 -164
  87. package/dist/workspace-files/store.js.map +1 -1
  88. package/dist/workspace-files/tool.d.ts +3 -4
  89. package/dist/workspace-files/tool.d.ts.map +1 -1
  90. package/dist/workspace-files/tool.js +8 -7
  91. package/dist/workspace-files/tool.js.map +1 -1
  92. package/docs/content/deployment.md +1 -1
  93. package/package.json +2 -1
  94. package/src/templates/workspace-core/.agents/skills/harness-agents/SKILL.md +98 -0
  95. package/dist/workspace-files/schema.d.ts +0 -195
  96. package/dist/workspace-files/schema.d.ts.map +0 -1
  97. package/dist/workspace-files/schema.js +0 -48
  98. package/dist/workspace-files/schema.js.map +0 -1
@@ -4,6 +4,7 @@ import { createSsrfSafeDispatcher, isBlockedExtensionUrlWithDns, } from "../exte
4
4
  import { deleteOAuthTokens, listOAuthAccountsByOwner, saveOAuthTokens, } from "../oauth-tokens/index.js";
5
5
  import { getCredentialContext } from "../server/request-context.js";
6
6
  import { resolveWorkspaceConnectionCredentialForApp } from "../workspace-connections/credentials.js";
7
+ import { createProviderQuotaIdentity, createProviderRequestDedupeKey, executeWithProviderQuota, } from "./quota-governor.js";
7
8
  export { upsertCustomProvider, deleteCustomProvider, listCustomProviders, getCustomProvider, validateCustomBaseUrl, } from "./custom-registry.js";
8
9
  export const PROVIDER_API_IDS = [
9
10
  "amplitude",
@@ -842,6 +843,14 @@ export async function executeProviderApiRequest(args, runtime) {
842
843
  const effectiveMaxBytes = args.saveToFile
843
844
  ? SAVE_TO_FILE_MAX_BYTES
844
845
  : clampMaxBytes(args.maxBytes);
846
+ const quotaIdentity = createProviderQuotaIdentity({
847
+ appId: runtimeOptionsAppId(runtime),
848
+ providerId: config.id,
849
+ ctx,
850
+ credentialSources: auth.credentialSources,
851
+ connectionId: args.connectionId,
852
+ accountId: args.accountId,
853
+ });
845
854
  // --- fetchAllPages mode ---
846
855
  if (args.fetchAllPages) {
847
856
  const pageCfg = args.fetchAllPages;
@@ -859,6 +868,12 @@ export async function executeProviderApiRequest(args, runtime) {
859
868
  ? setValueAtPath(substituteUnknown(args.body, placeholders), extra.bodyCursor.path, extra.bodyCursor.value)
860
869
  : substituteUnknown(args.body, placeholders);
861
870
  const pageBody = prepareBody(bodyWithCursor, { ...headers });
871
+ const requestKey = createProviderRequestDedupeKey({
872
+ method,
873
+ url: pageUrl.href,
874
+ body: pageBody,
875
+ headers,
876
+ });
862
877
  const resp = await fetchWithTimeout(pageUrl.href, {
863
878
  method,
864
879
  headers,
@@ -866,6 +881,12 @@ export async function executeProviderApiRequest(args, runtime) {
866
881
  maxBytes: effectiveMaxBytes,
867
882
  timeoutMs: clampTimeout(args.timeoutMs),
868
883
  secretValues: auth.secretValues,
884
+ quota: {
885
+ identity: quotaIdentity,
886
+ method,
887
+ target: describeProviderRequestTarget(pageUrl.href, auth.secretValues),
888
+ requestKey,
889
+ },
869
890
  });
870
891
  return {
871
892
  text: resp.text ??
@@ -890,6 +911,12 @@ export async function executeProviderApiRequest(args, runtime) {
890
911
  }
891
912
  // --- Single request ---
892
913
  const body = prepareBody(substituteUnknown(args.body, placeholders), headers);
914
+ const requestKey = createProviderRequestDedupeKey({
915
+ method,
916
+ url: url.href,
917
+ body,
918
+ headers,
919
+ });
893
920
  const response = await fetchWithTimeout(url.href, {
894
921
  method,
895
922
  headers,
@@ -897,6 +924,12 @@ export async function executeProviderApiRequest(args, runtime) {
897
924
  maxBytes: effectiveMaxBytes,
898
925
  timeoutMs: clampTimeout(args.timeoutMs),
899
926
  secretValues: auth.secretValues,
927
+ quota: {
928
+ identity: quotaIdentity,
929
+ method,
930
+ target: describeProviderRequestTarget(url.href, auth.secretValues),
931
+ requestKey,
932
+ },
900
933
  });
901
934
  // saveToFile: write full body to workspace file and return compact summary.
902
935
  if (args.saveToFile) {
@@ -978,6 +1011,14 @@ async function executeCustomProviderApiRequest(args, customConfig, runtime) {
978
1011
  const effectiveMaxBytes = args.saveToFile
979
1012
  ? SAVE_TO_FILE_MAX_BYTES
980
1013
  : clampMaxBytes(args.maxBytes);
1014
+ const quotaIdentity = createProviderQuotaIdentity({
1015
+ appId: runtimeOptionsAppId(runtime),
1016
+ providerId: customConfig.id,
1017
+ ctx,
1018
+ credentialSources: auth.credentialSources,
1019
+ connectionId: args.connectionId,
1020
+ accountId: args.accountId,
1021
+ });
981
1022
  // --- fetchAllPages mode (same cursor pagination as built-in providers) ---
982
1023
  if (args.fetchAllPages) {
983
1024
  const pageCfg = args.fetchAllPages;
@@ -995,6 +1036,12 @@ async function executeCustomProviderApiRequest(args, customConfig, runtime) {
995
1036
  ? setValueAtPath(args.body, extra.bodyCursor.path, extra.bodyCursor.value)
996
1037
  : args.body;
997
1038
  const pageBody = prepareBody(bodyWithCursor, { ...headers });
1039
+ const requestKey = createProviderRequestDedupeKey({
1040
+ method,
1041
+ url: pageUrl.href,
1042
+ body: pageBody,
1043
+ headers,
1044
+ });
998
1045
  const resp = await fetchWithTimeout(pageUrl.href, {
999
1046
  method,
1000
1047
  headers,
@@ -1002,6 +1049,12 @@ async function executeCustomProviderApiRequest(args, customConfig, runtime) {
1002
1049
  maxBytes: effectiveMaxBytes,
1003
1050
  timeoutMs: clampTimeout(args.timeoutMs),
1004
1051
  secretValues: auth.secretValues,
1052
+ quota: {
1053
+ identity: quotaIdentity,
1054
+ method,
1055
+ target: describeProviderRequestTarget(pageUrl.href, auth.secretValues),
1056
+ requestKey,
1057
+ },
1005
1058
  });
1006
1059
  return {
1007
1060
  text: resp.text ??
@@ -1035,6 +1088,17 @@ async function executeCustomProviderApiRequest(args, customConfig, runtime) {
1035
1088
  maxBytes: effectiveMaxBytes,
1036
1089
  timeoutMs: clampTimeout(args.timeoutMs),
1037
1090
  secretValues: auth.secretValues,
1091
+ quota: {
1092
+ identity: quotaIdentity,
1093
+ method,
1094
+ target: describeProviderRequestTarget(url.href, auth.secretValues),
1095
+ requestKey: createProviderRequestDedupeKey({
1096
+ method,
1097
+ url: url.href,
1098
+ body,
1099
+ headers,
1100
+ }),
1101
+ },
1038
1102
  });
1039
1103
  if (args.saveToFile) {
1040
1104
  const rawText = response.text ??
@@ -1857,52 +1921,108 @@ function prepareBody(body, headers) {
1857
1921
  headers["Content-Type"] = "application/json";
1858
1922
  return JSON.stringify(body);
1859
1923
  }
1924
+ function runtimeOptionsAppId(runtime) {
1925
+ return runtime.appId || "app";
1926
+ }
1860
1927
  async function fetchWithTimeout(optionsUrl, options) {
1861
- const controller = new AbortController();
1862
- const timeoutMs = clampTimeout(options.timeoutMs);
1863
- const timeout = setTimeout(() => controller.abort(), timeoutMs);
1864
- const method = options.method ?? "GET";
1865
- const secretValues = options.secretValues ?? [];
1866
- try {
1867
- const dispatcher = (await createSsrfSafeDispatcher()) ?? undefined;
1868
- const fetchOptions = {
1869
- method,
1870
- headers: options.headers,
1871
- body: options.body,
1872
- signal: controller.signal,
1873
- redirect: "manual",
1874
- };
1875
- if (dispatcher)
1876
- fetchOptions.dispatcher = dispatcher;
1928
+ const runOnce = async () => {
1929
+ const controller = new AbortController();
1930
+ const timeoutMs = clampTimeout(options.timeoutMs);
1931
+ const timeout = setTimeout(() => controller.abort(), timeoutMs);
1932
+ const method = options.method ?? "GET";
1933
+ const secretValues = options.secretValues ?? [];
1877
1934
  try {
1878
- return await fetchProviderResponse(optionsUrl, fetchOptions, {
1879
- maxBytes: options.maxBytes,
1880
- secretValues,
1881
- });
1882
- }
1883
- catch (error) {
1884
- if (dispatcher && isDispatcherCompatibilityError(error)) {
1885
- const fallbackOptions = { ...fetchOptions };
1886
- delete fallbackOptions.dispatcher;
1887
- return await fetchProviderResponse(optionsUrl, fallbackOptions, {
1935
+ const dispatcher = (await createSsrfSafeDispatcher()) ?? undefined;
1936
+ const fetchOptions = {
1937
+ method,
1938
+ headers: options.headers,
1939
+ body: options.body,
1940
+ signal: controller.signal,
1941
+ redirect: "manual",
1942
+ };
1943
+ if (dispatcher)
1944
+ fetchOptions.dispatcher = dispatcher;
1945
+ try {
1946
+ return await fetchProviderResponse(optionsUrl, fetchOptions, {
1888
1947
  maxBytes: options.maxBytes,
1889
1948
  secretValues,
1890
1949
  });
1891
1950
  }
1892
- throw error;
1951
+ catch (error) {
1952
+ if (dispatcher && isDispatcherCompatibilityError(error)) {
1953
+ const fallbackOptions = { ...fetchOptions };
1954
+ delete fallbackOptions.dispatcher;
1955
+ return await fetchProviderResponse(optionsUrl, fallbackOptions, {
1956
+ maxBytes: options.maxBytes,
1957
+ secretValues,
1958
+ });
1959
+ }
1960
+ throw error;
1961
+ }
1893
1962
  }
1894
- }
1895
- catch (error) {
1896
- throw normalizeFetchError(error, {
1897
- method,
1898
- url: optionsUrl,
1899
- timeoutMs,
1900
- secretValues,
1963
+ catch (error) {
1964
+ throw normalizeFetchError(error, {
1965
+ method,
1966
+ url: optionsUrl,
1967
+ timeoutMs,
1968
+ secretValues,
1969
+ });
1970
+ }
1971
+ finally {
1972
+ clearTimeout(timeout);
1973
+ }
1974
+ };
1975
+ if (options.quota) {
1976
+ return executeWithProviderQuota({
1977
+ request: {
1978
+ identity: options.quota.identity,
1979
+ method: options.quota.method,
1980
+ target: options.quota.target,
1981
+ requestKey: options.quota.requestKey,
1982
+ },
1983
+ execute: runOnce,
1984
+ inspect: (result) => ({
1985
+ status: result.status,
1986
+ headers: result.headers,
1987
+ }),
1988
+ buildQuotaExhaustedResult: providerQuotaExhaustedResponse,
1901
1989
  });
1902
1990
  }
1903
- finally {
1904
- clearTimeout(timeout);
1905
- }
1991
+ return runOnce();
1992
+ }
1993
+ function providerQuotaExhaustedResponse(detail) {
1994
+ const retryAfterSeconds = Math.max(0, Math.ceil(detail.retryAfterMs / 1000));
1995
+ return {
1996
+ status: 429,
1997
+ statusText: "Provider quota cooldown",
1998
+ ok: false,
1999
+ elapsedMs: 0,
2000
+ headers: {
2001
+ "retry-after": String(retryAfterSeconds),
2002
+ "x-agent-native-provider-quota": "exhausted",
2003
+ },
2004
+ contentType: "application/json",
2005
+ size: 0,
2006
+ truncated: false,
2007
+ json: {
2008
+ error: "provider_quota_exhausted",
2009
+ provider: detail.providerId,
2010
+ message: `Provider API quota is cooling down for ${detail.providerId}. ` +
2011
+ `Retry after ${detail.retryAt}.`,
2012
+ retryAt: detail.retryAt,
2013
+ retryAfterMs: detail.retryAfterMs,
2014
+ reason: detail.reason,
2015
+ method: detail.method,
2016
+ target: detail.target,
2017
+ },
2018
+ quota: {
2019
+ exhausted: true,
2020
+ providerId: detail.providerId,
2021
+ retryAfterMs: detail.retryAfterMs,
2022
+ retryAt: detail.retryAt,
2023
+ reason: detail.reason,
2024
+ },
2025
+ };
1906
2026
  }
1907
2027
  async function fetchProviderResponse(url, fetchOptions, options) {
1908
2028
  const startedAt = Date.now();