@aliyunrds/ctxdb-shared 0.0.8-beta.0 → 0.0.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/README.md +15 -0
- package/dist/index.d.ts +388 -20
- package/dist/index.js +1269 -182
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,3 +64,18 @@ pnpm install
|
|
|
64
64
|
pnpm test # → vitest unit tests
|
|
65
65
|
pnpm build # → dist/index.{js,d.ts}
|
|
66
66
|
```
|
|
67
|
+
|
|
68
|
+
## Public CLI authentication
|
|
69
|
+
|
|
70
|
+
`selectDataApiCredential` preserves environment AT/API-Key priority. `DataApiAuthorizationProvider`
|
|
71
|
+
rereads the persistent Agent choice before requests and delegates Device refresh to
|
|
72
|
+
`OAuthProfileProvider` / `OAuthSessionStore`. Legacy profile references retain their profile
|
|
73
|
+
check; shared references require the explicit Agent → login ID → credential relationship.
|
|
74
|
+
|
|
75
|
+
`login-bindings.ts` owns shared registration, switching, unbind and optimistic login commits.
|
|
76
|
+
`auth-config.ts` supplies short config-lock transactions used by ordinary CLI config writers too.
|
|
77
|
+
The config lock is never held across a network request; credential locks can acquire it, and
|
|
78
|
+
config writers never wait for credential locks. Login IDs are stable, credential references are
|
|
79
|
+
replaced on reauthorization, and rotation/ambiguity/tombstone behavior is common to all consumers.
|
|
80
|
+
|
|
81
|
+
See [configuration and lifecycle contract](../../docs/cli-shared-login.md).
|
package/dist/index.d.ts
CHANGED
|
@@ -399,7 +399,7 @@ declare function sanitizeQuery(raw: string): string;
|
|
|
399
399
|
*/
|
|
400
400
|
declare function recall(provider: Mem0Provider, query: string, userId: string, config?: SkillsConfig, sessionId?: string): Promise<RecallResult>;
|
|
401
401
|
|
|
402
|
-
declare const OFFICIAL_PRODUCTION_BASE_URLS: readonly ["https://context-database.aliyuncs.com"];
|
|
402
|
+
declare const OFFICIAL_PRODUCTION_BASE_URLS: readonly ["https://api.cn-hangzhou.agentcontext.aliyuncs.com", "https://context-database.aliyuncs.com"];
|
|
403
403
|
type DebugReason = "non_production_base_url" | null;
|
|
404
404
|
interface DebugPolicy {
|
|
405
405
|
debugConfigured: boolean;
|
|
@@ -495,6 +495,94 @@ declare function sanitizeRecallFailureReason(reason: string, secrets?: Array<str
|
|
|
495
495
|
declare function writeRecallTrace(record: RecallTraceRecord, options?: RecallTraceStoreOptions): boolean;
|
|
496
496
|
declare function readRecallTraces(options?: ReadRecallTraceOptions): ReadRecallTraceResult;
|
|
497
497
|
|
|
498
|
+
declare const ACTIVE_CONTEXTDB_CREDENTIAL: "contextdb/active";
|
|
499
|
+
type CredentialKey = typeof ACTIVE_CONTEXTDB_CREDENTIAL;
|
|
500
|
+
interface ApiKeyCredentialRecord {
|
|
501
|
+
kind: "api-key";
|
|
502
|
+
payload: {
|
|
503
|
+
apiKey: string;
|
|
504
|
+
};
|
|
505
|
+
metadata: {
|
|
506
|
+
baseUrl: string;
|
|
507
|
+
loginServer: string;
|
|
508
|
+
authorizationMethod: "browser-loopback" | "device-code";
|
|
509
|
+
issuedAt: string;
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
type CredentialRecord = ApiKeyCredentialRecord;
|
|
513
|
+
interface CredentialInfo {
|
|
514
|
+
configured: boolean;
|
|
515
|
+
kind?: "api-key" | "oauth-session";
|
|
516
|
+
writable: boolean;
|
|
517
|
+
}
|
|
518
|
+
interface ResolvedRequestAuthorization {
|
|
519
|
+
scheme: "Token" | "Bearer";
|
|
520
|
+
value: string;
|
|
521
|
+
expiresAt: number | null;
|
|
522
|
+
baseUrl: string;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
type CredentialOwner = {
|
|
526
|
+
distribution: "internal";
|
|
527
|
+
} | {
|
|
528
|
+
distribution: "public";
|
|
529
|
+
agent: string;
|
|
530
|
+
loginId?: string;
|
|
531
|
+
};
|
|
532
|
+
type CredentialMetadata = {
|
|
533
|
+
owner: CredentialOwner;
|
|
534
|
+
generation: string;
|
|
535
|
+
revision: number;
|
|
536
|
+
state: "ready" | "refreshing" | "reauth_required" | "logged_out";
|
|
537
|
+
[field: string]: any;
|
|
538
|
+
};
|
|
539
|
+
type StoredCredential = {
|
|
540
|
+
kind: "api-key" | "oauth-session";
|
|
541
|
+
payload: Record<string, any>;
|
|
542
|
+
metadata: CredentialMetadata;
|
|
543
|
+
};
|
|
544
|
+
type CredentialCandidate = Omit<StoredCredential, "metadata"> & {
|
|
545
|
+
metadata: {
|
|
546
|
+
owner: CredentialOwner;
|
|
547
|
+
state: CredentialMetadata["state"];
|
|
548
|
+
[field: string]: any;
|
|
549
|
+
};
|
|
550
|
+
};
|
|
551
|
+
type CredentialSnapshot = {
|
|
552
|
+
key: string;
|
|
553
|
+
fingerprint: string;
|
|
554
|
+
record?: StoredCredential;
|
|
555
|
+
};
|
|
556
|
+
type CredentialCommit = {
|
|
557
|
+
before: CredentialSnapshot;
|
|
558
|
+
after: CredentialSnapshot;
|
|
559
|
+
};
|
|
560
|
+
declare function defaultCredentialsPath(): string;
|
|
561
|
+
declare function internalCandidate(record: ApiKeyCredentialRecord): CredentialCandidate;
|
|
562
|
+
/** One store for both distributions. Every commit rereads and changes only its own record. */
|
|
563
|
+
declare class LocalCredentialProvider {
|
|
564
|
+
private readonly listeners;
|
|
565
|
+
readonly path: string;
|
|
566
|
+
constructor(path?: string);
|
|
567
|
+
snapshot(key: string): CredentialSnapshot;
|
|
568
|
+
readStoredRecord(key: string): StoredCredential | undefined;
|
|
569
|
+
readRecord(key: CredentialKey): Promise<ApiKeyCredentialRecord | undefined>;
|
|
570
|
+
describeRecord(key: string): Promise<CredentialInfo>;
|
|
571
|
+
onRecordUpdated(listener: (key: CredentialKey) => void): () => void;
|
|
572
|
+
/** Synchronous short commit; callbacks may acquire a config lock, never the reverse. */
|
|
573
|
+
transaction<T>(operation: (tx: {
|
|
574
|
+
read(key: string): CredentialSnapshot;
|
|
575
|
+
put(key: string, record: CredentialCandidate, expected?: CredentialSnapshot): CredentialCommit;
|
|
576
|
+
remove(expected: CredentialSnapshot): void;
|
|
577
|
+
}) => T): T;
|
|
578
|
+
commit(key: string, record: CredentialCandidate, expected?: CredentialSnapshot): CredentialCommit;
|
|
579
|
+
rollback(receipt: CredentialCommit): boolean;
|
|
580
|
+
modifyRecord(key: CredentialKey, mutate: (current: ApiKeyCredentialRecord | undefined) => Promise<ApiKeyCredentialRecord | undefined>, signal?: AbortSignal): Promise<ApiKeyCredentialRecord | undefined>;
|
|
581
|
+
deleteRecord(key: CredentialKey, signal?: AbortSignal): Promise<void>;
|
|
582
|
+
}
|
|
583
|
+
declare function readActiveCredentialSync(path?: string): ApiKeyCredentialRecord | undefined;
|
|
584
|
+
declare function withAuthorizationLock<T>(path: string, operation: (signal?: AbortSignal) => Promise<T>, signal?: AbortSignal): Promise<T>;
|
|
585
|
+
|
|
498
586
|
type OAuthScope = "read_only" | "read_write" | "default";
|
|
499
587
|
type OAuthLogin = {
|
|
500
588
|
baseUrl: string;
|
|
@@ -510,7 +598,10 @@ type OAuthLogin = {
|
|
|
510
598
|
issuedAt: number;
|
|
511
599
|
expiresAt: number;
|
|
512
600
|
};
|
|
513
|
-
type Phase = "ready" | "refreshing" | "reauth_required";
|
|
601
|
+
type Phase = "ready" | "refreshing" | "reauth_required" | "logged_out";
|
|
602
|
+
type OAuthOwner = string | {
|
|
603
|
+
loginId: string;
|
|
604
|
+
};
|
|
514
605
|
type OAuthRefreshResponse = {
|
|
515
606
|
access_token: string;
|
|
516
607
|
refresh_token: string;
|
|
@@ -535,21 +626,19 @@ declare class OAuthCredentialError extends Error {
|
|
|
535
626
|
readonly code: "login_required" | "credential_busy" | "invalid_profile" | "unsafe_storage";
|
|
536
627
|
constructor(code: OAuthCredentialError["code"]);
|
|
537
628
|
}
|
|
538
|
-
/**
|
|
539
|
-
* Profiles store only this reference. A new login gets a new reference, so it never steals a
|
|
540
|
-
* crashed refresher's lock or lets a late response overwrite the replacement login.
|
|
541
|
-
*/
|
|
629
|
+
/** Public session lifecycle over the same credentials.json provider used by internal login. */
|
|
542
630
|
declare class OAuthSessionStore {
|
|
543
|
-
private readonly
|
|
631
|
+
private readonly provider;
|
|
544
632
|
private readonly now;
|
|
545
633
|
private readonly lockWaitMs;
|
|
546
|
-
|
|
634
|
+
readonly path: string;
|
|
635
|
+
constructor(path: string, options?: {
|
|
547
636
|
now?: () => number;
|
|
548
637
|
lockWaitMs?: number;
|
|
549
638
|
});
|
|
550
|
-
saveLogin(profile: string, session: OAuthLogin): string;
|
|
551
|
-
status(ref: string,
|
|
552
|
-
state: "
|
|
639
|
+
saveLogin(profile: string, session: OAuthLogin, loginId?: string): string;
|
|
640
|
+
status(ref: string, owner: OAuthOwner): {
|
|
641
|
+
state: "missing";
|
|
553
642
|
profile?: undefined;
|
|
554
643
|
baseUrl?: undefined;
|
|
555
644
|
workspaceId?: undefined;
|
|
@@ -571,19 +660,30 @@ declare class OAuthSessionStore {
|
|
|
571
660
|
accountDisplay: string;
|
|
572
661
|
accessExpiresAt: number;
|
|
573
662
|
};
|
|
574
|
-
resolve(ref: string,
|
|
575
|
-
|
|
663
|
+
resolve(ref: string, owner: OAuthOwner, transport: OAuthRefreshTransport): Promise<OAuthRequestAuthorization>;
|
|
664
|
+
share<T>(ref: string, profile: string, loginId: string, commit: () => T): Promise<T>;
|
|
665
|
+
/** Setup changes the DATA endpoint without replacing the identity or racing a refresh. */
|
|
666
|
+
changeBaseUrl(ref: string, owner: OAuthOwner, baseUrl: string, beforeWrite: () => void): Promise<void>;
|
|
667
|
+
logout(ref: string, owner: OAuthOwner, transport: OAuthRevokeTransport, beforeRevoke?: () => void): Promise<{
|
|
668
|
+
remoteRevoked: boolean;
|
|
669
|
+
}>;
|
|
670
|
+
/** Release config references under the write lock, then delete an unused session.
|
|
671
|
+
* Waiting on the operation lock first lets an in-flight refresh supply its latest RT.
|
|
672
|
+
* Returning false from release preserves a session that still has users.
|
|
673
|
+
*/
|
|
674
|
+
retire(ref: string, owner: OAuthOwner, transport: OAuthRevokeTransport, release: () => boolean): Promise<{
|
|
675
|
+
removed: boolean;
|
|
576
676
|
remoteRevoked: boolean;
|
|
677
|
+
remoteUnconfirmed: boolean;
|
|
577
678
|
}>;
|
|
578
679
|
private needsRefresh;
|
|
579
|
-
private path;
|
|
580
|
-
private isLoggedOut;
|
|
581
|
-
private prepareDirectory;
|
|
582
680
|
private read;
|
|
583
681
|
private write;
|
|
584
|
-
private atomicWrite;
|
|
585
682
|
private withLock;
|
|
586
683
|
}
|
|
684
|
+
/** Keep storage layout mapping in shared; callers use the same candidate for commit and compensation. */
|
|
685
|
+
declare function oauthSessionCandidate(profile: string, session: OAuthLogin, loginId?: string): CredentialCandidate;
|
|
686
|
+
declare function oauthSessionFromCredential(record: CredentialCandidate): OAuthLogin;
|
|
587
687
|
|
|
588
688
|
type DevicePrompt = {
|
|
589
689
|
requestId: string;
|
|
@@ -603,15 +703,18 @@ declare class CoreDeviceClient {
|
|
|
603
703
|
readonly baseUrl: string;
|
|
604
704
|
private readonly fetchImpl;
|
|
605
705
|
private readonly now;
|
|
706
|
+
private readonly requestTimeoutMs;
|
|
606
707
|
private readonly sleep;
|
|
607
708
|
constructor(baseUrl: string, options?: {
|
|
608
709
|
fetchImpl?: typeof fetch;
|
|
609
710
|
now?: () => number;
|
|
711
|
+
requestTimeoutMs?: number;
|
|
610
712
|
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
611
713
|
});
|
|
612
714
|
login(options: {
|
|
613
715
|
onPrompt: (prompt: DevicePrompt) => void;
|
|
614
716
|
signal?: AbortSignal;
|
|
717
|
+
initialAgent?: string;
|
|
615
718
|
}): Promise<OAuthLogin>;
|
|
616
719
|
refresh(refreshToken: string, baseUrl: string): Promise<OAuthRefreshResponse>;
|
|
617
720
|
revoke(refreshToken: string, baseUrl: string): Promise<void>;
|
|
@@ -619,15 +722,75 @@ declare class CoreDeviceClient {
|
|
|
619
722
|
private post;
|
|
620
723
|
}
|
|
621
724
|
|
|
725
|
+
type AuthConfig = {
|
|
726
|
+
version: 2;
|
|
727
|
+
agents: Record<string, Record<string, any>>;
|
|
728
|
+
logins?: Record<string, {
|
|
729
|
+
credential_ref: string;
|
|
730
|
+
[key: string]: unknown;
|
|
731
|
+
}>;
|
|
732
|
+
[key: string]: any;
|
|
733
|
+
};
|
|
734
|
+
declare class AuthConfigError extends Error {
|
|
735
|
+
constructor(message: string);
|
|
736
|
+
}
|
|
737
|
+
declare function readAuthConfig(path: string): AuthConfig;
|
|
738
|
+
declare function ownAuthProfile(raw: AuthConfig, agent: string): Record<string, any>;
|
|
739
|
+
declare function requireLoginId(id: unknown): asserts id is string;
|
|
740
|
+
declare function loginUsers(raw: AuthConfig, id: string): string[];
|
|
741
|
+
/** Validate BEFORE the caller merges default fields. Legacy-only profiles keep their old precedence. */
|
|
742
|
+
declare function validateLoginChoice(section: Record<string, any>): void;
|
|
743
|
+
/** No token values in errors. This snapshot is private process state, never printed. */
|
|
744
|
+
declare function authSnapshot(raw: AuthConfig, agent: string): string;
|
|
745
|
+
declare function assertAuthSnapshot(raw: AuthConfig, agent: string, expected: string): void;
|
|
746
|
+
/** Preserve only existing legacy profiles that really inherited the default key. Never synthesize Agents. */
|
|
747
|
+
declare function preserveDefaultApiKey(raw: AuthConfig, store?: (agent: string, key: string, baseUrl: string) => string): void;
|
|
748
|
+
declare function rejectAuthEnvironment(env: Record<string, string | undefined>): void;
|
|
749
|
+
/** Short, synchronous critical sections only. Never hold this lock across network IO or an await.
|
|
750
|
+
* Credential operations may acquire this config lock, but config writers never acquire a credential lock.
|
|
751
|
+
* This is also used by ordinary CLI config writers, so a business-field save cannot lose a login commit.
|
|
752
|
+
*/
|
|
753
|
+
declare function withAuthConfigLock<T>(path: string, task: () => T): T;
|
|
754
|
+
declare function updateAuthConfig<T>(path: string, task: (raw: AuthConfig) => T): T;
|
|
755
|
+
|
|
622
756
|
/** Safe config metadata, never AT/RT. References are explicit per profile and are not inherited. */
|
|
623
757
|
type OAuthProfile = {
|
|
624
758
|
reference: string;
|
|
625
759
|
profile: string;
|
|
626
760
|
configPath: string;
|
|
627
|
-
|
|
761
|
+
credentialsPath: string;
|
|
628
762
|
baseUrl: string;
|
|
763
|
+
loginId?: string;
|
|
629
764
|
};
|
|
630
765
|
declare function oauthProfile(reference: unknown, configPath: string, profile: string, baseUrl: string): OAuthProfile | undefined;
|
|
766
|
+
/** Resolve explicit Agent -> login -> credential relationships before default inheritance. No writes. */
|
|
767
|
+
declare function oauthProfileFromConfig(raw: AuthConfig, path: string, agent: string, baseUrlOverride?: string): OAuthProfile | undefined;
|
|
768
|
+
declare function oauthOwner(profile: OAuthProfile): string | {
|
|
769
|
+
loginId: string;
|
|
770
|
+
};
|
|
771
|
+
declare function oauthProfileStatus(profile: OAuthProfile): {
|
|
772
|
+
state: "missing";
|
|
773
|
+
profile?: undefined;
|
|
774
|
+
baseUrl?: undefined;
|
|
775
|
+
workspaceId?: undefined;
|
|
776
|
+
memberId?: undefined;
|
|
777
|
+
clientId?: undefined;
|
|
778
|
+
scope?: undefined;
|
|
779
|
+
sessionId?: undefined;
|
|
780
|
+
accountDisplay?: undefined;
|
|
781
|
+
accessExpiresAt?: undefined;
|
|
782
|
+
} | {
|
|
783
|
+
state: "ready" | "refreshing" | "reauth_required" | "logged_out";
|
|
784
|
+
profile: string;
|
|
785
|
+
baseUrl: string;
|
|
786
|
+
workspaceId: string;
|
|
787
|
+
memberId: string;
|
|
788
|
+
clientId: "ctxdb-cli";
|
|
789
|
+
scope: OAuthScope;
|
|
790
|
+
sessionId: string;
|
|
791
|
+
accountDisplay: string;
|
|
792
|
+
accessExpiresAt: number;
|
|
793
|
+
};
|
|
631
794
|
/** Shared by CLI, out-of-process hooks and the in-process OpenCode runtime.
|
|
632
795
|
* Re-read the selected reference so a long-lived runtime sees a new login. An endpoint
|
|
633
796
|
* change requires reloading the runtime; no credential is sent to the replacement host.
|
|
@@ -635,7 +798,212 @@ declare function oauthProfile(reference: unknown, configPath: string, profile: s
|
|
|
635
798
|
declare class OAuthProfileProvider {
|
|
636
799
|
private readonly selected;
|
|
637
800
|
constructor(selected: OAuthProfile);
|
|
638
|
-
resolve(
|
|
801
|
+
resolve(options?: {
|
|
802
|
+
timeoutMs?: number;
|
|
803
|
+
}): Promise<OAuthRequestAuthorization>;
|
|
639
804
|
}
|
|
640
805
|
|
|
641
|
-
|
|
806
|
+
declare function selectedLogin(path: string, agent: string): OAuthProfile | undefined;
|
|
807
|
+
/** --login default is resolved now, never stored as a chain through another Agent. */
|
|
808
|
+
declare function namedLogin(raw: AuthConfig, path: string, name: string): OAuthProfile;
|
|
809
|
+
declare function beginLogin(path: string, agent: string, name?: string): {
|
|
810
|
+
path: string;
|
|
811
|
+
agent: string;
|
|
812
|
+
name: string;
|
|
813
|
+
previous: OAuthProfile;
|
|
814
|
+
loginId: string;
|
|
815
|
+
update: boolean;
|
|
816
|
+
snapshot: string;
|
|
817
|
+
previousState: "missing" | ("ready" | "refreshing" | "reauth_required" | "logged_out");
|
|
818
|
+
group: string;
|
|
819
|
+
users: string[];
|
|
820
|
+
};
|
|
821
|
+
type PendingLogin = ReturnType<typeof beginLogin>;
|
|
822
|
+
declare function commitLogin(pending: PendingLogin, reference: string, baseUrl: string): void;
|
|
823
|
+
declare function unbindLogin(path: string, agent: string): void;
|
|
824
|
+
declare function bindLogin(path: string, agent: string, name: string): Promise<void>;
|
|
825
|
+
type SetupAuthenticationOptions = {
|
|
826
|
+
apiKey?: string;
|
|
827
|
+
login?: string;
|
|
828
|
+
baseUrl?: string;
|
|
829
|
+
preserveBaseUrl?: boolean;
|
|
830
|
+
};
|
|
831
|
+
/** Setup keeps the selected identity, but resets its DATA endpoint unless explicitly supplied. */
|
|
832
|
+
declare function setupAuthentication(path: string, agent: string, options: SetupAuthenticationOptions, env?: Record<string, string | undefined>): Promise<void>;
|
|
833
|
+
|
|
834
|
+
/** Config mutation and reference check occur together, after any concurrent refresh.
|
|
835
|
+
* The caller's mutation must only use the supplied config (the credential write lock is held).
|
|
836
|
+
*/
|
|
837
|
+
declare function releaseLogin(profile: OAuthProfile, transport: OAuthRevokeTransport, detach?: (raw: AuthConfig) => void): Promise<{
|
|
838
|
+
removed: boolean;
|
|
839
|
+
remoteRevoked: boolean;
|
|
840
|
+
remoteUnconfirmed: boolean;
|
|
841
|
+
}>;
|
|
842
|
+
/** Collect catalogued orphans after a successful authentication change. Never scan arbitrary
|
|
843
|
+
* credentials: an unpublished concurrent login or an internal/API-key record is not an orphan.
|
|
844
|
+
*/
|
|
845
|
+
declare function collectUnusedLogins(path: string, transport: OAuthRevokeTransport, previous?: OAuthProfile): Promise<{
|
|
846
|
+
removed: number;
|
|
847
|
+
unconfirmed: number;
|
|
848
|
+
}>;
|
|
849
|
+
|
|
850
|
+
declare const DEFAULT_DATA_BASE_URL = "https://api.cn-hangzhou.agentcontext.aliyuncs.com";
|
|
851
|
+
/** Validate explicit input before any config/credential write; never echo a supplied URL's secrets. */
|
|
852
|
+
declare function validateDataBaseUrl(value: unknown, coreOrigin?: boolean): asserts value is string;
|
|
853
|
+
|
|
854
|
+
type DataAuthContext = {
|
|
855
|
+
configPath: string;
|
|
856
|
+
agent: string;
|
|
857
|
+
baseUrl: string;
|
|
858
|
+
inheritDefaultKey: boolean;
|
|
859
|
+
baseUrlOverride?: string;
|
|
860
|
+
managedCredentials?: boolean;
|
|
861
|
+
credentialsPath?: string;
|
|
862
|
+
};
|
|
863
|
+
type DataApiCredential = {
|
|
864
|
+
type: "access-token";
|
|
865
|
+
value: string;
|
|
866
|
+
context?: undefined;
|
|
867
|
+
} | {
|
|
868
|
+
type: "oauth-session";
|
|
869
|
+
profile: OAuthProfile;
|
|
870
|
+
value?: undefined;
|
|
871
|
+
context?: DataAuthContext;
|
|
872
|
+
} | {
|
|
873
|
+
type: "api-key";
|
|
874
|
+
value: string;
|
|
875
|
+
context?: DataAuthContext;
|
|
876
|
+
};
|
|
877
|
+
declare function selectDataApiCredential(cfg: {
|
|
878
|
+
apiKey: string | null;
|
|
879
|
+
oauthCredential?: OAuthProfile;
|
|
880
|
+
authContext?: DataAuthContext;
|
|
881
|
+
}, env?: Record<string, string | undefined>): DataApiCredential | null;
|
|
882
|
+
/** Used by both HTTP clients. Persisted choices are reread for every request, including API Key switches.
|
|
883
|
+
* Runtime environment credentials are selected first by selectDataApiCredential and never enter this store.
|
|
884
|
+
*/
|
|
885
|
+
declare class DataApiAuthorizationProvider {
|
|
886
|
+
private readonly context;
|
|
887
|
+
constructor(context: DataAuthContext);
|
|
888
|
+
resolve(options?: {
|
|
889
|
+
timeoutMs?: number;
|
|
890
|
+
}): Promise<{
|
|
891
|
+
scheme: "Token" | "Bearer";
|
|
892
|
+
value: string;
|
|
893
|
+
baseUrl: string;
|
|
894
|
+
expiresAt: number | null;
|
|
895
|
+
}>;
|
|
896
|
+
}
|
|
897
|
+
/** Referenced credentials own their endpoint. Legacy config addresses never select or redirect them.
|
|
898
|
+
* Only an explicit runtime override is compared, before any credential can be sent.
|
|
899
|
+
*/
|
|
900
|
+
declare function publicAuthenticationFromConfig(raw: AuthConfig, path: string, agent: string, baseUrlOverride?: string): {
|
|
901
|
+
baseUrl: string;
|
|
902
|
+
apiKey?: string;
|
|
903
|
+
oauthCredential?: OAuthProfile;
|
|
904
|
+
} | undefined;
|
|
905
|
+
/** Compatibility export; resolution and origin checks live in the unified reader. */
|
|
906
|
+
declare function publicApiKeyFromConfig(raw: AuthConfig, path: string, agent: string, baseUrl?: string): string | undefined;
|
|
907
|
+
declare function createRequestAuthorizationProvider(credential: DataApiCredential | null, baseUrl: string): OAuthProfileProvider | DataApiAuthorizationProvider | {
|
|
908
|
+
resolve(_options?: {
|
|
909
|
+
timeoutMs?: number;
|
|
910
|
+
}): Promise<{
|
|
911
|
+
scheme: "Token" | "Bearer";
|
|
912
|
+
value: string;
|
|
913
|
+
baseUrl: string;
|
|
914
|
+
expiresAt: any;
|
|
915
|
+
}>;
|
|
916
|
+
};
|
|
917
|
+
|
|
918
|
+
interface AuthorizationMethod {
|
|
919
|
+
id: string;
|
|
920
|
+
label: string;
|
|
921
|
+
}
|
|
922
|
+
interface AuthorizationNotice {
|
|
923
|
+
message: string;
|
|
924
|
+
url?: string;
|
|
925
|
+
code?: string;
|
|
926
|
+
}
|
|
927
|
+
type AuthorizationPrompt = {
|
|
928
|
+
kind: "text" | "secret";
|
|
929
|
+
message: string;
|
|
930
|
+
placeholder?: string;
|
|
931
|
+
signal?: AbortSignal;
|
|
932
|
+
} | {
|
|
933
|
+
kind: "select";
|
|
934
|
+
message: string;
|
|
935
|
+
options: readonly {
|
|
936
|
+
id: string;
|
|
937
|
+
label: string;
|
|
938
|
+
}[];
|
|
939
|
+
signal?: AbortSignal;
|
|
940
|
+
};
|
|
941
|
+
interface AuthorizationInteraction {
|
|
942
|
+
notify(notice: AuthorizationNotice): void;
|
|
943
|
+
prompt(prompt: AuthorizationPrompt): Promise<string>;
|
|
944
|
+
}
|
|
945
|
+
interface AuthorizationSession {
|
|
946
|
+
readonly method: string;
|
|
947
|
+
readonly signal: AbortSignal;
|
|
948
|
+
notify(notice: AuthorizationNotice): void;
|
|
949
|
+
prompt(prompt: AuthorizationPrompt): Promise<string>;
|
|
950
|
+
}
|
|
951
|
+
/** key identifies the protocol flow, independently of the target credential reference. */
|
|
952
|
+
interface AuthorizationFlow {
|
|
953
|
+
key: string;
|
|
954
|
+
label: string;
|
|
955
|
+
methods: readonly [AuthorizationMethod, ...AuthorizationMethod[]];
|
|
956
|
+
run(session: AuthorizationSession): Promise<CredentialCandidate>;
|
|
957
|
+
validate?(candidate: CredentialCandidate, signal: AbortSignal): Promise<void>;
|
|
958
|
+
revoke(candidate: CredentialCandidate): Promise<void>;
|
|
959
|
+
}
|
|
960
|
+
interface AuthorizationEntry {
|
|
961
|
+
key: string;
|
|
962
|
+
label: string;
|
|
963
|
+
methods: readonly AuthorizationMethod[];
|
|
964
|
+
inFlight: boolean;
|
|
965
|
+
}
|
|
966
|
+
interface AuthorizationTarget {
|
|
967
|
+
/** Opaque begin-state and commit receipts stay inside the adapter. */
|
|
968
|
+
commit(candidate: CredentialCandidate): unknown;
|
|
969
|
+
rollback(receipt: unknown): boolean;
|
|
970
|
+
discard?(): void;
|
|
971
|
+
retirePrevious?(): Promise<void>;
|
|
972
|
+
}
|
|
973
|
+
type AuthorizationOutcome = {
|
|
974
|
+
status: "authorized" | "cancelled";
|
|
975
|
+
};
|
|
976
|
+
|
|
977
|
+
declare class AuthorizationError extends Error {
|
|
978
|
+
readonly code: string;
|
|
979
|
+
constructor(message: string, code: string);
|
|
980
|
+
}
|
|
981
|
+
declare class AuthorizationDeclinedError extends Error {
|
|
982
|
+
constructor(message?: string);
|
|
983
|
+
}
|
|
984
|
+
/** Protocols issue candidates. This module owns commit, cancellation compensation and retirement. */
|
|
985
|
+
declare class AuthorizationService {
|
|
986
|
+
private readonly flows;
|
|
987
|
+
private readonly running;
|
|
988
|
+
private readonly credentials?;
|
|
989
|
+
constructor(credentials?: LocalCredentialProvider);
|
|
990
|
+
registerFlow(flow: AuthorizationFlow): () => void;
|
|
991
|
+
list(): readonly AuthorizationEntry[];
|
|
992
|
+
cancel(key: string): void;
|
|
993
|
+
begin(request: {
|
|
994
|
+
key: string;
|
|
995
|
+
credentialKey?: string;
|
|
996
|
+
method?: string;
|
|
997
|
+
interaction: AuthorizationInteraction;
|
|
998
|
+
signal?: AbortSignal;
|
|
999
|
+
target?: AuthorizationTarget;
|
|
1000
|
+
previousCleanupWarning?: string;
|
|
1001
|
+
finalize?: () => Promise<void>;
|
|
1002
|
+
warn?: (message: string) => void;
|
|
1003
|
+
}): Promise<AuthorizationOutcome>;
|
|
1004
|
+
}
|
|
1005
|
+
|
|
1006
|
+
/** Publishes a stable login ID only after its fresh record exists. CAS preserves newer Agent choices. */
|
|
1007
|
+
declare function publicAuthorizationTarget(pending: PendingLogin, revoke: OAuthRevokeTransport): AuthorizationTarget;
|
|
1008
|
+
|
|
1009
|
+
export { ACTIVE_CONTEXTDB_CREDENTIAL, type AddOptions, type AddResult, type AddResultItem, type ApiKeyCredentialRecord, type AuthConfig, AuthConfigError, AuthorizationDeclinedError, type AuthorizationEntry, AuthorizationError, type AuthorizationFlow, type AuthorizationInteraction, type AuthorizationMethod, type AuthorizationNotice, type AuthorizationOutcome, type AuthorizationPrompt, AuthorizationService, type AuthorizationSession, type AuthorizationTarget, type CategoryConfig, CoreDeviceClient, type CredentialCandidate, type CredentialCommit, type CredentialInfo, type CredentialKey, type CredentialRecord, type CredentialSnapshot, DEFAULT_DATA_BASE_URL, DOCUMENT_EVIDENCE_SECTION_TITLE, DataApiAuthorizationProvider, type DataApiCredential, type DataAuthContext, type DebugPolicy, type DebugReason, type DetectionResult, DeviceFlowError, type DevicePrompt, EXTERNAL_KNOWLEDGE_PREAMBLE_HEAD, type ExcludedRecallMemory, type ExternalContext, type ExternalContextChunk, GRAPH_CONTEXT_MAX_CHARS, GRAPH_CONTEXT_SECTION_TITLE, GRAPH_CONTEXT_SOURCE_LABEL, GRAPH_CONTEXT_TAG, GRAPH_CONTEXT_TRUNCATION_MARKER, GRAPH_CONTEXT_USAGE_NOTICE, type ListOptions, LocalCredentialProvider, type Mem0Provider, type MemoryItem, type NormalizedGraphContext, OAuthCredentialError, type OAuthLogin, type OAuthProfile, OAuthProfileProvider, type OAuthRequestAuthorization, type OAuthScope, OAuthSessionStore, OFFICIAL_PRODUCTION_BASE_URLS, type ParsedMessage, RECALLED_MEMORIES_SAFETY_NOTICE, RECALL_TRACE_AGENTS, RECALL_TRACE_FILENAME, RECALL_TRACE_MAX_BYTES, RECALL_TRACE_OUTCOMES, RECALL_TRACE_ROTATED_GENERATIONS, RECALL_TRACE_SCHEMA_VERSION, type ReadRecallTraceOptions, type ReadRecallTraceResult, type RecallFinishTraceInput, type RecallFinishTraceRecord, type RecallMemoryExclusionReason, type RecallMemorySelectionBase, type RecallResult, type RecallSelectionResult, type RecallStartTraceInput, type RecallStartTraceRecord, type RecallTraceAgent, type RecallTraceKind, type RecallTraceOutcome, type RecallTraceRecord, type RecallTraceRequest, type RecallTraceSelection, type RecallTraceStoreOptions, type ResolvedRequestAuthorization, type SearchOptions, type SearchResultWithExternalContext, type SelectTurnOptions, type SelectedRecallMemory, type SkillsConfig, type StoredCredential, assertAuthSnapshot, authSnapshot, beginLogin, bindLogin, buildExternalKnowledgeBlock, buildExternalKnowledgePreamble, buildNormalizedGraphContext, collectUnusedLogins, commitLogin, createRecallFinishRecord, createRecallStartRecord, createRequestAuthorizationProvider, defaultCredentialsPath, extractKnowledgeBaseIds, extractKnowledgeChunkContent, extractKnowledgeChunkSourceLabel, extractKnowledgeChunkTags, filterMessagesForExtraction, formatExternalKnowledgeChunks, formatRecalledMemoriesBlock, internalCandidate, isGenericAssistantMessage, isGraphContextChunk, isKnowledgeBaseUploadTurn, isNoiseMessage, isOfficialProductionUrl, isSessionSpecificContent, loginUsers, namedLogin, normalizeBaseUrl, normalizeCoreOrigin, oauthOwner, oauthProfile, oauthProfileFromConfig, oauthProfileStatus, oauthSessionCandidate, oauthSessionFromCredential, ownAuthProfile, partitionKnowledgeChunks, preserveDefaultApiKey, publicApiKeyFromConfig, publicAuthenticationFromConfig, publicAuthorizationTarget, readActiveCredentialSync, readAuthConfig, readRecallTraces, recall, recallTracePath, rejectAuthEnvironment, releaseLogin, requireLoginId, resolveDebugPolicy, sanitizeChunkContent, sanitizeQuery, sanitizeRecallFailureReason, selectAndFormatRecalledMemories, selectDataApiCredential, selectTurnMessages, selectedLogin, setupAuthentication, stripNoiseFromContent, truncateGraphContext, unbindLogin, updateAuthConfig, validateDataBaseUrl, validateLoginChoice, withAuthConfigLock, withAuthorizationLock, writeRecallTrace };
|