@mastra/factory 0.24.0-alpha.6 → 0.24.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/boards/review.d.ts.map +1 -1
- package/dist/boards/review.js +21 -1
- package/dist/boards/review.js.map +1 -1
- package/dist/boards/work-transition-policy.d.ts.map +1 -1
- package/dist/boards/work-transition-policy.js +2 -1
- package/dist/boards/work-transition-policy.js.map +1 -1
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +103 -19
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +26 -22
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +2 -3
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +78 -7
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +28 -21
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/slack/integration.d.ts.map +1 -1
- package/dist/integrations/slack/integration.js +33 -6
- package/dist/integrations/slack/integration.js.map +1 -1
- package/dist/integrations/slack/slack.d.ts.map +1 -1
- package/dist/integrations/slack/slack.js +25 -24
- package/dist/integrations/slack/slack.js.map +1 -1
- package/dist/routes/config.d.ts +37 -2
- package/dist/routes/config.d.ts.map +1 -1
- package/dist/routes/config.js +83 -41
- package/dist/routes/config.js.map +1 -1
- package/dist/routes/custom-provider-source.d.ts +8 -0
- package/dist/routes/custom-provider-source.d.ts.map +1 -1
- package/dist/routes/custom-provider-source.js +22 -1
- package/dist/routes/custom-provider-source.js.map +1 -1
- package/dist/routes/provider-credentials.d.ts +2 -1
- package/dist/routes/provider-credentials.d.ts.map +1 -1
- package/dist/routes/provider-credentials.js +6 -2
- package/dist/routes/provider-credentials.js.map +1 -1
- package/dist/routes/surface.js +1 -1
- package/dist/routes/work-items.js +2 -2
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +12 -0
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +42 -3
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/session/channel-reply-processor.d.ts +35 -0
- package/dist/session/channel-reply-processor.d.ts.map +1 -0
- package/dist/session/channel-reply-processor.js +46 -0
- package/dist/session/channel-reply-processor.js.map +1 -0
- package/dist/session/channel-session-link-processor.d.ts +39 -0
- package/dist/session/channel-session-link-processor.d.ts.map +1 -0
- package/dist/session/channel-session-link-processor.js +99 -0
- package/dist/session/channel-session-link-processor.js.map +1 -0
- package/dist/session/factory-session.d.ts +4 -0
- package/dist/session/factory-session.d.ts.map +1 -1
- package/dist/session/factory-session.js +1 -0
- package/dist/session/factory-session.js.map +1 -1
- package/dist/session/reply-credential-processor.d.ts.map +1 -1
- package/dist/session/reply-credential-processor.js +4 -6
- package/dist/session/reply-credential-processor.js.map +1 -1
- package/dist/session/run-audit.d.ts +24 -0
- package/dist/session/run-audit.d.ts.map +1 -1
- package/dist/session/run-audit.js +93 -7
- package/dist/session/run-audit.js.map +1 -1
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/storage/domains/source-control/base.d.ts +7 -0
- package/dist/storage/domains/source-control/base.d.ts.map +1 -1
- package/dist/storage/domains/source-control/base.js +12 -0
- package/dist/storage/domains/source-control/base.js.map +1 -1
- package/dist/storage/domains/source-control/inmemory.d.ts +4 -0
- package/dist/storage/domains/source-control/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/source-control/inmemory.js +8 -0
- package/dist/storage/domains/source-control/inmemory.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +2 -2
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +5 -0
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/tools/approval-tools.d.ts +1 -1
- package/dist/tools/approval-tools.d.ts.map +1 -1
- package/dist/tools/approval-tools.js +3 -1
- package/dist/tools/approval-tools.js.map +1 -1
- package/dist/tools/deliver.d.ts +16 -2
- package/dist/tools/deliver.d.ts.map +1 -1
- package/dist/tools/deliver.js +12 -2
- package/dist/tools/deliver.js.map +1 -1
- package/dist/tools/index.d.ts +6 -5
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +9 -12
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/messaging-tools.d.ts +1 -1
- package/dist/tools/messaging-tools.d.ts.map +1 -1
- package/dist/tools/messaging-tools.js +84 -3
- package/dist/tools/messaging-tools.js.map +1 -1
- package/dist/tools/permissions.d.ts.map +1 -1
- package/dist/tools/permissions.js +3 -0
- package/dist/tools/permissions.js.map +1 -1
- package/dist/tools/read-tools.d.ts +3 -0
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +16 -8
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/reports.d.ts.map +1 -1
- package/dist/tools/reports.js +3 -1
- package/dist/tools/reports.js.map +1 -1
- package/dist/tools/scope.d.ts +6 -0
- package/dist/tools/scope.d.ts.map +1 -1
- package/dist/tools/scope.js +10 -1
- package/dist/tools/scope.js.map +1 -1
- package/dist/tools/session-tools.d.ts +14 -2
- package/dist/tools/session-tools.d.ts.map +1 -1
- package/dist/tools/session-tools.js +69 -9
- package/dist/tools/session-tools.js.map +1 -1
- package/dist/tools/sessions-state-processor.d.ts +5 -1
- package/dist/tools/sessions-state-processor.d.ts.map +1 -1
- package/dist/tools/sessions-state-processor.js +32 -48
- package/dist/tools/sessions-state-processor.js.map +1 -1
- package/dist/tools/side-sessions.d.ts +53 -0
- package/dist/tools/side-sessions.d.ts.map +1 -0
- package/dist/tools/side-sessions.js +83 -0
- package/dist/tools/side-sessions.js.map +1 -0
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +46 -26
- package/dist/tools/work-item-tools.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { factoryUserOrgId } from "../auth.js";
|
|
2
|
+
import { providerDisplayName } from "../provider-display-name.js";
|
|
2
3
|
import { getCredentialProviderId as getAuthProviderId } from "@mastra/code-sdk/providers/model-ids";
|
|
3
4
|
//#region src/routes/provider-credentials.ts
|
|
4
5
|
/**
|
|
@@ -6,7 +7,7 @@ import { getCredentialProviderId as getAuthProviderId } from "@mastra/code-sdk/p
|
|
|
6
7
|
* *catalog* provider id (what the routes and settings UI use). All flows need
|
|
7
8
|
* no inbound connection to the server: Anthropic uses paste-code PKCE, the
|
|
8
9
|
* rest use RFC 8628-style device codes. `subscription` names the plan the
|
|
9
|
-
* sign-in bills, as shown under a reply.
|
|
10
|
+
* sign-in bills, as shown under a reply and in the composer.
|
|
10
11
|
*/
|
|
11
12
|
const WEB_OAUTH_PROVIDERS = {
|
|
12
13
|
anthropic: {
|
|
@@ -26,6 +27,9 @@ const WEB_OAUTH_PROVIDERS = {
|
|
|
26
27
|
subscription: "SuperGrok/X Premium+"
|
|
27
28
|
}
|
|
28
29
|
};
|
|
30
|
+
function credentialLabel(provider, credentialType) {
|
|
31
|
+
return credentialType === "api_key" ? `${providerDisplayName(provider)} API key` : WEB_OAUTH_PROVIDERS[provider]?.subscription;
|
|
32
|
+
}
|
|
29
33
|
/**
|
|
30
34
|
* The tenant credentials domain, when registered and ready. `undefined` means
|
|
31
35
|
* the factory never ran (no handle threaded in) or the domain's init failed
|
|
@@ -88,6 +92,6 @@ async function listTenantCredentialsForRequest({ c, auth, credentials }) {
|
|
|
88
92
|
return storage.listCredentials(tenantOrgId(tenant), tenant.userId);
|
|
89
93
|
}
|
|
90
94
|
//#endregion
|
|
91
|
-
export { WEB_OAUTH_PROVIDERS, getAuthProviderId, getTenantCredentialsStorage, listTenantCredentialsForRequest, resolveCredentialContext, tenantOrgId };
|
|
95
|
+
export { WEB_OAUTH_PROVIDERS, credentialLabel, getAuthProviderId, getTenantCredentialsStorage, listTenantCredentialsForRequest, resolveCredentialContext, tenantOrgId };
|
|
92
96
|
|
|
93
97
|
//# sourceMappingURL=provider-credentials.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-credentials.js","names":[],"sources":["../../src/routes/provider-credentials.ts"],"sourcesContent":["/**\n * Per-request model-provider credential context.\n *\n * The provider config/OAuth routes serve two deployment shapes:\n *\n * - **Local** (no web auth adapter): credentials live in the server-global\n * file-backed `AuthStorage` (`auth.json`) — unchanged TUI behavior.\n * - **Tenant** (auth adapter active): credentials live in the\n * `model-credentials` factory storage domain, scoped per `(orgId, userId)`\n * with optional org-wide rows (`userId` absent).\n *\n * `resolveCredentialContext` decides which shape a request is in: an\n * authenticated user always gets the tenant path; an unauthenticated request\n * is rejected when auth is enabled and falls back to local otherwise.\n */\n\nimport type { Context } from 'hono';\n\nimport { factoryUserOrgId } from '../auth.js';\nimport type {\n CredentialRecord,\n LoginSessionKind,\n ModelCredentialsStorage,\n} from '../storage/domains/credentials/base.js';\nimport type { RouteAuth } from './route.js';\n\n/**\n * OAuth credentials are stored under the credential id, which differs from the\n * catalog provider id for OpenAI (`openai-codex`) and Kimi (`kimi-for-coding`).\n * Tenant rows use the same keying so one lookup serves both OAuth tokens and\n * API keys, and match what model resolution reads.\n */\nexport { getCredentialProviderId as getAuthProviderId } from '@mastra/code-sdk/providers/model-ids';\n\n/**\n * Providers that support a browser-driven OAuth sign-in flow, keyed by\n * *catalog* provider id (what the routes and settings UI use). All flows need\n * no inbound connection to the server: Anthropic uses paste-code PKCE, the\n * rest use RFC 8628-style device codes. `subscription` names the plan the\n * sign-in bills, as shown under a reply.\n */\nexport const WEB_OAUTH_PROVIDERS: Readonly<Record<string, { flow: LoginSessionKind; subscription: string }>> = {\n anthropic: { flow: 'paste-code', subscription: 'Claude Pro/Max' },\n openai: { flow: 'device-code', subscription: 'ChatGPT Plus/Pro' },\n 'github-copilot': { flow: 'device-code', subscription: 'GitHub Copilot' },\n xai: { flow: 'device-code', subscription: 'SuperGrok/X Premium+' },\n};\n\nexport type CredentialContext =\n | { mode: 'local' }\n | { mode: 'tenant'; storage: ModelCredentialsStorage; orgId: string; userId: string };\n\n/**\n * The tenant credentials domain, when registered and ready. `undefined` means\n * the factory never ran (no handle threaded in) or the domain's init failed\n * (fail-soft — callers report the feature unavailable instead of crashing).\n */\nexport async function getTenantCredentialsStorage(\n credentials: ModelCredentialsStorage | undefined,\n): Promise<ModelCredentialsStorage | undefined> {\n if (!credentials) return undefined;\n try {\n await credentials.ensureReady();\n } catch {\n return undefined;\n }\n return credentials;\n}\n\n/**\n * Org key for tenant rows. Personal accounts get an org bootstrapped by the\n * auth adapter (`ensureOrg`); if one still isn't present, scope rows under a\n * per-user synthetic org so credentials never become server-global.\n */\nexport function tenantOrgId(tenant: { orgId?: string; userId: string }): string {\n return tenant.orgId ?? factoryUserOrgId({ id: tenant.userId }) ?? `user:${tenant.userId}`;\n}\n\n/**\n * Resolve the credential context for a request, or a ready-to-return error\n * response. Mutating credential routes call this and hard-fail (401/503)\n * when the tenant path is required but unavailable.\n */\nexport async function resolveCredentialContext({\n c,\n auth,\n credentials,\n}: {\n c: Context;\n auth: RouteAuth;\n /** Tenant credential domain handle; absent in local (no-DB) mode. */\n credentials?: ModelCredentialsStorage;\n}): Promise<CredentialContext | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) {\n // When an auth provider is active, credential operations always require a\n // signed-in caller — otherwise one anonymous request could write keys for\n // everyone. Without a provider this is a single-user local server.\n if (auth.enabled()) return { response: c.json({ error: 'unauthorized' }, 401) };\n return { mode: 'local' };\n }\n const storage = await getTenantCredentialsStorage(credentials);\n if (!storage) {\n return {\n response: c.json(\n {\n error: 'credentials_unavailable',\n message: 'Tenant credential storage is unavailable — the app database is not configured or failed to start.',\n },\n 503,\n ),\n };\n }\n return { mode: 'tenant', storage, orgId: tenantOrgId(tenant), userId: tenant.userId };\n}\n\n/**\n * List the caller's tenant credential records for provider listing, or\n * `undefined` in local mode (caller should fall back to `AuthStorage`).\n * Read-only and degradation-friendly: an authenticated caller with the domain\n * unavailable gets an empty list (sources show `env`/`none`) instead of a 503\n * so the settings page still renders.\n */\nexport async function listTenantCredentialsForRequest({\n c,\n auth,\n credentials,\n}: {\n c: Context;\n auth: RouteAuth;\n /** Tenant credential domain handle; absent in local (no-DB) mode. */\n credentials?: ModelCredentialsStorage;\n}): Promise<CredentialRecord[] | undefined> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return auth.enabled() ? [] : undefined;\n const storage = await getTenantCredentialsStorage(credentials);\n if (!storage) return [];\n return storage.listCredentials(tenantOrgId(tenant), tenant.userId);\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"provider-credentials.js","names":[],"sources":["../../src/routes/provider-credentials.ts"],"sourcesContent":["/**\n * Per-request model-provider credential context.\n *\n * The provider config/OAuth routes serve two deployment shapes:\n *\n * - **Local** (no web auth adapter): credentials live in the server-global\n * file-backed `AuthStorage` (`auth.json`) — unchanged TUI behavior.\n * - **Tenant** (auth adapter active): credentials live in the\n * `model-credentials` factory storage domain, scoped per `(orgId, userId)`\n * with optional org-wide rows (`userId` absent).\n *\n * `resolveCredentialContext` decides which shape a request is in: an\n * authenticated user always gets the tenant path; an unauthenticated request\n * is rejected when auth is enabled and falls back to local otherwise.\n */\n\nimport type { Context } from 'hono';\n\nimport { factoryUserOrgId } from '../auth.js';\nimport { providerDisplayName } from '../provider-display-name.js';\nimport type {\n CredentialRecord,\n LoginSessionKind,\n ModelCredentialsStorage,\n} from '../storage/domains/credentials/base.js';\nimport type { RouteAuth } from './route.js';\n\n/**\n * OAuth credentials are stored under the credential id, which differs from the\n * catalog provider id for OpenAI (`openai-codex`) and Kimi (`kimi-for-coding`).\n * Tenant rows use the same keying so one lookup serves both OAuth tokens and\n * API keys, and match what model resolution reads.\n */\nexport { getCredentialProviderId as getAuthProviderId } from '@mastra/code-sdk/providers/model-ids';\n\n/**\n * Providers that support a browser-driven OAuth sign-in flow, keyed by\n * *catalog* provider id (what the routes and settings UI use). All flows need\n * no inbound connection to the server: Anthropic uses paste-code PKCE, the\n * rest use RFC 8628-style device codes. `subscription` names the plan the\n * sign-in bills, as shown under a reply and in the composer.\n */\nexport const WEB_OAUTH_PROVIDERS: Readonly<Record<string, { flow: LoginSessionKind; subscription: string }>> = {\n anthropic: { flow: 'paste-code', subscription: 'Claude Pro/Max' },\n openai: { flow: 'device-code', subscription: 'ChatGPT Plus/Pro' },\n 'github-copilot': { flow: 'device-code', subscription: 'GitHub Copilot' },\n xai: { flow: 'device-code', subscription: 'SuperGrok/X Premium+' },\n};\n\nexport function credentialLabel(provider: string, credentialType: CredentialRecord['credential']['type']) {\n return credentialType === 'api_key'\n ? `${providerDisplayName(provider)} API key`\n : WEB_OAUTH_PROVIDERS[provider]?.subscription;\n}\n\nexport type CredentialContext =\n | { mode: 'local' }\n | { mode: 'tenant'; storage: ModelCredentialsStorage; orgId: string; userId: string };\n\n/**\n * The tenant credentials domain, when registered and ready. `undefined` means\n * the factory never ran (no handle threaded in) or the domain's init failed\n * (fail-soft — callers report the feature unavailable instead of crashing).\n */\nexport async function getTenantCredentialsStorage(\n credentials: ModelCredentialsStorage | undefined,\n): Promise<ModelCredentialsStorage | undefined> {\n if (!credentials) return undefined;\n try {\n await credentials.ensureReady();\n } catch {\n return undefined;\n }\n return credentials;\n}\n\n/**\n * Org key for tenant rows. Personal accounts get an org bootstrapped by the\n * auth adapter (`ensureOrg`); if one still isn't present, scope rows under a\n * per-user synthetic org so credentials never become server-global.\n */\nexport function tenantOrgId(tenant: { orgId?: string; userId: string }): string {\n return tenant.orgId ?? factoryUserOrgId({ id: tenant.userId }) ?? `user:${tenant.userId}`;\n}\n\n/**\n * Resolve the credential context for a request, or a ready-to-return error\n * response. Mutating credential routes call this and hard-fail (401/503)\n * when the tenant path is required but unavailable.\n */\nexport async function resolveCredentialContext({\n c,\n auth,\n credentials,\n}: {\n c: Context;\n auth: RouteAuth;\n /** Tenant credential domain handle; absent in local (no-DB) mode. */\n credentials?: ModelCredentialsStorage;\n}): Promise<CredentialContext | { response: Response }> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) {\n // When an auth provider is active, credential operations always require a\n // signed-in caller — otherwise one anonymous request could write keys for\n // everyone. Without a provider this is a single-user local server.\n if (auth.enabled()) return { response: c.json({ error: 'unauthorized' }, 401) };\n return { mode: 'local' };\n }\n const storage = await getTenantCredentialsStorage(credentials);\n if (!storage) {\n return {\n response: c.json(\n {\n error: 'credentials_unavailable',\n message: 'Tenant credential storage is unavailable — the app database is not configured or failed to start.',\n },\n 503,\n ),\n };\n }\n return { mode: 'tenant', storage, orgId: tenantOrgId(tenant), userId: tenant.userId };\n}\n\n/**\n * List the caller's tenant credential records for provider listing, or\n * `undefined` in local mode (caller should fall back to `AuthStorage`).\n * Read-only and degradation-friendly: an authenticated caller with the domain\n * unavailable gets an empty list (sources show `env`/`none`) instead of a 503\n * so the settings page still renders.\n */\nexport async function listTenantCredentialsForRequest({\n c,\n auth,\n credentials,\n}: {\n c: Context;\n auth: RouteAuth;\n /** Tenant credential domain handle; absent in local (no-DB) mode. */\n credentials?: ModelCredentialsStorage;\n}): Promise<CredentialRecord[] | undefined> {\n await auth.ensureUser(c);\n const tenant = auth.tenant(c);\n if (!tenant) return auth.enabled() ? [] : undefined;\n const storage = await getTenantCredentialsStorage(credentials);\n if (!storage) return [];\n return storage.listCredentials(tenantOrgId(tenant), tenant.userId);\n}\n"],"mappings":";;;;;;;;;;;AA0CA,MAAa,sBAAkG;CAC7G,WAAW;EAAE,MAAM;EAAc,cAAc;CAAiB;CAChE,QAAQ;EAAE,MAAM;EAAe,cAAc;CAAmB;CAChE,kBAAkB;EAAE,MAAM;EAAe,cAAc;CAAiB;CACxE,KAAK;EAAE,MAAM;EAAe,cAAc;CAAuB;AACnE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face.js
CHANGED
|
@@ -9,10 +9,10 @@ import { invalidateTenantCredentialSnapshots } from "./tenant-credentials.js";
|
|
|
9
9
|
import { effectiveModelScope } from "../storage/domains/projects/base.js";
|
|
10
10
|
import { SessionOwnershipMismatchError, SourceControlConnectionNotFoundError } from "../storage/domains/source-control/base.js";
|
|
11
11
|
import { FactorySourceSessionResolutionError, createSourceControlSessionLookup, ensureFactorySourceSession, resolveFactorySourceControl } from "../session/factory-session.js";
|
|
12
|
+
import { ConfigRoutes } from "./config.js";
|
|
12
13
|
import { buildSourceControlSessionRoutes } from "./source-control-sessions.js";
|
|
13
14
|
import { resolveWorkItemRepository } from "../session/work-item-repository.js";
|
|
14
15
|
import { FactoryStartCoordinator } from "../rules/start-coordinator.js";
|
|
15
|
-
import { ConfigRoutes } from "./config.js";
|
|
16
16
|
import { invalidateCustomProvidersSnapshots } from "./custom-provider-source.js";
|
|
17
17
|
import { FactoryTransitionService } from "../rules/transition-service.js";
|
|
18
18
|
import { buildAutomationRunRoutes } from "./automation-runs.js";
|
|
@@ -4,13 +4,13 @@ import { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, FACTORY_RULE_MATERIALIZATION_K
|
|
|
4
4
|
import { EXTERNAL_SOURCE_MISSING_KEY } from "../integrations/issue-reconciler.js";
|
|
5
5
|
import { effectiveModelScope } from "../storage/domains/projects/base.js";
|
|
6
6
|
import { decisionRetryable, overtakenDecisionIds } from "../rules/decision-applicability.js";
|
|
7
|
-
import { FactoryStartTransitionError, WorkItemRepositoryError } from "../rules/start-coordinator.js";
|
|
8
7
|
import { FACTORY_ROUTE_CONTRACTS } from "./contracts.js";
|
|
8
|
+
import { Route } from "./route.js";
|
|
9
|
+
import { FactoryStartTransitionError, WorkItemRepositoryError } from "../rules/start-coordinator.js";
|
|
9
10
|
import { createFactoryWorkItem } from "../work-items/create-work-item.js";
|
|
10
11
|
import { factoryDecisionType } from "./attention-providers.js";
|
|
11
12
|
import { buildAttentionRoutes } from "./attention.js";
|
|
12
13
|
import { resolveFactoryProposal, retryFactoryDecision } from "../work-items/decision-actions.js";
|
|
13
|
-
import { Route } from "./route.js";
|
|
14
14
|
import { auditRequestOrigin } from "../storage/domains/audit/domain.js";
|
|
15
15
|
import { thresholdsOrDefault } from "../storage/domains/queue-health/base.js";
|
|
16
16
|
import { computeFactoryMetrics, parseMetricsRange } from "../storage/domains/work-items/metrics.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-errors.d.ts","sourceRoot":"","sources":["../../src/rules/dispatch-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,gCAAgC,EACjC,MAAM,uCAAuC,CAAC;AAE/C,UAAU,8BAA8B;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"dispatch-errors.d.ts","sourceRoot":"","sources":["../../src/rules/dispatch-errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0BAA0B,EAC1B,gCAAgC,EACjC,MAAM,uCAAuC,CAAC;AAE/C,UAAU,8BAA8B;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AA+BD,qBAAa,oBAAqB,SAAQ,KAAK;IAE3C,QAAQ,CAAC,IAAI,EAAE,0BAA0B;gBAAhC,IAAI,EAAE,0BAA0B,EACzC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,YAAY;CAKzB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,0BAA0B,CAErF;AAED,wBAAgB,8BAA8B,CAC5C,IAAI,EAAE,gCAAgC,GAAG,IAAI,GAC5C,8BAA8B,CAEhC"}
|
|
@@ -72,6 +72,18 @@ const FAILURE_METADATA = {
|
|
|
72
72
|
canRetry: false,
|
|
73
73
|
label: "Run configuration rejected by provider"
|
|
74
74
|
},
|
|
75
|
+
run_credentials_unavailable: {
|
|
76
|
+
canRetry: true,
|
|
77
|
+
label: "Model credentials unavailable for the run"
|
|
78
|
+
},
|
|
79
|
+
run_user_unauthenticated: {
|
|
80
|
+
canRetry: false,
|
|
81
|
+
label: "Run started without an authenticated user"
|
|
82
|
+
},
|
|
83
|
+
run_failed: {
|
|
84
|
+
canRetry: true,
|
|
85
|
+
label: "Agent run ended in error"
|
|
86
|
+
},
|
|
75
87
|
unknown: {
|
|
76
88
|
canRetry: true,
|
|
77
89
|
label: "Factory automation failed"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatch-errors.js","names":[],"sources":["../../src/rules/dispatch-errors.ts"],"sourcesContent":["import type {\n FactoryDispatchFailureCode,\n StoredFactoryDispatchFailureCode,\n} from '../storage/domains/work-items/base.js';\n\ninterface FactoryDispatchFailureMetadata {\n canRetry: boolean;\n label: string;\n}\n\nconst FAILURE_METADATA = {\n session_unavailable: { canRetry: true, label: 'Factory session unavailable' },\n source_control_missing: { canRetry: true, label: 'Source-control connection unavailable' },\n source_repository_missing: { canRetry: true, label: 'Source repository unavailable' },\n source_repository_ambiguous: { canRetry: true, label: 'Choose a repository for this work item' },\n unsupported_provider_item: { canRetry: false, label: 'Unsupported provider work item' },\n notification_delivery_failed: { canRetry: true, label: 'Factory message delivery failed' },\n run_terminal_event_missing: { canRetry: false, label: 'Agent run terminal event was not observed' },\n skill_delivery_ambiguous: { canRetry: false, label: 'Factory skill delivery could not be confirmed' },\n run_overdue: { canRetry: false, label: 'Agent run is overdue' },\n repository_git_missing: { canRetry: false, label: 'Git is unavailable in the workspace' },\n repository_egress_blocked: { canRetry: false, label: 'Repository network access is blocked' },\n repository_clone_failed: { canRetry: true, label: 'Repository clone failed' },\n repository_pull_failed: { canRetry: true, label: 'Repository update failed' },\n repository_push_failed: { canRetry: true, label: 'Repository push failed' },\n repository_commit_failed: { canRetry: true, label: 'Repository commit failed' },\n repository_cli_missing: { canRetry: false, label: 'GitHub CLI is unavailable in the workspace' },\n repository_pr_failed: { canRetry: true, label: 'Pull request creation failed' },\n run_configuration_invalid: { canRetry: false, label: 'Run configuration rejected by provider' },\n unknown: { canRetry: true, label: 'Factory automation failed' },\n // Retired: no path writes these any more, stored rows still read through here.\n plan_awaiting_approval: { canRetry: false, label: 'Plan waiting for review' },\n run_awaiting_input: { canRetry: false, label: 'Agent is waiting for an answer' },\n} satisfies Record<StoredFactoryDispatchFailureCode, FactoryDispatchFailureMetadata>;\n\nexport class FactoryDispatchError extends Error {\n constructor(\n readonly code: FactoryDispatchFailureCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = 'FactoryDispatchError';\n }\n}\n\nexport function factoryDispatchFailureCode(error: unknown): FactoryDispatchFailureCode {\n return error instanceof FactoryDispatchError ? error.code : 'unknown';\n}\n\nexport function factoryDispatchFailureMetadata(\n code: StoredFactoryDispatchFailureCode | null,\n): FactoryDispatchFailureMetadata {\n return code === null ? FAILURE_METADATA.unknown : FAILURE_METADATA[code];\n}\n"],"mappings":";AAUA,MAAM,mBAAmB;CACvB,qBAAqB;EAAE,UAAU;EAAM,OAAO;CAA8B;CAC5E,wBAAwB;EAAE,UAAU;EAAM,OAAO;CAAwC;CACzF,2BAA2B;EAAE,UAAU;EAAM,OAAO;CAAgC;CACpF,6BAA6B;EAAE,UAAU;EAAM,OAAO;CAAyC;CAC/F,2BAA2B;EAAE,UAAU;EAAO,OAAO;CAAiC;CACtF,8BAA8B;EAAE,UAAU;EAAM,OAAO;CAAkC;CACzF,4BAA4B;EAAE,UAAU;EAAO,OAAO;CAA4C;CAClG,0BAA0B;EAAE,UAAU;EAAO,OAAO;CAAgD;CACpG,aAAa;EAAE,UAAU;EAAO,OAAO;CAAuB;CAC9D,wBAAwB;EAAE,UAAU;EAAO,OAAO;CAAsC;CACxF,2BAA2B;EAAE,UAAU;EAAO,OAAO;CAAuC;CAC5F,yBAAyB;EAAE,UAAU;EAAM,OAAO;CAA0B;CAC5E,wBAAwB;EAAE,UAAU;EAAM,OAAO;CAA2B;CAC5E,wBAAwB;EAAE,UAAU;EAAM,OAAO;CAAyB;CAC1E,0BAA0B;EAAE,UAAU;EAAM,OAAO;CAA2B;CAC9E,wBAAwB;EAAE,UAAU;EAAO,OAAO;CAA6C;CAC/F,sBAAsB;EAAE,UAAU;EAAM,OAAO;CAA+B;CAC9E,2BAA2B;EAAE,UAAU;EAAO,OAAO;CAAyC;CAC9F,SAAS;EAAE,UAAU;EAAM,OAAO;CAA4B;CAE9D,wBAAwB;EAAE,UAAU;EAAO,OAAO;CAA0B;CAC5E,oBAAoB;EAAE,UAAU;EAAO,OAAO;CAAiC;AACjF;AAEA,IAAa,uBAAb,cAA0C,MAAM;CAEnC;CADX,YACE,MACA,SACA,SACA;EACA,MAAM,SAAS,OAAO;EAJb,KAAA,OAAA;EAKT,KAAK,OAAO;CACd;AACF;AAEA,SAAgB,2BAA2B,OAA4C;CACrF,OAAO,iBAAiB,uBAAuB,MAAM,OAAO;AAC9D;AAEA,SAAgB,+BACd,MACgC;CAChC,OAAO,SAAS,OAAO,iBAAiB,UAAU,iBAAiB;AACrE"}
|
|
1
|
+
{"version":3,"file":"dispatch-errors.js","names":[],"sources":["../../src/rules/dispatch-errors.ts"],"sourcesContent":["import type {\n FactoryDispatchFailureCode,\n StoredFactoryDispatchFailureCode,\n} from '../storage/domains/work-items/base.js';\n\ninterface FactoryDispatchFailureMetadata {\n canRetry: boolean;\n label: string;\n}\n\nconst FAILURE_METADATA = {\n session_unavailable: { canRetry: true, label: 'Factory session unavailable' },\n source_control_missing: { canRetry: true, label: 'Source-control connection unavailable' },\n source_repository_missing: { canRetry: true, label: 'Source repository unavailable' },\n source_repository_ambiguous: { canRetry: true, label: 'Choose a repository for this work item' },\n unsupported_provider_item: { canRetry: false, label: 'Unsupported provider work item' },\n notification_delivery_failed: { canRetry: true, label: 'Factory message delivery failed' },\n run_terminal_event_missing: { canRetry: false, label: 'Agent run terminal event was not observed' },\n skill_delivery_ambiguous: { canRetry: false, label: 'Factory skill delivery could not be confirmed' },\n run_overdue: { canRetry: false, label: 'Agent run is overdue' },\n repository_git_missing: { canRetry: false, label: 'Git is unavailable in the workspace' },\n repository_egress_blocked: { canRetry: false, label: 'Repository network access is blocked' },\n repository_clone_failed: { canRetry: true, label: 'Repository clone failed' },\n repository_pull_failed: { canRetry: true, label: 'Repository update failed' },\n repository_push_failed: { canRetry: true, label: 'Repository push failed' },\n repository_commit_failed: { canRetry: true, label: 'Repository commit failed' },\n repository_cli_missing: { canRetry: false, label: 'GitHub CLI is unavailable in the workspace' },\n repository_pr_failed: { canRetry: true, label: 'Pull request creation failed' },\n run_configuration_invalid: { canRetry: false, label: 'Run configuration rejected by provider' },\n run_credentials_unavailable: { canRetry: true, label: 'Model credentials unavailable for the run' },\n // The run's request carries no user, so every retry fails the same way; a person has to start it.\n run_user_unauthenticated: { canRetry: false, label: 'Run started without an authenticated user' },\n run_failed: { canRetry: true, label: 'Agent run ended in error' },\n unknown: { canRetry: true, label: 'Factory automation failed' },\n // Retired: no path writes these any more, stored rows still read through here.\n plan_awaiting_approval: { canRetry: false, label: 'Plan waiting for review' },\n run_awaiting_input: { canRetry: false, label: 'Agent is waiting for an answer' },\n} satisfies Record<StoredFactoryDispatchFailureCode, FactoryDispatchFailureMetadata>;\n\nexport class FactoryDispatchError extends Error {\n constructor(\n readonly code: FactoryDispatchFailureCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = 'FactoryDispatchError';\n }\n}\n\nexport function factoryDispatchFailureCode(error: unknown): FactoryDispatchFailureCode {\n return error instanceof FactoryDispatchError ? error.code : 'unknown';\n}\n\nexport function factoryDispatchFailureMetadata(\n code: StoredFactoryDispatchFailureCode | null,\n): FactoryDispatchFailureMetadata {\n return code === null ? FAILURE_METADATA.unknown : FAILURE_METADATA[code];\n}\n"],"mappings":";AAUA,MAAM,mBAAmB;CACvB,qBAAqB;EAAE,UAAU;EAAM,OAAO;CAA8B;CAC5E,wBAAwB;EAAE,UAAU;EAAM,OAAO;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9D;AAEA,SAAgB,+BACd,MACgC;CAChC,OAAO,SAAS,OAAO,iBAAiB,UAAU,iBAAiB;AACrE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/rules/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,+BAA+B,CAAC;AAU5G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAErF,OAAO,KAAK,EACV,6BAA6B,EAI7B,WAAW,EACX,gBAAgB,EAEjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAGjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAAK,EAAE,qBAAqB,EAA4C,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/rules/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,+BAA+B,CAAC;AAU5G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAExE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6CAA6C,CAAC;AAErF,OAAO,KAAK,EACV,6BAA6B,EAI7B,WAAW,EACX,gBAAgB,EAEjB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAA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, not succeeded. */
|
|
38
38
|
var FactoryDecisionSuperseded = class extends Error {};
|
|
39
39
|
/** A run that ran and ended in error; the session's own listener reports it to followers. */
|
|
40
|
-
var RunEndedInError = class extends
|
|
40
|
+
var RunEndedInError = class extends FactoryDispatchError {};
|
|
41
|
+
const CREDENTIAL_RESOLUTION_FAILURE = "tenant model credential policy could not be resolved";
|
|
42
|
+
const NO_AUTHENTICATED_USER = "the request has no authenticated user";
|
|
43
|
+
function httpStatus(error) {
|
|
44
|
+
if (!error || typeof error !== "object") return void 0;
|
|
45
|
+
if ("statusCode" in error && typeof error.statusCode === "number") return error.statusCode;
|
|
46
|
+
return "status" in error && typeof error.status === "number" ? error.status : void 0;
|
|
47
|
+
}
|
|
48
|
+
function causeOf(error) {
|
|
49
|
+
return error && typeof error === "object" && "cause" in error ? error.cause : void 0;
|
|
50
|
+
}
|
|
51
|
+
function runErrorCode(error, message) {
|
|
52
|
+
const lower = message.toLowerCase();
|
|
53
|
+
if (lower.includes(CREDENTIAL_RESOLUTION_FAILURE)) return lower.includes(NO_AUTHENTICATED_USER) ? "run_user_unauthenticated" : "run_credentials_unavailable";
|
|
54
|
+
const status = httpStatus(error) ?? httpStatus(causeOf(error));
|
|
55
|
+
return status === 401 || status === 403 ? "run_credentials_unavailable" : "run_failed";
|
|
56
|
+
}
|
|
57
|
+
function runErrorFailure(label, error) {
|
|
58
|
+
const cause = (error instanceof Error ? error.message : String(error ?? "")).trim();
|
|
59
|
+
if (!cause) return new RunEndedInError("run_failed", `${label} ended in error.`);
|
|
60
|
+
return new RunEndedInError(runErrorCode(error, cause), `${label} ended in error: ${cause}`);
|
|
61
|
+
}
|
|
41
62
|
function isTerminalFailure(attempts, failureCode) {
|
|
42
63
|
return attempts >= MAX_ATTEMPTS || !factoryDispatchFailureMetadata(failureCode).canRetry;
|
|
43
64
|
}
|
|
@@ -59,10 +80,12 @@ function watchRun(session, { timeoutMs, approvePlans, onAgentEnd, label, runStil
|
|
|
59
80
|
let supersededAtEnd;
|
|
60
81
|
let parked;
|
|
61
82
|
let omFailure;
|
|
83
|
+
let runError;
|
|
62
84
|
const arm = () => {
|
|
63
85
|
endReason = void 0;
|
|
64
86
|
supersededAtEnd = void 0;
|
|
65
87
|
omFailure = void 0;
|
|
88
|
+
runError = void 0;
|
|
66
89
|
agentEnd = new Promise((resolve) => {
|
|
67
90
|
resolveAgentEnd = resolve;
|
|
68
91
|
});
|
|
@@ -75,6 +98,10 @@ function watchRun(session, { timeoutMs, approvePlans, onAgentEnd, label, runStil
|
|
|
75
98
|
resolveAgentEnd();
|
|
76
99
|
return;
|
|
77
100
|
}
|
|
101
|
+
if (event.type === "error") {
|
|
102
|
+
runError = event.error;
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
78
105
|
if (event.type === "om_observation_failed" || event.type === "om_buffering_failed") {
|
|
79
106
|
if (event.error) omFailure = event.error;
|
|
80
107
|
return;
|
|
@@ -119,7 +146,7 @@ function watchRun(session, { timeoutMs, approvePlans, onAgentEnd, label, runStil
|
|
|
119
146
|
observed = await wait();
|
|
120
147
|
}
|
|
121
148
|
if (!observed) throw new FactoryDispatchError("run_terminal_event_missing", `${label} terminal event was not observed before timeout.`);
|
|
122
|
-
if (endReason === "error") throw
|
|
149
|
+
if (endReason === "error") throw runErrorFailure(label, runError);
|
|
123
150
|
if (endReason === "aborted") {
|
|
124
151
|
if (omFailure) {
|
|
125
152
|
if (isPermanentProviderRejection(omFailure)) throw new FactoryDispatchError("run_configuration_invalid", `${label} was aborted by an observational-memory failure that will not succeed on retry: ${omFailure}`);
|
|
@@ -164,8 +191,20 @@ function factoryRequestContext(input) {
|
|
|
164
191
|
function positiveMs(value, fallback) {
|
|
165
192
|
return typeof value === "number" && Number.isFinite(value) && value > 0 ? Math.floor(value) : fallback;
|
|
166
193
|
}
|
|
194
|
+
const KEY_SHAPED_TOKEN = /\b(?:sk-[A-Za-z0-9_-]{3,}|gh[pousr]_[A-Za-z0-9]{10,}|github_pat_[A-Za-z0-9_]{10,}|xox[abprs]-[A-Za-z0-9-]{10,})/g;
|
|
195
|
+
function looksLikeSecret(token) {
|
|
196
|
+
return /[A-Z]/.test(token) && /[a-z]/.test(token) && /\d/.test(token) && /[A-Za-z0-9]{16,}/.test(token);
|
|
197
|
+
}
|
|
198
|
+
function redactSecretRun(token) {
|
|
199
|
+
if (looksLikeSecret(token) && !token.split("/").some((piece) => /^[A-Za-z][a-z]+$/.test(piece))) return "[redacted]";
|
|
200
|
+
return token.replace(/[A-Za-z0-9_+=-]{24,}/g, (piece) => looksLikeSecret(piece) || isGroupedKey(piece) ? "[redacted]" : piece);
|
|
201
|
+
}
|
|
202
|
+
function isGroupedKey(token) {
|
|
203
|
+
const groups = token.split(/[-_]/);
|
|
204
|
+
return groups.length >= 4 && groups.every((group) => /[A-Z]/.test(group) && /[a-z]/.test(group) && /\d/.test(group));
|
|
205
|
+
}
|
|
167
206
|
function sanitizeDispatchError(error) {
|
|
168
|
-
return (error instanceof Error ? error.message : String(error)).replace(/\b(?:bearer|token|api[-_ ]?key|authorization)\s*[:=]?\s*[^\s,;]+/gi, "[redacted]").slice(0, MAX_ERROR_LENGTH);
|
|
207
|
+
return (error instanceof Error ? error.message : String(error)).replace(KEY_SHAPED_TOKEN, "[redacted]").replace(/\b[A-Za-z0-9_+=/-]{24,}/g, redactSecretRun).replace(/\b(?:bearer|token|api[-_ ]?key|authorization)\s*[:=]?\s*(?:bearer\s+)?[^\s,;]+/gi, "[redacted]").slice(0, MAX_ERROR_LENGTH);
|
|
169
208
|
}
|
|
170
209
|
function retryAt(now, attempts) {
|
|
171
210
|
return new Date(now.getTime() + Math.min(1e3 * 2 ** Math.max(0, attempts - 1), MAX_BACKOFF_MS));
|