@acrylblends/control 0.0.0-stage → 0.2.11
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 +13 -2
- package/cordis.patch.yml +3 -0
- package/lib/index.js +1457 -0
- package/lib/index.js.map +1 -0
- package/lib/types/agent/agent-control.d.ts +104 -0
- package/lib/types/agent/providers/acp.d.ts +7 -0
- package/lib/types/agent/providers/capabilities.d.ts +13 -0
- package/lib/types/agent/providers/claude.d.ts +7 -0
- package/lib/types/agent/providers/codex.d.ts +7 -0
- package/lib/types/agent/providers/dsh-native.d.ts +7 -0
- package/lib/types/agent/providers/factory.d.ts +17 -0
- package/lib/types/agent/transports/claude-stream.d.ts +55 -0
- package/lib/types/architecture/projection.d.ts +43 -0
- package/lib/types/architecture/provider.d.ts +15 -0
- package/lib/types/authorization/attempts.d.ts +88 -0
- package/lib/types/authorization/service.d.ts +25 -0
- package/lib/types/authorization/types.d.ts +89 -0
- package/lib/types/contracts/operations.d.ts +20 -0
- package/lib/types/contracts/session.d.ts +42 -0
- package/lib/types/credential/default-model.d.ts +38 -0
- package/lib/types/credential/projection.d.ts +87 -0
- package/lib/types/credential/route-activation.d.ts +25 -0
- package/lib/types/credential/types.d.ts +38 -0
- package/lib/types/events.d.ts +14 -0
- package/lib/types/index.d.ts +28 -0
- package/lib/types/platform/tools.d.ts +113 -0
- package/lib/types/platform/web.d.ts +19 -0
- package/lib/types/plugin/controller.d.ts +145 -0
- package/lib/types/plugin/host.d.ts +84 -0
- package/lib/types/plugin/provider.d.ts +41 -0
- package/lib/types/plugin/types.d.ts +43 -0
- package/lib/types/protocol/client.d.ts +7 -0
- package/package.json +55 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type Context, Service } from '@deepseek-ai/cordis';
|
|
2
|
+
import { type ArchitecturePlane, type RuntimeArchitectureSnapshot } from './projection.ts';
|
|
3
|
+
export interface AcrRuntimeArchitecture {
|
|
4
|
+
snapshot(plane: ArchitecturePlane): RuntimeArchitectureSnapshot;
|
|
5
|
+
}
|
|
6
|
+
declare module '@deepseek-ai/cordis' {
|
|
7
|
+
interface Context {
|
|
8
|
+
acrRuntimeArchitecture: AcrRuntimeArchitecture;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export declare class AcrRuntimeArchitectureService extends Service implements AcrRuntimeArchitecture {
|
|
12
|
+
constructor(ctx: Context);
|
|
13
|
+
snapshot(plane: ArchitecturePlane): RuntimeArchitectureSnapshot;
|
|
14
|
+
}
|
|
15
|
+
export default AcrRuntimeArchitectureService;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SignInAttempts`: the one sign-in conversation a surface shows at a time, as a plain read model.
|
|
3
|
+
*
|
|
4
|
+
* `AuthorizationService.begin` runs a flow to its end and talks to the human through callbacks (notices, prompts). A
|
|
5
|
+
* request/response surface (a native window, a page) cannot hold a callback open, so this owns the conversation in
|
|
6
|
+
* between: it starts the flow, records what the flow said (`notices`) and asked (`prompt`), lets the surface answer or
|
|
7
|
+
* cancel by id, and reports how it ended. The terminal keeps its own copy of this logic inline; this is the shared one.
|
|
8
|
+
*
|
|
9
|
+
* Framework-free: the only dependency is a `begin` function, so it is unit-testable without Cordis. A secret typed into a
|
|
10
|
+
* prompt travels from `answer` to the flow and is never stored here.
|
|
11
|
+
*/
|
|
12
|
+
import type { AuthorizationBeginRequest, AuthorizationOutcome } from './types.ts';
|
|
13
|
+
/** What the running flow said: where to go, or what to do next. */
|
|
14
|
+
export interface SignInNotice {
|
|
15
|
+
readonly message: string;
|
|
16
|
+
readonly url?: string;
|
|
17
|
+
readonly code?: string;
|
|
18
|
+
}
|
|
19
|
+
/** A question the running flow waits on. */
|
|
20
|
+
export interface SignInPrompt {
|
|
21
|
+
/** Echoed back by `answer`, so a late answer to a withdrawn question is refused. */
|
|
22
|
+
readonly id: string;
|
|
23
|
+
readonly kind: 'text' | 'secret' | 'select';
|
|
24
|
+
readonly message: string;
|
|
25
|
+
readonly placeholder?: string;
|
|
26
|
+
readonly options?: readonly {
|
|
27
|
+
readonly id: string;
|
|
28
|
+
readonly label: string;
|
|
29
|
+
readonly description?: string;
|
|
30
|
+
}[];
|
|
31
|
+
}
|
|
32
|
+
export type SignInPhase = 'running' | 'authorized' | 'cancelled' | 'failed';
|
|
33
|
+
/** One attempt as a surface sees it. */
|
|
34
|
+
export interface SignInAttemptView {
|
|
35
|
+
readonly id: string;
|
|
36
|
+
readonly key: string;
|
|
37
|
+
readonly method: string | undefined;
|
|
38
|
+
readonly phase: SignInPhase;
|
|
39
|
+
/** The most recent notices, oldest first. */
|
|
40
|
+
readonly notices: readonly SignInNotice[];
|
|
41
|
+
/** The question the flow is waiting on, while `phase` is `running`. */
|
|
42
|
+
readonly prompt?: SignInPrompt;
|
|
43
|
+
/** Why a `failed` attempt failed, in words safe to show. */
|
|
44
|
+
readonly error?: string;
|
|
45
|
+
}
|
|
46
|
+
export interface SignInAttemptsDeps {
|
|
47
|
+
readonly begin: (request: AuthorizationBeginRequest) => Promise<AuthorizationOutcome>;
|
|
48
|
+
/** A fresh id for an attempt or a prompt. */
|
|
49
|
+
readonly newId: () => string;
|
|
50
|
+
}
|
|
51
|
+
/** A refused request (unknown attempt, stale prompt): the caller learns what to fix. */
|
|
52
|
+
export declare class SignInAttemptError extends Error {
|
|
53
|
+
readonly code: 'unknown-attempt' | 'unknown-prompt' | 'invalid-answer';
|
|
54
|
+
constructor(code: 'unknown-attempt' | 'unknown-prompt' | 'invalid-answer', message: string);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A flow's failure as a person reads it. Provider token endpoints answer with a JSON body that the flows quote whole
|
|
58
|
+
* ("... token exchange failed (401): { "error": { "message": "Could not validate your token. ..." } }"); keep the flow's
|
|
59
|
+
* own lead-in and the provider's sentence, drop the JSON around it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function readableFailure(cause: unknown): string;
|
|
62
|
+
export declare class SignInAttempts {
|
|
63
|
+
private readonly deps;
|
|
64
|
+
private live;
|
|
65
|
+
constructor(deps: SignInAttemptsDeps);
|
|
66
|
+
/** The latest attempt (running or settled), or undefined before any. */
|
|
67
|
+
current(): SignInAttemptView | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* Start an attempt, withdrawing a running one first (a surface that restarts has abandoned the old conversation).
|
|
70
|
+
* @returns the new attempt, already `running`.
|
|
71
|
+
*/
|
|
72
|
+
begin(key: string, method: string | undefined): SignInAttemptView;
|
|
73
|
+
/**
|
|
74
|
+
* Answer the question the flow is waiting on.
|
|
75
|
+
* @param promptId - the id of the prompt being answered, as the view showed it.
|
|
76
|
+
* @param value - the typed text or the chosen option id.
|
|
77
|
+
*/
|
|
78
|
+
answer(attemptId: string, promptId: string, value: string): SignInAttemptView;
|
|
79
|
+
/** Withdraw the attempt; a settled attempt is left as it ended. */
|
|
80
|
+
cancel(attemptId: string): SignInAttemptView;
|
|
81
|
+
private require;
|
|
82
|
+
private update;
|
|
83
|
+
/** Show (or clear) the question the flow waits on. */
|
|
84
|
+
private show;
|
|
85
|
+
/** Stop a running attempt: the flow's pending question is refused, which ends it as cancelled. */
|
|
86
|
+
private withdraw;
|
|
87
|
+
private run;
|
|
88
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `AuthorizationService`: the `beginAuthorization` use-case, owned outside
|
|
3
|
+
* the terminal surface (finding R1). Forwards to the underlying
|
|
4
|
+
* `AuthorizationPort`, activates the route on success (no display-name
|
|
5
|
+
* encoding — the `-oauth` suffix hack is deleted, not moved; see finding R2),
|
|
6
|
+
* and emits `credential.changed` so subscribers can invalidate a targeted
|
|
7
|
+
* projection instead of a shotgun dual reload (finding R4).
|
|
8
|
+
*
|
|
9
|
+
* Framework-free: every dependency is a plain port, so this is directly
|
|
10
|
+
* unit-testable with stubs — no Cordis boot required.
|
|
11
|
+
*/
|
|
12
|
+
import type { AuthorizationBeginRequest, AuthorizationOutcome, AuthorizationPort, CredentialChangedListener, DefaultModelAdoptionPort, RouteActivationPort } from './types.ts';
|
|
13
|
+
export interface AuthorizationServiceDeps {
|
|
14
|
+
readonly authorization: AuthorizationPort;
|
|
15
|
+
/** Optional: absent profiles degrade to "not available" (matches the surface's own optional-service pattern). */
|
|
16
|
+
readonly routeActivation?: RouteActivationPort;
|
|
17
|
+
/** Optional: runs after the route is active, so the route's models can be listed. */
|
|
18
|
+
readonly defaultModel?: DefaultModelAdoptionPort;
|
|
19
|
+
readonly onCredentialChanged: CredentialChangedListener;
|
|
20
|
+
}
|
|
21
|
+
export declare class AuthorizationService {
|
|
22
|
+
private readonly deps;
|
|
23
|
+
constructor(deps: AuthorizationServiceDeps);
|
|
24
|
+
begin(request: AuthorizationBeginRequest): Promise<AuthorizationOutcome>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** Typed authorization use-case contract: `/login`'s `beginAuthorization` action. */
|
|
2
|
+
/** A question the running flow needs answered before it can continue (opaque pass-through). */
|
|
3
|
+
export interface AuthorizationInteraction {
|
|
4
|
+
notify(notice: {
|
|
5
|
+
readonly message: string;
|
|
6
|
+
readonly url?: string;
|
|
7
|
+
readonly code?: string;
|
|
8
|
+
}): void;
|
|
9
|
+
prompt(prompt: {
|
|
10
|
+
readonly kind: 'text' | 'secret' | 'select';
|
|
11
|
+
readonly message: string;
|
|
12
|
+
readonly options?: readonly {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly label: string;
|
|
15
|
+
readonly description?: string;
|
|
16
|
+
}[];
|
|
17
|
+
readonly placeholder?: string;
|
|
18
|
+
readonly signal?: AbortSignal;
|
|
19
|
+
}): Promise<string>;
|
|
20
|
+
}
|
|
21
|
+
export interface AuthorizationBeginRequest {
|
|
22
|
+
/** The credential record key this flow writes (`<scope>/<id>`). */
|
|
23
|
+
readonly key: string;
|
|
24
|
+
readonly method: string | undefined;
|
|
25
|
+
readonly interaction: AuthorizationInteraction;
|
|
26
|
+
/** Withdraws the attempt (a Cancel button on a surface that is not the one holding the flow). */
|
|
27
|
+
readonly signal?: AbortSignal;
|
|
28
|
+
}
|
|
29
|
+
export interface AuthorizationOutcome {
|
|
30
|
+
readonly status: string;
|
|
31
|
+
readonly [extra: string]: unknown;
|
|
32
|
+
}
|
|
33
|
+
/** The underlying pi-ai (or equivalent) authorization flow runner. */
|
|
34
|
+
export interface AuthorizationPort {
|
|
35
|
+
begin(request: AuthorizationBeginRequest): Promise<AuthorizationOutcome>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Make a route usable from `/model` after a successful sign-in: `dsh-llm-pi-ai`
|
|
39
|
+
* only registers a route as live once its settings section names it (even an
|
|
40
|
+
* empty profile — "use the installed catalog's defaults" — counts), so a
|
|
41
|
+
* signed-in-but-never-configured route stays credentialed but absent from
|
|
42
|
+
* `ctx.llm`'s live directory otherwise. A no-op when the route already has a
|
|
43
|
+
* settings profile, so it never clobbers one the user already configured.
|
|
44
|
+
*/
|
|
45
|
+
export interface RouteActivationPort {
|
|
46
|
+
ensureRouteActivated(providerId: string, method: string | undefined): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Point new sessions at a just-signed-in provider when the current default
|
|
50
|
+
* cannot answer, so a first sign-in with anything but the composition's default
|
|
51
|
+
* provider does not leave the first message failing. A no-op when the current
|
|
52
|
+
* default works.
|
|
53
|
+
*/
|
|
54
|
+
export interface DefaultModelAdoptionPort {
|
|
55
|
+
adoptIfDefaultUnusable(providerId: string): Promise<void>;
|
|
56
|
+
}
|
|
57
|
+
export type CredentialChangedListener = (key: string) => void;
|
|
58
|
+
/** The service name of {@link AccountSignInPort}. */
|
|
59
|
+
export declare const ACCOUNT_SIGN_IN_SERVICE = "acrylAccountSignIn";
|
|
60
|
+
/**
|
|
61
|
+
* The key DeepSeek's account flow registers on `ctx.authorization` (`dsh-deepseek-account-platform`). It runs only once
|
|
62
|
+
* DeepSeek's account service has opened an attempt, so a surface never starts it through `begin`.
|
|
63
|
+
*/
|
|
64
|
+
export declare const DEEPSEEK_ACCOUNT_FLOW_KEY = "deepseek-account-platform/default";
|
|
65
|
+
export type AccountSignInOutcome = {
|
|
66
|
+
readonly status: 'authorized';
|
|
67
|
+
} | {
|
|
68
|
+
readonly status: 'cancelled';
|
|
69
|
+
} | {
|
|
70
|
+
readonly status: 'failed';
|
|
71
|
+
readonly error: string;
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* `acrylAccountSignIn`: DeepSeek account sign-in on a surface without a web server of its own (the terminal), provided by
|
|
75
|
+
* `acryl-sign-in/account-callback`. DeepSeek's account flow is registered on `ctx.authorization` as `key`, but it can only
|
|
76
|
+
* be started here; a surface lists it under that key and signs in through this port instead of `begin`.
|
|
77
|
+
*/
|
|
78
|
+
export interface AccountSignInPort {
|
|
79
|
+
/** The authorization flow key the sign-in writes ({@link DEEPSEEK_ACCOUNT_FLOW_KEY}). */
|
|
80
|
+
readonly key: string;
|
|
81
|
+
/** The model route a successful sign-in makes usable (`deepseek-account`). */
|
|
82
|
+
readonly route: string;
|
|
83
|
+
/** Start a sign-in and settle when it ends; `notify` receives the page to open in a browser. Aborting cancels it. */
|
|
84
|
+
signIn(request: {
|
|
85
|
+
readonly locale?: string;
|
|
86
|
+
readonly signal?: AbortSignal;
|
|
87
|
+
notify(url: string): void;
|
|
88
|
+
}): Promise<AccountSignInOutcome>;
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Presentation labels retained without a control transport. */
|
|
2
|
+
export type HostKind = 'tui' | 'gui' | 'web';
|
|
3
|
+
export type ControlCapability = string;
|
|
4
|
+
export type RestartClass = 'HOT' | 'WARM' | 'COLD';
|
|
5
|
+
export type ControlOperationState = 'CREATED' | 'VALIDATING' | 'DENIED' | 'READY' | 'RUNNING' | 'CANCELLING' | 'SETTLING' | 'SUCCEEDED' | 'FAILED' | 'RECOVERABLE' | 'CANCELLED';
|
|
6
|
+
export interface ControlOperation<TResult = unknown> {
|
|
7
|
+
readonly operationId: string;
|
|
8
|
+
readonly kind: string;
|
|
9
|
+
readonly profileKey: string;
|
|
10
|
+
readonly requestedAt: string;
|
|
11
|
+
readonly state: ControlOperationState;
|
|
12
|
+
readonly restartClass?: RestartClass;
|
|
13
|
+
readonly result?: TResult;
|
|
14
|
+
readonly error?: {
|
|
15
|
+
readonly code: string;
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly retryable: boolean;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export type AcrylExitClass = 'success' | 'usage' | 'unavailable' | 'denied' | 'conflict' | 'failed' | 'interrupted';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type AcrylSessionAttachment = 'owner' | 'attached';
|
|
2
|
+
export type AcrylSessionAgentStatus = 'idle' | 'running' | 'waiting' | 'failed';
|
|
3
|
+
export type AcrylTranscriptAuthor = 'user' | 'assistant';
|
|
4
|
+
export type AcrylToolStatus = 'pending' | 'running' | 'succeeded' | 'failed';
|
|
5
|
+
export interface AcrylTranscriptItem {
|
|
6
|
+
readonly id: string;
|
|
7
|
+
readonly author: AcrylTranscriptAuthor;
|
|
8
|
+
readonly text: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AcrylToolProjection {
|
|
11
|
+
readonly callId: string;
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly status: AcrylToolStatus;
|
|
14
|
+
}
|
|
15
|
+
export interface AcrylSessionSnapshot {
|
|
16
|
+
readonly profile: string;
|
|
17
|
+
readonly generationId: string;
|
|
18
|
+
readonly attachment: AcrylSessionAttachment;
|
|
19
|
+
readonly sessionId: string;
|
|
20
|
+
readonly agentStatus: AcrylSessionAgentStatus;
|
|
21
|
+
readonly transcript: readonly AcrylTranscriptItem[];
|
|
22
|
+
readonly tools: readonly AcrylToolProjection[];
|
|
23
|
+
}
|
|
24
|
+
export interface AcrylSessionSubscription {
|
|
25
|
+
dispose(): Promise<void>;
|
|
26
|
+
/** Resolves with the terminal endpoint-subscription failure, if one occurs. */
|
|
27
|
+
whenError(): Promise<Error>;
|
|
28
|
+
}
|
|
29
|
+
export interface AcrylSessionClient {
|
|
30
|
+
snapshot(sessionId: string): Promise<AcrylSessionSnapshot>;
|
|
31
|
+
subscribe(sessionId: string, listener: (snapshot: AcrylSessionSnapshot) => void, onError?: (error: Error) => void): Promise<AcrylSessionSubscription>;
|
|
32
|
+
submitPrompt(input: {
|
|
33
|
+
readonly sessionId: string;
|
|
34
|
+
readonly text: string;
|
|
35
|
+
readonly clientCommandId: string;
|
|
36
|
+
}): Promise<void>;
|
|
37
|
+
cancel(input: {
|
|
38
|
+
readonly sessionId: string;
|
|
39
|
+
}): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
/** Validate an untrusted control-plane session projection at the boundary. */
|
|
42
|
+
export declare function parseAcrylSessionSnapshot(value: unknown): AcrylSessionSnapshot;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createDefaultModelAdoption`: after a sign-in, make the signed-in provider the default for new sessions when the
|
|
3
|
+
* current default cannot answer (its provider has no credential or is not live).
|
|
4
|
+
*
|
|
5
|
+
* Without this, a first-run user who signs into Claude still gets new sessions on the composition's default (DeepSeek),
|
|
6
|
+
* and the first message fails. A default whose provider works is never replaced: the user's own choice wins.
|
|
7
|
+
*
|
|
8
|
+
* Framework-free like the rest of this folder: plain ports, no Cordis `Context`.
|
|
9
|
+
*/
|
|
10
|
+
import type { DefaultModelAdoptionPort } from '../authorization/types.ts';
|
|
11
|
+
export interface DefaultModelSelection {
|
|
12
|
+
readonly provider: string;
|
|
13
|
+
readonly model: string;
|
|
14
|
+
}
|
|
15
|
+
export interface DefaultModelAdoptionPorts {
|
|
16
|
+
/** `ctx.agentDefaultModel` (`dsh-agent-default-model`). */
|
|
17
|
+
readonly defaultModel: {
|
|
18
|
+
currentSelection(): DefaultModelSelection;
|
|
19
|
+
saveSelection(next: DefaultModelSelection): Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
/** Whether a provider route can answer a request now: live in `ctx.llm` and holding a credential. */
|
|
22
|
+
readonly isUsable: (provider: string) => Promise<boolean>;
|
|
23
|
+
/** The route's models in adapter order (`ctx.llm.listModels`). */
|
|
24
|
+
readonly listModels: (provider: string) => Promise<readonly {
|
|
25
|
+
readonly id: string;
|
|
26
|
+
}[]>;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The model a new session starts on for a provider ACRYL features on its sign-in screen, most preferred first. The
|
|
30
|
+
* installed catalog lists models alphabetically, so its first entry is no recommendation; a provider absent here (or
|
|
31
|
+
* whose preferred ids a catalog update removed) starts on that first entry instead.
|
|
32
|
+
*/
|
|
33
|
+
export declare const STARTING_MODELS: Readonly<Record<string, readonly string[]>>;
|
|
34
|
+
/** The model to start on from a route's catalog, or `undefined` when the route lists none. */
|
|
35
|
+
export declare function startingModel(provider: string, models: readonly {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
}[]): string | undefined;
|
|
38
|
+
export declare function createDefaultModelAdoption(ports: DefaultModelAdoptionPorts): DefaultModelAdoptionPort;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `CredentialProjection`: the one join of `ctx.llm` + `ctx.settings` +
|
|
3
|
+
* `ctx.credentials` into provider rows. Replaces the surface's own
|
|
4
|
+
* `computeProviderRows`/`loadAuthorizationFlows` duplicate joins (finding R1)
|
|
5
|
+
* so `/login` and `/model` read the same projection instead of two
|
|
6
|
+
* independently-fetched pictures of the same state.
|
|
7
|
+
*
|
|
8
|
+
* Framework-free: takes plain service ports (not a Cordis `Context`), so it
|
|
9
|
+
* is directly unit-testable with stubs — no Cordis boot required. The
|
|
10
|
+
* surface wires these ports from `host.ctx.get(...)`.
|
|
11
|
+
*/
|
|
12
|
+
import type { CredentialModelEntry, CredentialProjectionRow } from './types.ts';
|
|
13
|
+
export interface CredentialProjectionConfigurableProvider {
|
|
14
|
+
readonly provider: string;
|
|
15
|
+
readonly displayName: string;
|
|
16
|
+
readonly settingsNs: string;
|
|
17
|
+
readonly settingsPath: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export interface CredentialProjectionLlmPort {
|
|
20
|
+
listConfigurableProviders(): readonly CredentialProjectionConfigurableProvider[];
|
|
21
|
+
listProviders(): readonly {
|
|
22
|
+
readonly id: string;
|
|
23
|
+
}[];
|
|
24
|
+
listModels(provider: string): Promise<readonly CredentialModelEntry[]>;
|
|
25
|
+
}
|
|
26
|
+
export interface CredentialProjectionSettingsDescriptor {
|
|
27
|
+
readonly ns: string;
|
|
28
|
+
readonly value: unknown;
|
|
29
|
+
readonly user?: unknown;
|
|
30
|
+
readonly revision?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface CredentialProjectionSettingsPort {
|
|
33
|
+
describe(options: {
|
|
34
|
+
readonly redactSecrets: boolean;
|
|
35
|
+
}): readonly CredentialProjectionSettingsDescriptor[];
|
|
36
|
+
}
|
|
37
|
+
export interface CredentialProjectionRecord {
|
|
38
|
+
readonly kind: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CredentialProjectionCredentialsPort {
|
|
41
|
+
describe(ref: string): Promise<{
|
|
42
|
+
readonly configured: boolean;
|
|
43
|
+
}>;
|
|
44
|
+
readRecord?(key: string): Promise<CredentialProjectionRecord | undefined>;
|
|
45
|
+
}
|
|
46
|
+
export interface CredentialProjectionServices {
|
|
47
|
+
readonly llm: CredentialProjectionLlmPort;
|
|
48
|
+
readonly settings: CredentialProjectionSettingsPort;
|
|
49
|
+
readonly credentials: CredentialProjectionCredentialsPort;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The `apiKeyEnv` reference a provider route falls back to when its settings
|
|
53
|
+
* profile names none, e.g. `my-proxy` -> `MY_PROXY_API_KEY`. One rule for every
|
|
54
|
+
* surface (the terminal's `/model` and the Desktop sign-in read the same name).
|
|
55
|
+
*/
|
|
56
|
+
export declare function deriveApiKeyRef(route: string): string;
|
|
57
|
+
export interface CredentialProjectionOptions {
|
|
58
|
+
/** Derive the settings-fallback `apiKeyEnv` reference for a route with no stored profile. Defaults to {@link deriveApiKeyRef}. */
|
|
59
|
+
readonly deriveApiKeyRef?: (route: string) => string;
|
|
60
|
+
/**
|
|
61
|
+
* The scope a `/login` sign-in's own credential record lives under
|
|
62
|
+
* (`dsh-llm-pi-ai`'s `credentialKey(scope, providerId)`), separate from the
|
|
63
|
+
* `apiKeyEnv` reference a manually configured provider's settings profile
|
|
64
|
+
* points at. Defaults to `'llm-pi-ai'`.
|
|
65
|
+
*/
|
|
66
|
+
readonly loginRecordScope?: string;
|
|
67
|
+
}
|
|
68
|
+
export interface RouteUsabilityServices {
|
|
69
|
+
readonly llm: Pick<CredentialProjectionLlmPort, 'listConfigurableProviders' | 'listProviders'>;
|
|
70
|
+
readonly settings: CredentialProjectionSettingsPort;
|
|
71
|
+
readonly credentials: {
|
|
72
|
+
describe(ref: string): Promise<{
|
|
73
|
+
readonly configured: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
describeRecord(key: string): Promise<{
|
|
76
|
+
readonly configured: boolean;
|
|
77
|
+
}>;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Whether one route can answer a request now: live in `ctx.llm` and holding a credential (the settings profile's
|
|
82
|
+
* `apiKeyEnv` secret, or a sign-in's own record). The same credential rule as {@link computeCredentialProjection}, for
|
|
83
|
+
* one route and without reading any secret or model list.
|
|
84
|
+
*/
|
|
85
|
+
export declare function isRouteUsable(services: RouteUsabilityServices, provider: string, options?: CredentialProjectionOptions): Promise<boolean>;
|
|
86
|
+
/** Compute every provider route's joined credential/settings/live-registration row. */
|
|
87
|
+
export declare function computeCredentialProjection(services: CredentialProjectionServices, options: CredentialProjectionOptions): Promise<readonly CredentialProjectionRow[]>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `createRouteActivation`: make a provider usable right after a sign-in.
|
|
3
|
+
*
|
|
4
|
+
* A sign-in only ever writes a credential (the OAuth grant or the typed API key); it never touches `ctx.settings`.
|
|
5
|
+
* `dsh-llm-pi-ai` registers a route as live only once its settings section names it (an empty profile, which means "use
|
|
6
|
+
* the installed catalog's defaults", counts), so without this a successful sign-in leaves the provider credentialed but
|
|
7
|
+
* absent from `ctx.llm`'s live directory and unusable. It writes only when the route has no settings profile yet, so it
|
|
8
|
+
* never replaces one the user configured (custom base URL, model overrides), and never touches the display name.
|
|
9
|
+
*
|
|
10
|
+
* Framework-free like the rest of this folder: plain ports, no Cordis `Context`.
|
|
11
|
+
*/
|
|
12
|
+
import type { CredentialProjectionConfigurableProvider, CredentialProjectionSettingsPort } from './projection.ts';
|
|
13
|
+
import type { RouteActivationPort } from '../authorization/types.ts';
|
|
14
|
+
export interface RouteActivationSettingsPort extends CredentialProjectionSettingsPort {
|
|
15
|
+
update(ns: string, patch: Record<string, unknown>, expectedRevision?: number): Promise<unknown>;
|
|
16
|
+
}
|
|
17
|
+
export interface RouteActivationPorts {
|
|
18
|
+
readonly settings: RouteActivationSettingsPort;
|
|
19
|
+
readonly llm: {
|
|
20
|
+
listConfigurableProviders(): readonly CredentialProjectionConfigurableProvider[];
|
|
21
|
+
};
|
|
22
|
+
/** Wait out the settings watcher queue after a write, so the route is live when this resolves. */
|
|
23
|
+
readonly settled?: () => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function createRouteActivation(ports: RouteActivationPorts): RouteActivationPort;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed read-model for a provider route's credential/authorization state.
|
|
3
|
+
* `/login` and `/model` (in `acryl-cli`) both consume the *same* projection —
|
|
4
|
+
* this is the one place `hasCredential`/`hasSettingsProfile`/`isLive`/
|
|
5
|
+
* `authMethod` are defined, so no field means two different things across
|
|
6
|
+
* the two overlays (see `specs/001-acryl-refactor-improvements-and-tech-debt`,
|
|
7
|
+
* finding R3).
|
|
8
|
+
*/
|
|
9
|
+
/** How a stored credential was obtained. */
|
|
10
|
+
export type AuthMethod = 'oauth' | 'api-key';
|
|
11
|
+
/** One model entry within a provider's catalog (subset shared with the surface's own `ModelEntry`). */
|
|
12
|
+
export interface CredentialModelEntry {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly name?: string;
|
|
15
|
+
readonly contextWindow?: number;
|
|
16
|
+
readonly maxTokens?: number;
|
|
17
|
+
}
|
|
18
|
+
/** One provider route, joined from `ctx.llm` + `ctx.settings` + `ctx.credentials`. */
|
|
19
|
+
export interface CredentialProjectionRow {
|
|
20
|
+
readonly route: string;
|
|
21
|
+
readonly displayName: string;
|
|
22
|
+
readonly settingsNs: string;
|
|
23
|
+
readonly settingsPath: readonly string[];
|
|
24
|
+
/** Whether the user's settings document has an override for this route (a `/model` save, not a `/login` sign-in). */
|
|
25
|
+
readonly hasSettingsProfile: boolean;
|
|
26
|
+
/** Whether a credential — an `apiKeyEnv` secret or a `/login` record — is stored for this route. */
|
|
27
|
+
readonly hasCredential: boolean;
|
|
28
|
+
/** Whether the route is currently registered/live in `ctx.llm`. */
|
|
29
|
+
readonly isLive: boolean;
|
|
30
|
+
/** How the credential behind `hasCredential` was obtained, or `undefined` when none is configured. */
|
|
31
|
+
readonly authMethod: AuthMethod | undefined;
|
|
32
|
+
readonly api: string | undefined;
|
|
33
|
+
readonly baseURL: string | undefined;
|
|
34
|
+
readonly apiKeyRef: string;
|
|
35
|
+
readonly models: readonly CredentialModelEntry[];
|
|
36
|
+
/** Settings revision this row was read at; replay as `expectedRevision` on write. */
|
|
37
|
+
readonly revision: number | undefined;
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { ControlOperation } from './contracts/operations.ts';
|
|
3
|
+
export interface AgentRuntimeStatusEvent {
|
|
4
|
+
readonly runtimeId: string;
|
|
5
|
+
readonly providerId: string;
|
|
6
|
+
readonly status: 'idle' | 'running' | 'waiting' | 'stopping' | 'stopped' | 'failed';
|
|
7
|
+
}
|
|
8
|
+
declare module '@deepseek-ai/cordis' {
|
|
9
|
+
interface Events {
|
|
10
|
+
'acryl/operation-settled'(operation: ControlOperation): void;
|
|
11
|
+
'acryl/agent-runtime-status'(status: AgentRuntimeStatusEvent): void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export type { Context };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export { Context, Service } from '@deepseek-ai/cordis';
|
|
2
|
+
export * from './agent/agent-control.ts';
|
|
3
|
+
export * from './agent/transports/claude-stream.ts';
|
|
4
|
+
export * from './agent/providers/capabilities.ts';
|
|
5
|
+
export * from './agent/providers/factory.ts';
|
|
6
|
+
export * from './agent/providers/dsh-native.ts';
|
|
7
|
+
export * from './agent/providers/codex.ts';
|
|
8
|
+
export * from './agent/providers/claude.ts';
|
|
9
|
+
export * from './agent/providers/acp.ts';
|
|
10
|
+
export * from './architecture/projection.ts';
|
|
11
|
+
export * from './architecture/provider.ts';
|
|
12
|
+
export * from './contracts/operations.ts';
|
|
13
|
+
export * from './contracts/session.ts';
|
|
14
|
+
export * from './credential/types.ts';
|
|
15
|
+
export * from './credential/projection.ts';
|
|
16
|
+
export * from './credential/route-activation.ts';
|
|
17
|
+
export * from './credential/default-model.ts';
|
|
18
|
+
export * from './authorization/types.ts';
|
|
19
|
+
export * from './authorization/service.ts';
|
|
20
|
+
export * from './authorization/attempts.ts';
|
|
21
|
+
export * from './platform/web.ts';
|
|
22
|
+
export * from './platform/tools.ts';
|
|
23
|
+
export * from './events.ts';
|
|
24
|
+
export * from './plugin/controller.ts';
|
|
25
|
+
export * from './plugin/host.ts';
|
|
26
|
+
export * from './plugin/provider.ts';
|
|
27
|
+
export * from './plugin/types.ts';
|
|
28
|
+
export * from './protocol/client.ts';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tools port of the ACRYL platform: what ACRYL's own Host plugins need to give an agent a tool, and to have a say in whether a call runs, without
|
|
3
|
+
* importing a DeepSeek Harness package. A plugin injects `acrylTools` (optional where a chat may not exist), defines tools with {@link defineAcrylTool}
|
|
4
|
+
* and registers them; a policy decides allow, deny or ask before a call runs. The provider is an adapter in the engine seam (`acryl-harness-runtime`),
|
|
5
|
+
* so the registry behind it can change without touching a plugin.
|
|
6
|
+
*
|
|
7
|
+
* @module acryl-control/platform/tools
|
|
8
|
+
*/
|
|
9
|
+
/** A parameter of a tool: a JSON Schema type, whether it must be given, and a description for the model. */
|
|
10
|
+
export interface AcrylToolParam {
|
|
11
|
+
readonly type: 'string' | 'integer' | 'number' | 'boolean' | 'array' | 'object';
|
|
12
|
+
readonly required?: boolean;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
readonly [extra: string]: unknown;
|
|
15
|
+
}
|
|
16
|
+
type ValueOf<P extends AcrylToolParam> = P['type'] extends 'string' ? string : P['type'] extends 'integer' | 'number' ? number : P['type'] extends 'boolean' ? boolean : unknown;
|
|
17
|
+
/** The arguments object a tool receives, inferred from its parameter specs: required ones always present, the others optional. */
|
|
18
|
+
export type AcrylToolArgs<P extends Readonly<Record<string, AcrylToolParam>>> = {
|
|
19
|
+
readonly [K in keyof P as P[K]['required'] extends true ? K : never]: ValueOf<P[K]>;
|
|
20
|
+
} & {
|
|
21
|
+
readonly [K in keyof P as P[K]['required'] extends true ? never : K]?: ValueOf<P[K]>;
|
|
22
|
+
};
|
|
23
|
+
/** One block of what the model reads back. */
|
|
24
|
+
export interface AcrylToolBlock {
|
|
25
|
+
readonly type: 'text';
|
|
26
|
+
readonly text: string;
|
|
27
|
+
}
|
|
28
|
+
/** What a running tool is given besides its arguments. */
|
|
29
|
+
export interface AcrylToolExecution {
|
|
30
|
+
/** Aborted when the call is cancelled; a tool honours it. */
|
|
31
|
+
readonly signal: AbortSignal;
|
|
32
|
+
}
|
|
33
|
+
export interface AcrylToolDefinition {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly description: string;
|
|
36
|
+
readonly parameters: Readonly<Record<string, AcrylToolParam>>;
|
|
37
|
+
readonly output: {
|
|
38
|
+
/** JSON Schema of the value `execute` returns. */
|
|
39
|
+
readonly schema: Readonly<Record<string, unknown>>;
|
|
40
|
+
/** What the model reads, separately from the typed value. */
|
|
41
|
+
readonly render?: (args: never, value: never) => readonly AcrylToolBlock[];
|
|
42
|
+
};
|
|
43
|
+
readonly execute: (args: never, exec: AcrylToolExecution) => unknown;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Describe a tool with its arguments inferred from `parameters` and its value typed by `execute`. Plain data in, the same data out: the typing is the
|
|
47
|
+
* whole job.
|
|
48
|
+
*/
|
|
49
|
+
export declare function defineAcrylTool<const P extends Readonly<Record<string, AcrylToolParam>>, V>(definition: {
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly description: string;
|
|
52
|
+
readonly parameters: P;
|
|
53
|
+
readonly output: {
|
|
54
|
+
readonly schema: Readonly<Record<string, unknown>>;
|
|
55
|
+
readonly render?: (args: AcrylToolArgs<P>, value: V) => readonly AcrylToolBlock[];
|
|
56
|
+
};
|
|
57
|
+
readonly execute: (args: AcrylToolArgs<P>, exec: AcrylToolExecution) => V | Promise<V>;
|
|
58
|
+
}): AcrylToolDefinition;
|
|
59
|
+
/** The call a policy is asked about. */
|
|
60
|
+
export interface AcrylToolCall {
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly arguments: unknown;
|
|
63
|
+
/** The agent session that made the call, when there is one (an outside caller has none). */
|
|
64
|
+
readonly agent?: {
|
|
65
|
+
readonly session: unknown;
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export type AcrylToolDecision = {
|
|
69
|
+
readonly kind: 'allow';
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'deny';
|
|
72
|
+
readonly reason: string;
|
|
73
|
+
} | {
|
|
74
|
+
readonly kind: 'ask';
|
|
75
|
+
readonly reason?: string;
|
|
76
|
+
};
|
|
77
|
+
/** A policy: ask `next()` for what the rest of the chain would decide, and return it unchanged unless this policy has something to say. */
|
|
78
|
+
export type AcrylToolPolicy = (call: AcrylToolCall, next: () => Promise<AcrylToolDecision>) => Promise<AcrylToolDecision>;
|
|
79
|
+
/** A tool as the registry knows it. */
|
|
80
|
+
export interface AcrylToolInfo {
|
|
81
|
+
readonly name: string;
|
|
82
|
+
readonly description: string;
|
|
83
|
+
/** JSON Schema of the arguments. */
|
|
84
|
+
readonly parameters: Readonly<Record<string, unknown>>;
|
|
85
|
+
}
|
|
86
|
+
export interface AcrylToolResult {
|
|
87
|
+
readonly isError?: boolean;
|
|
88
|
+
readonly content?: ReadonlyArray<{
|
|
89
|
+
readonly type: string;
|
|
90
|
+
readonly text?: string;
|
|
91
|
+
}>;
|
|
92
|
+
}
|
|
93
|
+
export interface AcrylTools {
|
|
94
|
+
/** @returns the disposer that removes exactly this tool. */
|
|
95
|
+
register(definition: AcrylToolDefinition): () => void;
|
|
96
|
+
/** @returns the tool, or `undefined` when none by that name is registered. */
|
|
97
|
+
get(name: string): AcrylToolInfo | undefined;
|
|
98
|
+
/** Run a tool through the registry's whole pipeline: every policy applies. */
|
|
99
|
+
execute(input: {
|
|
100
|
+
readonly callId: string;
|
|
101
|
+
readonly name: string;
|
|
102
|
+
readonly arguments: unknown;
|
|
103
|
+
readonly signal: AbortSignal;
|
|
104
|
+
}): Promise<AcrylToolResult>;
|
|
105
|
+
/** @returns the disposer that removes exactly this policy. */
|
|
106
|
+
policy(handler: AcrylToolPolicy): () => void;
|
|
107
|
+
}
|
|
108
|
+
declare module '@deepseek-ai/cordis' {
|
|
109
|
+
interface Context {
|
|
110
|
+
acrylTools: AcrylTools;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The web port of the ACRYL platform: where the thing that serves the page listens, and nothing else. Routes and WebSocket upgrades are
|
|
3
|
+
* served by the framework's router (`ctx.router`, `ctx.routerHttp`); a plugin injects `acrylWeb` only for the address itself (the loopback
|
|
4
|
+
* check, an origin to hand to a child process). Plugins never inject a DeepSeek Harness service, so the carrier behind it can change (DSH's web
|
|
5
|
+
* server today, an ACRYL-owned one later) without touching them. The provider is an adapter in the engine seam (`acryl-harness-runtime`).
|
|
6
|
+
*
|
|
7
|
+
* @module acryl-control/platform/web
|
|
8
|
+
*/
|
|
9
|
+
export interface AcrylWeb {
|
|
10
|
+
/** The address the carrier is bound to. ACRYL's plugins refuse anything but loopback. */
|
|
11
|
+
readonly host: string;
|
|
12
|
+
/** The listening port (the OS-assigned one when it was configured as zero). */
|
|
13
|
+
readonly port: number;
|
|
14
|
+
}
|
|
15
|
+
declare module '@deepseek-ai/cordis' {
|
|
16
|
+
interface Context {
|
|
17
|
+
acrylWeb: AcrylWeb;
|
|
18
|
+
}
|
|
19
|
+
}
|