nolo-cli 0.1.30 → 0.1.31
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/agent-runtime/agentRecordConfig.ts +0 -2
- package/agent-runtime/hostAdapter.ts +0 -1
- package/agent-runtime/hostRuntimeCapabilities.ts +7 -0
- package/agent-runtime/hostRuntimeConfig.ts +86 -0
- package/agent-runtime/index.ts +13 -0
- package/agent-runtime/localToolPolicy.ts +13 -6
- package/agent-runtime/localWorkspaceTools.ts +333 -30
- package/agent-runtime/platformChatProvider.ts +4 -1
- package/agent-runtime/runtimeToolPolicy.ts +32 -47
- package/agent-runtime/shellCommandPolicy.ts +117 -0
- package/agent-runtime/toolGate.ts +38 -0
- package/agentRecordCommands.ts +1 -1
- package/agentRecordHelpers.ts +35 -20
- package/agentRunParsing.ts +18 -5
- package/agentRuntimeLocal.ts +10 -0
- package/ai/agent/agentRunDialogLineage.ts +56 -0
- package/ai/agent/agentSlice.ts +45 -10
- package/ai/agent/avatarUtils.ts +1 -1
- package/ai/agent/buildSystemPrompt.ts +1 -2
- package/ai/agent/cliExecutor.ts +330 -19
- package/ai/agent/createAgentSchema.ts +22 -0
- package/ai/agent/hooks/fetchPublicAgents.ts +14 -39
- package/ai/agent/hooks/usePublicAgents.ts +90 -192
- package/ai/agent/publicAgentCatalog.ts +359 -0
- package/ai/agent/publicAgentIdentity.ts +76 -0
- package/ai/agent/server/fetchPublicAgents.ts +21 -46
- package/ai/agent/serverOrigin.ts +7 -0
- package/ai/agent/streamAgentChatTurn.ts +23 -21
- package/ai/agent/streamAgentChatTurnUtils.ts +292 -6
- package/ai/agent/types.ts +2 -0
- package/ai/agent/web/agentDisplayUtils.ts +171 -0
- package/ai/agent/web/useAgentModelAvatarComponent.ts +32 -0
- package/ai/ai.locale.ts +8 -0
- package/ai/chat/sendOpenAICompletionsRequest.native.ts +15 -0
- package/ai/chat/sendOpenAICompletionsRequest.ts +93 -1
- package/ai/chat/sendOpenAIResponseRequest.ts +86 -9
- package/ai/chat/updateTotalUsage.ts +7 -0
- package/ai/llm/deepinfra.ts +30 -15
- package/ai/llm/mistral.ts +3 -4
- package/ai/llm/providers.ts +2 -0
- package/ai/llm/types.ts +15 -0
- package/ai/memory/capture.ts +3 -3
- package/ai/memory/consolidate.ts +2 -2
- package/ai/memory/delete.ts +4 -3
- package/ai/memory/query.ts +3 -3
- package/ai/memory/remember.ts +2 -2
- package/ai/memory/store.ts +3 -3
- package/ai/memory/storeShared.ts +3 -2
- package/ai/policy/commercialMultiplier.ts +16 -0
- package/ai/token/billingAdminAuditEvent.ts +68 -0
- package/ai/token/billingAdminAuditEventWriter.ts +41 -0
- package/ai/token/billingAnomaly.ts +90 -0
- package/ai/token/billingAnomalyLifecycle.ts +54 -0
- package/ai/token/billingAnomalyLifecycleWriter.ts +44 -0
- package/ai/token/billingAnomalyWriter.ts +41 -0
- package/ai/token/calculatePrice.ts +3 -2
- package/ai/token/deepinfraReconciliation.ts +153 -0
- package/ai/token/deepinfraRequestIdQuery.ts +92 -0
- package/ai/token/externalToolCost.ts +54 -41
- package/ai/token/missingUsageEstimate.ts +12 -3
- package/ai/token/normalizeUsage.ts +45 -5
- package/ai/token/openaiReconciliation.ts +188 -0
- package/ai/token/providerBillableEvent.ts +84 -0
- package/ai/token/providerBillableEventWriter.ts +36 -0
- package/ai/token/providerBillingAnomalyDrilldown.ts +308 -0
- package/ai/token/providerBillingDrilldown.ts +361 -0
- package/ai/token/providerBillingHealthReport.ts +366 -0
- package/ai/token/providerCall.ts +144 -0
- package/ai/token/providerCallSweeper.ts +168 -0
- package/ai/token/providerCallWriter.ts +33 -0
- package/ai/token/providerCredential.ts +89 -0
- package/ai/token/providerCredentialAnomaly.ts +154 -0
- package/ai/token/providerCredentialLifecycle.ts +59 -0
- package/ai/token/providerCredentialLifecycleWriter.ts +44 -0
- package/ai/token/providerCredentialRegistry.ts +83 -0
- package/ai/token/providerCredentialRegistryCommand.ts +97 -0
- package/ai/token/providerCredentialRegistryList.ts +124 -0
- package/ai/token/providerCredentialRegistryResolver.ts +150 -0
- package/ai/token/providerCredentialRegistryWriter.ts +41 -0
- package/ai/token/providerCredentialRotationCommand.ts +102 -0
- package/ai/token/providerCredentialRuntime.ts +56 -0
- package/ai/token/providerDispatchIntent.ts +67 -0
- package/ai/token/providerDispatchIntentWriter.ts +36 -0
- package/ai/token/providerGateway.ts +260 -0
- package/ai/token/providerReconciliation.ts +148 -0
- package/ai/token/providerReconciliationLocal.ts +97 -0
- package/ai/token/providerReconciliationRunner.ts +165 -0
- package/ai/token/providerReconciliationWriter.ts +41 -0
- package/ai/token/ratingResult.ts +202 -0
- package/ai/token/ratingResultWriter.ts +33 -0
- package/ai/token/serverDialogProjection.ts +5 -3
- package/ai/token/serverTokenWriter.ts +11 -3
- package/ai/token/types.ts +10 -0
- package/ai/tools/agent/callAgentTool.ts +3 -4
- package/ai/tools/agent/presets/appBuilderPreset.ts +5 -7
- package/ai/tools/agent/runStreamingAgentTool.ts +1 -2
- package/ai/tools/agent/streamParallelAgentsTool.ts +2 -3
- package/ai/tools/readXPostTool.ts +1 -5
- package/app/admin/adminPages.ts +9 -0
- package/app/i18n/i18n.config.ts +5 -0
- package/app/i18n/translations/pricing.locale.ts +397 -0
- package/app/utils/desktopAgentRuntimeStatusClient.ts +5 -4
- package/app/utils/desktopAgentRuntimeTurnClient.ts +4 -1
- package/app/utils/imageUtils.ts +64 -34
- package/auth/adminPermissions.ts +18 -0
- package/auth/authSlice.ts +26 -12
- package/auth/hooks/useFetchUsers.ts +3 -0
- package/auth/routes.ts +46 -0
- package/auth/server/accessActivity.ts +4 -3
- package/auth/server/adminPermissions.ts +43 -0
- package/auth/server/adminUsageReport.ts +375 -0
- package/auth/server/billingAnomalies.ts +235 -0
- package/auth/server/billingUsageReport.ts +41 -2
- package/auth/server/creatorEarningCreditConversion.ts +10 -2
- package/auth/server/deduct.ts +14 -7
- package/auth/server/delete.ts +10 -2
- package/auth/server/disable.ts +4 -3
- package/auth/server/emailAutomation.ts +7 -5
- package/auth/server/emailDbConfig.ts +4 -2
- package/auth/server/emailDelivery.ts +24 -20
- package/auth/server/emailDeliveryGuards.ts +10 -7
- package/auth/server/emailPreferences.ts +6 -4
- package/auth/server/emailReport.ts +6 -4
- package/auth/server/emailRuntimeConfig.ts +3 -3
- package/auth/server/emailScenarioNotifications.ts +9 -8
- package/auth/server/enable.ts +4 -3
- package/auth/server/getRechargeHistory.ts +3 -2
- package/auth/server/getUser.ts +3 -2
- package/auth/server/gptProAccess.ts +44 -0
- package/auth/server/inviteReward.ts +10 -7
- package/auth/server/listusers.ts +6 -4
- package/auth/server/login.ts +2 -2
- package/auth/server/productEntitlements.ts +7 -4
- package/auth/server/productPurchase.ts +10 -2
- package/auth/server/providerBillingDrilldown.ts +47 -0
- package/auth/server/providerBillingHealth.ts +71 -0
- package/auth/server/providerCredentials.ts +136 -0
- package/auth/server/recharge.ts +14 -8
- package/auth/server/revokeSessions.ts +4 -3
- package/auth/server/route.ts +77 -0
- package/auth/server/sendEmail.ts +5 -4
- package/auth/server/signup.ts +10 -3
- package/auth/server/token.ts +53 -55
- package/auth/server/tokenUsageBilling.ts +18 -7
- package/auth/server/usageManagementAccess.ts +43 -0
- package/auth/server/usageReport.ts +59 -0
- package/auth/types.ts +12 -0
- package/auth/utils.ts +24 -22
- package/authCommands.ts +36 -2
- package/buildPublish.ts +3 -1
- package/buildPublishArtifactAssembly.ts +62 -1
- package/buildPublishImportAnalysis.ts +21 -16
- package/chat/dialog/dialogLaunchScope.ts +32 -0
- package/chat/dialog/objectAssistantRegistry.ts +2 -2
- package/chat/dialog/useCreateDialog.ts +1 -1
- package/chat/hooks/useChatInput.ts +41 -10
- package/chat/messages/messageSlice.ts +5 -1
- package/chat/messages/pendingAttachmentParts.ts +28 -2
- package/chat/messages/sendFirstMessage.ts +76 -79
- package/chat/messages/types.ts +9 -0
- package/chat/messages/web/streamingMarkdownModel.ts +41 -0
- package/chat/messages/web/useStreamingReveal.ts +91 -0
- package/chat/web/messageInputAgentUi.ts +94 -6
- package/cliEnvHelpers.ts +8 -0
- package/cliRuntimeDoctorReport.ts +193 -0
- package/client/agentConfigResolver.test.ts +0 -2
- package/client/agentRun.test.ts +171 -10
- package/client/agentRun.ts +44 -637
- package/client/agentRunInput.ts +10 -0
- package/client/agentRunLocalExecutor.ts +179 -0
- package/client/agentRunServerTransport.ts +394 -0
- package/client/agentRunTaskRunRecorder.ts +176 -0
- package/client/localRuntimeAdapter.test.ts +236 -9
- package/client/localRuntimeAdapter.ts +221 -23
- package/client/localToolPolicy.test.ts +28 -4
- package/connector-experimental/daemonLauncher.ts +38 -4
- package/connectorRunArtifact.ts +34 -10
- package/connectorWebSocketTarget.ts +9 -5
- package/core/builtinAgents.ts +155 -11
- package/create/space/contentLabels.ts +1 -1
- package/create/space/contentTypeMeta.ts +3 -2
- package/create/space/sidebarVisibleTypes.ts +27 -0
- package/create/space/space.locale.ts +76 -4
- package/database/actions/agentReadResolution.ts +2 -8
- package/database/actions/read.ts +11 -9
- package/database/actions/readAndWait.ts +10 -5
- package/database/server/agentDelegation.ts +3 -2
- package/database/server/authorityStoreConformance.ts +209 -0
- package/database/server/authorityStoreTypes.ts +31 -0
- package/database/server/coreDataProxy.ts +1 -1
- package/database/server/dataHandlers.ts +13 -5
- package/database/server/db.ts +15 -34
- package/database/server/delete.ts +88 -71
- package/database/server/emailRepository.ts +11 -9
- package/database/server/fileService.ts +2 -1
- package/database/server/legacyServerDb.ts +58 -0
- package/database/server/levelAuthorityStore.ts +75 -0
- package/database/server/memoryAuthorityStore.ts +133 -0
- package/database/server/patch.ts +13 -12
- package/database/server/query.ts +3 -2
- package/database/server/read.ts +33 -30
- package/database/server/resourceAccess.ts +7 -5
- package/database/server/serverStoreFactory.ts +124 -0
- package/database/server/spaceMemberAuthority.ts +3 -2
- package/database/server/storeBatchCompat.ts +37 -0
- package/database/server/testAuthorityStore.ts +76 -0
- package/database/server/write.ts +29 -27
- package/integrations/anthropic/anthropicModels.ts +12 -12
- package/integrations/deepseek/models.ts +67 -67
- package/integrations/google/models.ts +111 -53
- package/integrations/openai/models.ts +22 -22
- package/integrations/xai/models.ts +1 -1
- package/localRuntimeDb.ts +39 -2
- package/machineCommandPrompts.ts +2 -0
- package/machineCommands.ts +193 -63
- package/machineWsRunDispatch.ts +80 -15
- package/machineWsSession.ts +39 -2
- package/noloReadBridgePrompt.ts +16 -0
- package/package.json +99 -6
- package/render/layout/mainLayoutViewMode.ts +25 -0
- package/render/page/server/createPage.ts +3 -1
- package/render/page/server/handleCreatePage.ts +2 -11
- package/runtimeDoctorCommands.ts +15 -66
- package/server/api/methods.ts +34 -12
- package/server/api/tableHandlers.ts +6 -3
- package/server/authenticateToken.ts +47 -2
- package/server/billingLedgerRoutes.ts +15 -0
- package/server/buildManifest.ts +54 -0
- package/server/coreReadiness.ts +34 -25
- package/server/coreRuntime.ts +15 -10
- package/server/handlers/activityStatsHandler.ts +5 -2
- package/server/handlers/agentEmailRegistrationE2EHandler.ts +25 -23
- package/server/handlers/agentRun/agentLookup.ts +1 -7
- package/server/handlers/agentRun/autonomousRuntime.ts +11 -10
- package/server/handlers/agentRun/builtinAgents.ts +12 -88
- package/server/handlers/agentRun/continueDialogContext.ts +15 -3
- package/server/handlers/agentRun/{inheritedDialogPrompt.ts → conversationReference.ts} +3 -3
- package/server/handlers/agentRun/dialogLookup.ts +4 -3
- package/server/handlers/agentRun/index.ts +864 -404
- package/server/handlers/agentRun/localRuntimeBootstrap.ts +17 -1
- package/server/handlers/agentRun/loop.ts +920 -508
- package/server/handlers/agentRun/machineConnector.ts +56 -8
- package/server/handlers/agentRun/machineRunAudit.ts +3 -2
- package/server/handlers/agentRun/modelUsageToolHandlers.ts +13 -10
- package/server/handlers/agentRun/requestContext.ts +12 -8
- package/server/handlers/agentRun/runtimeExecutionContext.ts +15 -3
- package/server/handlers/agentRun/runtimePreparation.ts +26 -24
- package/server/handlers/agentRun/runtimeRouting.ts +25 -40
- package/server/handlers/agentRun/runtimeSystemMessages.ts +65 -0
- package/server/handlers/agentRun/saveDialog.ts +97 -87
- package/server/handlers/agentRun/taskRunToolHandler.ts +9 -7
- package/server/handlers/agentRun/toolExecutor.ts +42 -78
- package/server/handlers/agentRun/types.ts +2 -1
- package/server/handlers/appDeployStatusStore.ts +17 -10
- package/server/handlers/appDomainHandler.ts +21 -15
- package/server/handlers/appLegacyInfraCleanup.ts +5 -2
- package/server/handlers/appSandboxHandler.ts +29 -8
- package/server/handlers/appSpaceAccess.ts +15 -8
- package/server/handlers/chatHandler.ts +22 -2
- package/server/handlers/chatUpstreamRetry.ts +225 -2
- package/server/handlers/connector/connectorConnectionRegistry.ts +55 -7
- package/server/handlers/connector/connectorWebSocket.ts +14 -10
- package/server/handlers/desktopAgentRuntimeAdapter.ts +4 -4
- package/server/handlers/desktopAgentRuntimeHostCapabilities.ts +25 -0
- package/server/handlers/desktopAgentRuntimeReadiness.ts +62 -0
- package/server/handlers/desktopAgentRuntimeStatusHandler.ts +38 -30
- package/server/handlers/desktopAgentRuntimeTurnHandler.ts +7 -3
- package/server/handlers/desktopAgentRuntimeTurnService.ts +39 -45
- package/server/handlers/desktopLlamaRuntimeHandler.ts +85 -51
- package/server/handlers/desktopUpdaterHandler.ts +132 -24
- package/server/handlers/favoriteHandlers.ts +8 -2
- package/server/handlers/getDialogBillingHandler.ts +4 -3
- package/server/handlers/getTransactionsHandler.ts +5 -2
- package/server/handlers/machines/machineBinding.ts +1 -0
- package/server/handlers/machines/machineHandlers.ts +0 -14
- package/server/handlers/machines/machineInstallAssets.ts +4 -2
- package/server/handlers/notificationEmitter.ts +5 -3
- package/server/handlers/notificationsHandler.ts +5 -2
- package/server/handlers/providerCallsRecentHandler.ts +234 -0
- package/server/handlers/providerReconciliationRunHandler.ts +180 -0
- package/server/handlers/providerRequestIdsHandler.ts +105 -0
- package/server/handlers/tableAccess.ts +6 -2
- package/server/handlers/tableToolHandlers.ts +28 -14
- package/server/handlers/userSecretsHandler.ts +17 -6
- package/server/handlers/versionHandler.ts +9 -4
- package/server/handlers/versionStore.ts +18 -10
- package/server/html/ssrPreload.ts +5 -3
- package/server/payments/crypto/cryptoUsdcBasePaymentProvider.ts +11 -8
- package/server/payments/crypto/cryptoUsdcBaseScanner.ts +12 -7
- package/server/payments/crypto/cryptoUsdtTronPaymentProvider.ts +11 -8
- package/server/payments/crypto/cryptoUsdtTronScanner.ts +9 -7
- package/server/payments/waffo/waffoPaymentProvider.ts +12 -9
- package/server/runtimeRole.ts +15 -0
- package/server/scheduler/scheduledTaskRuntime.ts +4 -2
- package/server/scheduler/schedulerService.ts +2 -2
- package/server/taskRunBridgeRoutes.ts +8 -5
- package/share/server/fetchCommunityShares.ts +1 -1
- package/share/server/helpers.ts +19 -17
- package/share/server/importShare.ts +9 -13
- package/share/server/listCommunityShares.ts +4 -4
- package/share/server/purchaseDoc.ts +8 -16
- package/share/server/readCommunityShareCover.ts +3 -2
- package/share/server/readSharedTable.ts +14 -13
- package/share/server/tableReplication.ts +42 -39
- package/spaceAttachCommands.ts +135 -0
- package/spaceInternalCommandEntries.ts +2 -0
- package/ai/agent/runtimeServerBase.ts +0 -37
- package/server/handlers/desktopAgentRuntimeHostFacts.ts +0 -40
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import crypto from "crypto";
|
|
2
|
+
|
|
3
|
+
export type ProviderApiKeySource =
|
|
4
|
+
| "platform_env"
|
|
5
|
+
| "agent_secret"
|
|
6
|
+
| "agent_reference"
|
|
7
|
+
| "user_secret"
|
|
8
|
+
| "space_secret"
|
|
9
|
+
| "unknown";
|
|
10
|
+
|
|
11
|
+
export type ProviderCredentialIdentity = {
|
|
12
|
+
credentialId: string;
|
|
13
|
+
credentialFingerprint: string;
|
|
14
|
+
providerAccountKey: string;
|
|
15
|
+
apiKeySource: ProviderApiKeySource;
|
|
16
|
+
providerAccountAlias?: string;
|
|
17
|
+
environment?: string;
|
|
18
|
+
officialBillingAccountId?: string;
|
|
19
|
+
registryStatus?: "active" | "rotating" | "revoked";
|
|
20
|
+
registryEffectiveFrom?: string;
|
|
21
|
+
registryEffectiveTo?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const normalizeToken = (value?: string | null) => value?.trim() || "";
|
|
25
|
+
|
|
26
|
+
const safeTokenHash = (token: string) =>
|
|
27
|
+
crypto.createHash("sha256").update(token).digest("hex");
|
|
28
|
+
|
|
29
|
+
const normalizeKeyPart = (value: string) =>
|
|
30
|
+
value
|
|
31
|
+
.trim()
|
|
32
|
+
.toLowerCase()
|
|
33
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
34
|
+
.replace(/^-+|-+$/g, "") || "unknown";
|
|
35
|
+
|
|
36
|
+
export function buildProviderAccountKey({
|
|
37
|
+
provider,
|
|
38
|
+
apiKeySource,
|
|
39
|
+
providerAccountAlias,
|
|
40
|
+
environment,
|
|
41
|
+
}: {
|
|
42
|
+
provider: string;
|
|
43
|
+
apiKeySource: ProviderApiKeySource;
|
|
44
|
+
providerAccountAlias?: string | null;
|
|
45
|
+
environment?: string | null;
|
|
46
|
+
}) {
|
|
47
|
+
const providerPart = normalizeKeyPart(provider);
|
|
48
|
+
const environmentPart = environment?.trim()
|
|
49
|
+
? normalizeKeyPart(environment)
|
|
50
|
+
: "unknown-env";
|
|
51
|
+
const accountPart = providerAccountAlias?.trim()
|
|
52
|
+
? normalizeKeyPart(providerAccountAlias)
|
|
53
|
+
: normalizeKeyPart(apiKeySource);
|
|
54
|
+
return `provider-account-${providerPart}-${environmentPart}-${accountPart}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function createProviderCredentialIdentity({
|
|
58
|
+
provider,
|
|
59
|
+
apiKey,
|
|
60
|
+
apiKeySource,
|
|
61
|
+
providerAccountAlias,
|
|
62
|
+
environment,
|
|
63
|
+
}: {
|
|
64
|
+
provider: string;
|
|
65
|
+
apiKey?: string | null;
|
|
66
|
+
apiKeySource: ProviderApiKeySource;
|
|
67
|
+
providerAccountAlias?: string | null;
|
|
68
|
+
environment?: string | null;
|
|
69
|
+
}): ProviderCredentialIdentity | undefined {
|
|
70
|
+
const token = normalizeToken(apiKey);
|
|
71
|
+
if (!token) return undefined;
|
|
72
|
+
const hash = safeTokenHash(token);
|
|
73
|
+
const normalizedProvider = provider.trim().toLowerCase() || "unknown";
|
|
74
|
+
return {
|
|
75
|
+
credentialId: `cred_${normalizedProvider}_${apiKeySource}_${hash.slice(0, 16)}`,
|
|
76
|
+
credentialFingerprint: `sha256:${hash}`,
|
|
77
|
+
providerAccountKey: buildProviderAccountKey({
|
|
78
|
+
provider: normalizedProvider,
|
|
79
|
+
apiKeySource,
|
|
80
|
+
providerAccountAlias,
|
|
81
|
+
environment,
|
|
82
|
+
}),
|
|
83
|
+
apiKeySource,
|
|
84
|
+
...(providerAccountAlias?.trim()
|
|
85
|
+
? { providerAccountAlias: providerAccountAlias.trim() }
|
|
86
|
+
: {}),
|
|
87
|
+
...(environment?.trim() ? { environment: environment.trim() } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBillingAnomaly,
|
|
3
|
+
type BillingAnomaly,
|
|
4
|
+
} from "./billingAnomaly";
|
|
5
|
+
import type { ProviderCallEvent } from "./providerCall";
|
|
6
|
+
import type { ProviderCredentialIdentity } from "./providerCredential";
|
|
7
|
+
|
|
8
|
+
export type BillingAnomalyWriterLike = (args: {
|
|
9
|
+
store: {
|
|
10
|
+
get(key: string): Promise<unknown>;
|
|
11
|
+
put(key: string, value: unknown): Promise<void>;
|
|
12
|
+
};
|
|
13
|
+
anomaly: BillingAnomaly;
|
|
14
|
+
}) => Promise<{ key: string }>;
|
|
15
|
+
|
|
16
|
+
export type BillingAnomalyWriteStore = Parameters<BillingAnomalyWriterLike>[0]["store"];
|
|
17
|
+
|
|
18
|
+
export const isDuplicateBillingAnomalyError = (error: unknown) =>
|
|
19
|
+
error instanceof Error && error.message.startsWith("billing anomaly already exists:");
|
|
20
|
+
|
|
21
|
+
export function createRevokedProviderCredentialUsedAnomaly({
|
|
22
|
+
event,
|
|
23
|
+
credential,
|
|
24
|
+
createdAt,
|
|
25
|
+
}: {
|
|
26
|
+
event: ProviderCallEvent;
|
|
27
|
+
credential: ProviderCredentialIdentity;
|
|
28
|
+
createdAt: string;
|
|
29
|
+
}): BillingAnomaly {
|
|
30
|
+
return createBillingAnomaly({
|
|
31
|
+
anomalyId: `anom_provider_credential_revoked_used_${event.providerCallId}`,
|
|
32
|
+
kind: "provider_credential_revoked_used",
|
|
33
|
+
severity: "high",
|
|
34
|
+
stage: "provider_call",
|
|
35
|
+
userId: event.userId,
|
|
36
|
+
dialogId: event.dialogId,
|
|
37
|
+
agentId: event.agentId,
|
|
38
|
+
provider: event.provider,
|
|
39
|
+
model: event.model,
|
|
40
|
+
providerCallId: event.providerCallId,
|
|
41
|
+
message: "Revoked provider credential was used for a provider call",
|
|
42
|
+
evidence: {
|
|
43
|
+
credentialId: credential.credentialId,
|
|
44
|
+
providerAccountKey: credential.providerAccountKey,
|
|
45
|
+
providerAccountAlias: credential.providerAccountAlias,
|
|
46
|
+
officialBillingAccountId: credential.officialBillingAccountId,
|
|
47
|
+
apiKeySource: credential.apiKeySource,
|
|
48
|
+
environment: credential.environment,
|
|
49
|
+
registryStatus: credential.registryStatus,
|
|
50
|
+
registryEffectiveFrom: credential.registryEffectiveFrom,
|
|
51
|
+
registryEffectiveTo: credential.registryEffectiveTo,
|
|
52
|
+
providerCallStatus: event.status,
|
|
53
|
+
},
|
|
54
|
+
createdAt,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function createRevokedProviderCredentialBlockedAnomaly({
|
|
59
|
+
event,
|
|
60
|
+
credential,
|
|
61
|
+
createdAt,
|
|
62
|
+
}: {
|
|
63
|
+
event: ProviderCallEvent;
|
|
64
|
+
credential: ProviderCredentialIdentity;
|
|
65
|
+
createdAt: string;
|
|
66
|
+
}): BillingAnomaly {
|
|
67
|
+
return createBillingAnomaly({
|
|
68
|
+
anomalyId: `anom_provider_credential_revoked_blocked_${event.providerCallId}`,
|
|
69
|
+
kind: "provider_credential_revoked_blocked",
|
|
70
|
+
severity: "critical",
|
|
71
|
+
stage: "provider_call",
|
|
72
|
+
userId: event.userId,
|
|
73
|
+
dialogId: event.dialogId,
|
|
74
|
+
agentId: event.agentId,
|
|
75
|
+
provider: event.provider,
|
|
76
|
+
model: event.model,
|
|
77
|
+
providerCallId: event.providerCallId,
|
|
78
|
+
message: "Revoked provider credential was blocked before provider dispatch",
|
|
79
|
+
evidence: {
|
|
80
|
+
credentialId: credential.credentialId,
|
|
81
|
+
providerAccountKey: credential.providerAccountKey,
|
|
82
|
+
providerAccountAlias: credential.providerAccountAlias,
|
|
83
|
+
officialBillingAccountId: credential.officialBillingAccountId,
|
|
84
|
+
apiKeySource: credential.apiKeySource,
|
|
85
|
+
environment: credential.environment,
|
|
86
|
+
registryStatus: credential.registryStatus,
|
|
87
|
+
registryEffectiveFrom: credential.registryEffectiveFrom,
|
|
88
|
+
registryEffectiveTo: credential.registryEffectiveTo,
|
|
89
|
+
providerCallStatus: event.status,
|
|
90
|
+
blockedBeforeDispatch: true,
|
|
91
|
+
},
|
|
92
|
+
createdAt,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function writeRevokedProviderCredentialUsedAnomalyIfNeeded({
|
|
97
|
+
store,
|
|
98
|
+
event,
|
|
99
|
+
now = () => new Date(),
|
|
100
|
+
billingAnomalyWriter,
|
|
101
|
+
onError,
|
|
102
|
+
}: {
|
|
103
|
+
store: BillingAnomalyWriteStore;
|
|
104
|
+
event: ProviderCallEvent;
|
|
105
|
+
now?: () => Date;
|
|
106
|
+
billingAnomalyWriter: BillingAnomalyWriterLike;
|
|
107
|
+
onError?: (error: unknown) => void;
|
|
108
|
+
}) {
|
|
109
|
+
const credential = event.credential;
|
|
110
|
+
if (credential?.registryStatus !== "revoked") return;
|
|
111
|
+
try {
|
|
112
|
+
await billingAnomalyWriter({
|
|
113
|
+
store,
|
|
114
|
+
anomaly: createRevokedProviderCredentialUsedAnomaly({
|
|
115
|
+
event,
|
|
116
|
+
credential,
|
|
117
|
+
createdAt: now().toISOString(),
|
|
118
|
+
}),
|
|
119
|
+
});
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (isDuplicateBillingAnomalyError(error)) return;
|
|
122
|
+
onError?.(error);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export async function writeRevokedProviderCredentialBlockedAnomalyIfNeeded({
|
|
127
|
+
store,
|
|
128
|
+
event,
|
|
129
|
+
now = () => new Date(),
|
|
130
|
+
billingAnomalyWriter,
|
|
131
|
+
onError,
|
|
132
|
+
}: {
|
|
133
|
+
store: BillingAnomalyWriteStore;
|
|
134
|
+
event: ProviderCallEvent;
|
|
135
|
+
now?: () => Date;
|
|
136
|
+
billingAnomalyWriter: BillingAnomalyWriterLike;
|
|
137
|
+
onError?: (error: unknown) => void;
|
|
138
|
+
}) {
|
|
139
|
+
const credential = event.credential;
|
|
140
|
+
if (credential?.registryStatus !== "revoked") return;
|
|
141
|
+
try {
|
|
142
|
+
await billingAnomalyWriter({
|
|
143
|
+
store,
|
|
144
|
+
anomaly: createRevokedProviderCredentialBlockedAnomaly({
|
|
145
|
+
event,
|
|
146
|
+
credential,
|
|
147
|
+
createdAt: now().toISOString(),
|
|
148
|
+
}),
|
|
149
|
+
});
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (isDuplicateBillingAnomalyError(error)) return;
|
|
152
|
+
onError?.(error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ProviderCredentialStatus } from "./providerCredentialRegistry";
|
|
2
|
+
|
|
3
|
+
export type ProviderCredentialLifecycleEvent = {
|
|
4
|
+
schemaVersion: 1;
|
|
5
|
+
recordType: "provider_credential_lifecycle_event";
|
|
6
|
+
credentialId: string;
|
|
7
|
+
eventId: string;
|
|
8
|
+
status: ProviderCredentialStatus;
|
|
9
|
+
effectiveAt: string;
|
|
10
|
+
createdAt: string;
|
|
11
|
+
reason?: string;
|
|
12
|
+
actorId?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const buildProviderCredentialLifecycleEventKey = (
|
|
16
|
+
credentialId: string,
|
|
17
|
+
eventId: string
|
|
18
|
+
) => `provider-credential-lifecycle-${credentialId}-event-${eventId}`;
|
|
19
|
+
|
|
20
|
+
function assertIsoTimestamp(name: string, value: string) {
|
|
21
|
+
const time = Date.parse(value);
|
|
22
|
+
if (!Number.isFinite(time)) {
|
|
23
|
+
throw new Error(`${name} must be an ISO timestamp`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function createProviderCredentialLifecycleEvent({
|
|
28
|
+
credentialId,
|
|
29
|
+
eventId,
|
|
30
|
+
status,
|
|
31
|
+
effectiveAt,
|
|
32
|
+
createdAt,
|
|
33
|
+
reason,
|
|
34
|
+
actorId,
|
|
35
|
+
}: {
|
|
36
|
+
credentialId: string;
|
|
37
|
+
eventId: string;
|
|
38
|
+
status: ProviderCredentialStatus;
|
|
39
|
+
effectiveAt: string;
|
|
40
|
+
createdAt: string;
|
|
41
|
+
reason?: string | null;
|
|
42
|
+
actorId?: string | null;
|
|
43
|
+
}): ProviderCredentialLifecycleEvent {
|
|
44
|
+
if (!credentialId.trim()) throw new Error("credentialId is required");
|
|
45
|
+
if (!eventId.trim()) throw new Error("eventId is required");
|
|
46
|
+
assertIsoTimestamp("effectiveAt", effectiveAt);
|
|
47
|
+
assertIsoTimestamp("createdAt", createdAt);
|
|
48
|
+
return {
|
|
49
|
+
schemaVersion: 1,
|
|
50
|
+
recordType: "provider_credential_lifecycle_event",
|
|
51
|
+
credentialId: credentialId.trim(),
|
|
52
|
+
eventId: eventId.trim(),
|
|
53
|
+
status,
|
|
54
|
+
effectiveAt,
|
|
55
|
+
createdAt,
|
|
56
|
+
...(reason?.trim() ? { reason: reason.trim() } : {}),
|
|
57
|
+
...(actorId?.trim() ? { actorId: actorId.trim() } : {}),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
buildProviderCredentialLifecycleEventKey,
|
|
3
|
+
type ProviderCredentialLifecycleEvent,
|
|
4
|
+
} from "./providerCredentialLifecycle";
|
|
5
|
+
|
|
6
|
+
export type ProviderCredentialLifecycleStore = {
|
|
7
|
+
get(key: string): Promise<unknown>;
|
|
8
|
+
put(key: string, value: unknown): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const isMissingRecordError = (error: unknown) => {
|
|
12
|
+
if (!error || typeof error !== "object") return false;
|
|
13
|
+
const code = (error as { code?: unknown }).code;
|
|
14
|
+
const message = (error as { message?: unknown }).message;
|
|
15
|
+
return (
|
|
16
|
+
code === "LEVEL_NOT_FOUND" ||
|
|
17
|
+
code === "NOT_FOUND" ||
|
|
18
|
+
message === "NotFound"
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export async function writeProviderCredentialLifecycleEvent({
|
|
23
|
+
store,
|
|
24
|
+
event,
|
|
25
|
+
}: {
|
|
26
|
+
store: ProviderCredentialLifecycleStore;
|
|
27
|
+
event: ProviderCredentialLifecycleEvent;
|
|
28
|
+
}): Promise<{ key: string }> {
|
|
29
|
+
const key = buildProviderCredentialLifecycleEventKey(
|
|
30
|
+
event.credentialId,
|
|
31
|
+
event.eventId
|
|
32
|
+
);
|
|
33
|
+
let existing: unknown;
|
|
34
|
+
try {
|
|
35
|
+
existing = await store.get(key);
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (!isMissingRecordError(error)) throw error;
|
|
38
|
+
}
|
|
39
|
+
if (existing) {
|
|
40
|
+
throw new Error(`provider credential lifecycle event already exists: ${key}`);
|
|
41
|
+
}
|
|
42
|
+
await store.put(key, event);
|
|
43
|
+
return { key };
|
|
44
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ProviderApiKeySource,
|
|
3
|
+
ProviderCredentialIdentity,
|
|
4
|
+
} from "./providerCredential";
|
|
5
|
+
|
|
6
|
+
export type ProviderCredentialStatus = "active" | "rotating" | "revoked";
|
|
7
|
+
|
|
8
|
+
export type ProviderCredentialRegistryRecord = {
|
|
9
|
+
schemaVersion: 1;
|
|
10
|
+
recordType: "provider_credential";
|
|
11
|
+
credentialId: string;
|
|
12
|
+
provider: string;
|
|
13
|
+
providerAccountKey: string;
|
|
14
|
+
credentialFingerprint: string;
|
|
15
|
+
apiKeySource: ProviderApiKeySource;
|
|
16
|
+
status: ProviderCredentialStatus;
|
|
17
|
+
effectiveFrom: string;
|
|
18
|
+
effectiveTo?: string;
|
|
19
|
+
createdAt: string;
|
|
20
|
+
providerAccountAlias?: string;
|
|
21
|
+
environment?: string;
|
|
22
|
+
officialBillingAccountId?: string;
|
|
23
|
+
note?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const buildProviderCredentialRegistryKey = (credentialId: string) =>
|
|
27
|
+
`provider-credential-${credentialId}`;
|
|
28
|
+
|
|
29
|
+
function assertIsoTimestamp(name: string, value: string) {
|
|
30
|
+
const time = Date.parse(value);
|
|
31
|
+
if (!Number.isFinite(time)) {
|
|
32
|
+
throw new Error(`${name} must be an ISO timestamp`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function createProviderCredentialRegistryRecord({
|
|
37
|
+
provider,
|
|
38
|
+
identity,
|
|
39
|
+
status,
|
|
40
|
+
effectiveFrom,
|
|
41
|
+
effectiveTo,
|
|
42
|
+
createdAt,
|
|
43
|
+
officialBillingAccountId,
|
|
44
|
+
note,
|
|
45
|
+
}: {
|
|
46
|
+
provider: string;
|
|
47
|
+
identity?: ProviderCredentialIdentity;
|
|
48
|
+
status: ProviderCredentialStatus;
|
|
49
|
+
effectiveFrom: string;
|
|
50
|
+
effectiveTo?: string;
|
|
51
|
+
createdAt: string;
|
|
52
|
+
officialBillingAccountId?: string | null;
|
|
53
|
+
note?: string | null;
|
|
54
|
+
}): ProviderCredentialRegistryRecord {
|
|
55
|
+
if (!identity) {
|
|
56
|
+
throw new Error("provider credential identity is required");
|
|
57
|
+
}
|
|
58
|
+
assertIsoTimestamp("effectiveFrom", effectiveFrom);
|
|
59
|
+
assertIsoTimestamp("createdAt", createdAt);
|
|
60
|
+
if (effectiveTo) assertIsoTimestamp("effectiveTo", effectiveTo);
|
|
61
|
+
const normalizedProvider = provider.trim().toLowerCase() || "unknown";
|
|
62
|
+
return {
|
|
63
|
+
schemaVersion: 1,
|
|
64
|
+
recordType: "provider_credential",
|
|
65
|
+
credentialId: identity.credentialId,
|
|
66
|
+
provider: normalizedProvider,
|
|
67
|
+
providerAccountKey: identity.providerAccountKey,
|
|
68
|
+
credentialFingerprint: identity.credentialFingerprint,
|
|
69
|
+
apiKeySource: identity.apiKeySource,
|
|
70
|
+
status,
|
|
71
|
+
effectiveFrom,
|
|
72
|
+
...(effectiveTo ? { effectiveTo } : {}),
|
|
73
|
+
createdAt,
|
|
74
|
+
...(identity.providerAccountAlias
|
|
75
|
+
? { providerAccountAlias: identity.providerAccountAlias }
|
|
76
|
+
: {}),
|
|
77
|
+
...(identity.environment ? { environment: identity.environment } : {}),
|
|
78
|
+
...(officialBillingAccountId?.trim()
|
|
79
|
+
? { officialBillingAccountId: officialBillingAccountId.trim() }
|
|
80
|
+
: {}),
|
|
81
|
+
...(note?.trim() ? { note: note.trim() } : {}),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderCredentialIdentity,
|
|
3
|
+
type ProviderApiKeySource,
|
|
4
|
+
} from "./providerCredential";
|
|
5
|
+
import {
|
|
6
|
+
buildProviderCredentialRegistryKey,
|
|
7
|
+
createProviderCredentialRegistryRecord,
|
|
8
|
+
type ProviderCredentialRegistryRecord,
|
|
9
|
+
type ProviderCredentialStatus,
|
|
10
|
+
} from "./providerCredentialRegistry";
|
|
11
|
+
import type { RuntimeCredentialEnv } from "./providerCredentialRuntime";
|
|
12
|
+
|
|
13
|
+
export type ProviderCredentialRegistryPublicSummary = {
|
|
14
|
+
credentialId: string;
|
|
15
|
+
provider: string;
|
|
16
|
+
providerAccountKey: string;
|
|
17
|
+
providerAccountAlias?: string;
|
|
18
|
+
apiKeySource: ProviderApiKeySource;
|
|
19
|
+
environment?: string;
|
|
20
|
+
officialBillingAccountId?: string;
|
|
21
|
+
status: ProviderCredentialStatus;
|
|
22
|
+
effectiveFrom: string;
|
|
23
|
+
effectiveTo?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const credentialEnvironment = (env: RuntimeCredentialEnv) =>
|
|
27
|
+
env.NOLO_DEPLOY_ENV?.trim() ||
|
|
28
|
+
env.NOLO_ENV?.trim() ||
|
|
29
|
+
env.NODE_ENV?.trim() ||
|
|
30
|
+
undefined;
|
|
31
|
+
|
|
32
|
+
export function buildProviderCredentialRegistryRegistration({
|
|
33
|
+
provider,
|
|
34
|
+
apiKey,
|
|
35
|
+
apiKeySource,
|
|
36
|
+
env = process.env,
|
|
37
|
+
providerAccountAlias,
|
|
38
|
+
officialBillingAccountId,
|
|
39
|
+
effectiveFrom,
|
|
40
|
+
effectiveTo,
|
|
41
|
+
createdAt,
|
|
42
|
+
status = "active",
|
|
43
|
+
note,
|
|
44
|
+
}: {
|
|
45
|
+
provider: string;
|
|
46
|
+
apiKey?: string | null;
|
|
47
|
+
apiKeySource: ProviderApiKeySource;
|
|
48
|
+
env?: RuntimeCredentialEnv;
|
|
49
|
+
providerAccountAlias?: string | null;
|
|
50
|
+
officialBillingAccountId?: string | null;
|
|
51
|
+
effectiveFrom: string;
|
|
52
|
+
effectiveTo?: string;
|
|
53
|
+
createdAt: string;
|
|
54
|
+
status?: ProviderCredentialStatus;
|
|
55
|
+
note?: string | null;
|
|
56
|
+
}): {
|
|
57
|
+
key: string;
|
|
58
|
+
record: ProviderCredentialRegistryRecord;
|
|
59
|
+
publicSummary: ProviderCredentialRegistryPublicSummary;
|
|
60
|
+
} {
|
|
61
|
+
if (!apiKey?.trim()) {
|
|
62
|
+
throw new Error("api key is required");
|
|
63
|
+
}
|
|
64
|
+
const identity = createProviderCredentialIdentity({
|
|
65
|
+
provider,
|
|
66
|
+
apiKey,
|
|
67
|
+
apiKeySource,
|
|
68
|
+
providerAccountAlias,
|
|
69
|
+
environment: credentialEnvironment(env),
|
|
70
|
+
});
|
|
71
|
+
const record = createProviderCredentialRegistryRecord({
|
|
72
|
+
provider,
|
|
73
|
+
identity,
|
|
74
|
+
status,
|
|
75
|
+
effectiveFrom,
|
|
76
|
+
effectiveTo,
|
|
77
|
+
createdAt,
|
|
78
|
+
officialBillingAccountId,
|
|
79
|
+
note,
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
key: buildProviderCredentialRegistryKey(record.credentialId),
|
|
83
|
+
record,
|
|
84
|
+
publicSummary: {
|
|
85
|
+
credentialId: record.credentialId,
|
|
86
|
+
provider: record.provider,
|
|
87
|
+
providerAccountKey: record.providerAccountKey,
|
|
88
|
+
providerAccountAlias: record.providerAccountAlias,
|
|
89
|
+
apiKeySource: record.apiKeySource,
|
|
90
|
+
environment: record.environment,
|
|
91
|
+
officialBillingAccountId: record.officialBillingAccountId,
|
|
92
|
+
status: record.status,
|
|
93
|
+
effectiveFrom: record.effectiveFrom,
|
|
94
|
+
effectiveTo: record.effectiveTo,
|
|
95
|
+
},
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { ProviderCredentialRegistryPublicSummary } from "./providerCredentialRegistryCommand";
|
|
2
|
+
import type { ProviderCredentialLifecycleEvent } from "./providerCredentialLifecycle";
|
|
3
|
+
import type {
|
|
4
|
+
ProviderCredentialRegistryRecord,
|
|
5
|
+
ProviderCredentialStatus,
|
|
6
|
+
} from "./providerCredentialRegistry";
|
|
7
|
+
|
|
8
|
+
export type ProviderCredentialRegistryListStore = {
|
|
9
|
+
iterator(options?: { gte?: string; lte?: string }): AsyncIterable<[string, unknown]>;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const REGISTRY_PREFIX = "provider-credential-";
|
|
13
|
+
const LIFECYCLE_PREFIX = "provider-credential-lifecycle-";
|
|
14
|
+
|
|
15
|
+
function isRegistryRecord(value: unknown): value is ProviderCredentialRegistryRecord {
|
|
16
|
+
if (!value || typeof value !== "object") return false;
|
|
17
|
+
const record = value as Partial<ProviderCredentialRegistryRecord>;
|
|
18
|
+
return (
|
|
19
|
+
record.schemaVersion === 1 &&
|
|
20
|
+
record.recordType === "provider_credential" &&
|
|
21
|
+
typeof record.credentialId === "string" &&
|
|
22
|
+
typeof record.provider === "string" &&
|
|
23
|
+
typeof record.providerAccountKey === "string" &&
|
|
24
|
+
typeof record.credentialFingerprint === "string" &&
|
|
25
|
+
typeof record.apiKeySource === "string" &&
|
|
26
|
+
typeof record.status === "string" &&
|
|
27
|
+
typeof record.effectiveFrom === "string"
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function isLifecycleEvent(value: unknown): value is ProviderCredentialLifecycleEvent {
|
|
32
|
+
if (!value || typeof value !== "object") return false;
|
|
33
|
+
const event = value as Partial<ProviderCredentialLifecycleEvent>;
|
|
34
|
+
return (
|
|
35
|
+
event.schemaVersion === 1 &&
|
|
36
|
+
event.recordType === "provider_credential_lifecycle_event" &&
|
|
37
|
+
typeof event.credentialId === "string" &&
|
|
38
|
+
typeof event.eventId === "string" &&
|
|
39
|
+
typeof event.status === "string" &&
|
|
40
|
+
typeof event.effectiveAt === "string" &&
|
|
41
|
+
typeof event.createdAt === "string"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function toPublicSummary(
|
|
46
|
+
record: ProviderCredentialRegistryRecord
|
|
47
|
+
): ProviderCredentialRegistryPublicSummary {
|
|
48
|
+
return {
|
|
49
|
+
credentialId: record.credentialId,
|
|
50
|
+
provider: record.provider,
|
|
51
|
+
providerAccountKey: record.providerAccountKey,
|
|
52
|
+
providerAccountAlias: record.providerAccountAlias,
|
|
53
|
+
apiKeySource: record.apiKeySource,
|
|
54
|
+
environment: record.environment,
|
|
55
|
+
officialBillingAccountId: record.officialBillingAccountId,
|
|
56
|
+
status: record.status,
|
|
57
|
+
effectiveFrom: record.effectiveFrom,
|
|
58
|
+
effectiveTo: record.effectiveTo,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function listProviderCredentialRegistryRecords({
|
|
63
|
+
store,
|
|
64
|
+
provider,
|
|
65
|
+
status,
|
|
66
|
+
at = new Date().toISOString(),
|
|
67
|
+
}: {
|
|
68
|
+
store: ProviderCredentialRegistryListStore;
|
|
69
|
+
provider?: string;
|
|
70
|
+
status?: ProviderCredentialStatus;
|
|
71
|
+
at?: string;
|
|
72
|
+
}): Promise<{
|
|
73
|
+
count: number;
|
|
74
|
+
credentials: ProviderCredentialRegistryPublicSummary[];
|
|
75
|
+
}> {
|
|
76
|
+
const normalizedProvider = provider?.trim().toLowerCase();
|
|
77
|
+
const lifecycleByCredential = new Map<string, ProviderCredentialLifecycleEvent>();
|
|
78
|
+
const atMs = Date.parse(at);
|
|
79
|
+
for await (const [, value] of store.iterator({
|
|
80
|
+
gte: LIFECYCLE_PREFIX,
|
|
81
|
+
lte: `${LIFECYCLE_PREFIX}\uffff`,
|
|
82
|
+
})) {
|
|
83
|
+
if (!isLifecycleEvent(value)) continue;
|
|
84
|
+
const effectiveMs = Date.parse(value.effectiveAt);
|
|
85
|
+
if (!Number.isFinite(effectiveMs) || effectiveMs > atMs) continue;
|
|
86
|
+
const existing = lifecycleByCredential.get(value.credentialId);
|
|
87
|
+
if (
|
|
88
|
+
!existing ||
|
|
89
|
+
Date.parse(existing.effectiveAt) < effectiveMs ||
|
|
90
|
+
(existing.effectiveAt === value.effectiveAt &&
|
|
91
|
+
existing.createdAt < value.createdAt)
|
|
92
|
+
) {
|
|
93
|
+
lifecycleByCredential.set(value.credentialId, value);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const credentials: ProviderCredentialRegistryPublicSummary[] = [];
|
|
97
|
+
for await (const [, value] of store.iterator({
|
|
98
|
+
gte: REGISTRY_PREFIX,
|
|
99
|
+
lte: `${REGISTRY_PREFIX}\uffff`,
|
|
100
|
+
})) {
|
|
101
|
+
if (!isRegistryRecord(value)) continue;
|
|
102
|
+
if (normalizedProvider && value.provider !== normalizedProvider) continue;
|
|
103
|
+
const summary = toPublicSummary(value);
|
|
104
|
+
const lifecycle = lifecycleByCredential.get(value.credentialId);
|
|
105
|
+
if (lifecycle) {
|
|
106
|
+
summary.status = lifecycle.status;
|
|
107
|
+
if (lifecycle.status === "revoked") {
|
|
108
|
+
summary.effectiveTo = lifecycle.effectiveAt;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (status && summary.status !== status) continue;
|
|
112
|
+
credentials.push(summary);
|
|
113
|
+
}
|
|
114
|
+
credentials.sort(
|
|
115
|
+
(a, b) =>
|
|
116
|
+
a.provider.localeCompare(b.provider) ||
|
|
117
|
+
a.providerAccountKey.localeCompare(b.providerAccountKey) ||
|
|
118
|
+
a.credentialId.localeCompare(b.credentialId)
|
|
119
|
+
);
|
|
120
|
+
return {
|
|
121
|
+
count: credentials.length,
|
|
122
|
+
credentials,
|
|
123
|
+
};
|
|
124
|
+
}
|