evolcore 0.0.8 → 0.0.9
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/CHANGELOG.md +24 -0
- package/README.md +37 -3
- package/dist/agents/baseagent.js +111 -19
- package/dist/agents/claude-runner.js +30 -2
- package/dist/agents/codex-app-server-client.js +31 -0
- package/dist/agents/codex-runner.js +3 -0
- package/dist/aun/msg/group.js +9 -9
- package/dist/aun/msg/p2p.js +11 -6
- package/dist/aun/msg/upload.js +43 -29
- package/dist/aun/outbox.js +48 -5
- package/dist/channels/aun.js +199 -50
- package/dist/cli/aun-commands.js +10 -7
- package/dist/cli/daemon-commands.js +19 -4
- package/dist/cli/index.js +11 -1
- package/dist/cli/init.js +103 -4
- package/dist/cli/model.js +5 -5
- package/dist/config/builtin-role-templates.js +4 -3
- package/dist/config/config-field-policy.js +6 -2
- package/dist/config/config-manager.js +48 -11
- package/dist/config/role-schema.js +18 -3
- package/dist/config/role-service.js +3 -3
- package/dist/config/role-store.js +4 -3
- package/dist/config-store.js +4 -0
- package/dist/core/auth/operation-authorizer.js +3 -1
- package/dist/core/bootstrap-service.js +0 -12
- package/dist/core/channel-loader.js +5 -1
- package/dist/core/command/command-handler.js +1 -1
- package/dist/core/command/evol-menu-version-gate.js +3 -2
- package/dist/core/command/menu-handler.js +33 -22
- package/dist/core/command/menu-protocol.js +7 -4
- package/dist/core/command/slash-handler.js +4 -4
- package/dist/core/inference/text-inference.js +18 -5
- package/dist/core/message/message-bridge.js +17 -6
- package/dist/core/message/response-engine.js +22 -3
- package/dist/core/model/config-scope.js +3 -3
- package/dist/core/permission/tool-policy.js +18 -0
- package/dist/index.js +43 -26
- package/dist/ipc.js +1 -1
- package/dist/product.js +1 -0
- package/dist/utils/autostart.js +27 -0
- package/dist/utils/ecweb-utils.js +15 -2
- package/dist/utils/macos-autostart.js +179 -0
- package/dist/utils/windows-autostart.js +130 -0
- package/ecagent/dist/agent-loop.d.ts +1 -1
- package/ecagent/dist/agent-loop.js +1 -1
- package/ecagent/dist/agent.d.ts +1 -1
- package/ecagent/dist/agent.js +1 -1
- package/ecagent/dist/harness/agent-harness.d.ts +1 -1
- package/ecagent/dist/harness/compaction/branch-summarization.d.ts +1 -1
- package/ecagent/dist/harness/compaction/compaction.d.ts +1 -1
- package/ecagent/dist/harness/compaction/utils.d.ts +1 -1
- package/ecagent/dist/harness/messages.d.ts +1 -1
- package/ecagent/dist/harness/session/session.d.ts +1 -1
- package/ecagent/dist/harness/types.d.ts +1 -1
- package/ecagent/dist/proxy.d.ts +1 -1
- package/ecagent/dist/proxy.js +1 -1
- package/ecagent/dist/types.d.ts +1 -1
- package/kits/migrations/migrate-role-config-v5.mjs +27 -2
- package/kits/schemas/agent-config.schema.10.json +19 -1
- package/kits/schemas/daemon.schema.4.json +4 -0
- package/kits/schemas/defaults.schema.4.json +15 -1
- package/kits/schemas/relation-config.schema.8.json +22 -1
- package/kits/schemas/role-config.schema.1.json +2 -2
- package/package.json +2 -4
- package/ecagent/dist/agent-loop.d.ts.map +0 -1
- package/ecagent/dist/agent-loop.js.map +0 -1
- package/ecagent/dist/agent.d.ts.map +0 -1
- package/ecagent/dist/agent.js.map +0 -1
- package/ecagent/dist/harness/agent-harness.d.ts.map +0 -1
- package/ecagent/dist/harness/agent-harness.js.map +0 -1
- package/ecagent/dist/harness/compaction/branch-summarization.d.ts.map +0 -1
- package/ecagent/dist/harness/compaction/branch-summarization.js.map +0 -1
- package/ecagent/dist/harness/compaction/compaction.d.ts.map +0 -1
- package/ecagent/dist/harness/compaction/compaction.js.map +0 -1
- package/ecagent/dist/harness/compaction/utils.d.ts.map +0 -1
- package/ecagent/dist/harness/compaction/utils.js.map +0 -1
- package/ecagent/dist/harness/env/nodejs.d.ts.map +0 -1
- package/ecagent/dist/harness/env/nodejs.js.map +0 -1
- package/ecagent/dist/harness/messages.d.ts.map +0 -1
- package/ecagent/dist/harness/messages.js.map +0 -1
- package/ecagent/dist/harness/prompt-templates.d.ts.map +0 -1
- package/ecagent/dist/harness/prompt-templates.js.map +0 -1
- package/ecagent/dist/harness/session/jsonl-repo.d.ts.map +0 -1
- package/ecagent/dist/harness/session/jsonl-repo.js.map +0 -1
- package/ecagent/dist/harness/session/jsonl-storage.d.ts.map +0 -1
- package/ecagent/dist/harness/session/jsonl-storage.js.map +0 -1
- package/ecagent/dist/harness/session/memory-repo.d.ts.map +0 -1
- package/ecagent/dist/harness/session/memory-repo.js.map +0 -1
- package/ecagent/dist/harness/session/memory-storage.d.ts.map +0 -1
- package/ecagent/dist/harness/session/memory-storage.js.map +0 -1
- package/ecagent/dist/harness/session/repo-utils.d.ts.map +0 -1
- package/ecagent/dist/harness/session/repo-utils.js.map +0 -1
- package/ecagent/dist/harness/session/session.d.ts.map +0 -1
- package/ecagent/dist/harness/session/session.js.map +0 -1
- package/ecagent/dist/harness/session/uuid.d.ts.map +0 -1
- package/ecagent/dist/harness/session/uuid.js.map +0 -1
- package/ecagent/dist/harness/skills.d.ts.map +0 -1
- package/ecagent/dist/harness/skills.js.map +0 -1
- package/ecagent/dist/harness/system-prompt.d.ts.map +0 -1
- package/ecagent/dist/harness/system-prompt.js.map +0 -1
- package/ecagent/dist/harness/types.d.ts.map +0 -1
- package/ecagent/dist/harness/types.js.map +0 -1
- package/ecagent/dist/harness/utils/shell-output.d.ts.map +0 -1
- package/ecagent/dist/harness/utils/shell-output.js.map +0 -1
- package/ecagent/dist/harness/utils/truncate.d.ts.map +0 -1
- package/ecagent/dist/harness/utils/truncate.js.map +0 -1
- package/ecagent/dist/index.d.ts.map +0 -1
- package/ecagent/dist/index.js.map +0 -1
- package/ecagent/dist/node.d.ts.map +0 -1
- package/ecagent/dist/node.js.map +0 -1
- package/ecagent/dist/proxy.d.ts.map +0 -1
- package/ecagent/dist/proxy.js.map +0 -1
- package/ecagent/dist/runtime/api/lazy.d.ts.map +0 -1
- package/ecagent/dist/runtime/api/lazy.js.map +0 -1
- package/ecagent/dist/runtime/api/pi-messages.d.ts.map +0 -1
- package/ecagent/dist/runtime/api/pi-messages.js.map +0 -1
- package/ecagent/dist/runtime/api/pi-messages.lazy.d.ts.map +0 -1
- package/ecagent/dist/runtime/api/pi-messages.lazy.js.map +0 -1
- package/ecagent/dist/runtime/auth/context.d.ts.map +0 -1
- package/ecagent/dist/runtime/auth/context.js.map +0 -1
- package/ecagent/dist/runtime/auth/credential-store.d.ts.map +0 -1
- package/ecagent/dist/runtime/auth/credential-store.js.map +0 -1
- package/ecagent/dist/runtime/auth/helpers.d.ts.map +0 -1
- package/ecagent/dist/runtime/auth/helpers.js.map +0 -1
- package/ecagent/dist/runtime/auth/resolve.d.ts.map +0 -1
- package/ecagent/dist/runtime/auth/resolve.js.map +0 -1
- package/ecagent/dist/runtime/auth/types.d.ts.map +0 -1
- package/ecagent/dist/runtime/auth/types.js.map +0 -1
- package/ecagent/dist/runtime/compat.d.ts.map +0 -1
- package/ecagent/dist/runtime/compat.js.map +0 -1
- package/ecagent/dist/runtime/index.d.ts.map +0 -1
- package/ecagent/dist/runtime/index.js.map +0 -1
- package/ecagent/dist/runtime/models.d.ts.map +0 -1
- package/ecagent/dist/runtime/models.js.map +0 -1
- package/ecagent/dist/runtime/oauth.d.ts.map +0 -1
- package/ecagent/dist/runtime/oauth.js.map +0 -1
- package/ecagent/dist/runtime/providers/faux.d.ts.map +0 -1
- package/ecagent/dist/runtime/providers/faux.js.map +0 -1
- package/ecagent/dist/runtime/types.d.ts.map +0 -1
- package/ecagent/dist/runtime/types.js.map +0 -1
- package/ecagent/dist/runtime/utils/diagnostics.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/diagnostics.js.map +0 -1
- package/ecagent/dist/runtime/utils/event-stream.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/event-stream.js.map +0 -1
- package/ecagent/dist/runtime/utils/headers.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/headers.js.map +0 -1
- package/ecagent/dist/runtime/utils/json-parse.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/json-parse.js.map +0 -1
- package/ecagent/dist/runtime/utils/oauth/types.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/oauth/types.js.map +0 -1
- package/ecagent/dist/runtime/utils/overflow.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/overflow.js.map +0 -1
- package/ecagent/dist/runtime/utils/provider-env.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/provider-env.js.map +0 -1
- package/ecagent/dist/runtime/utils/retry.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/retry.js.map +0 -1
- package/ecagent/dist/runtime/utils/typebox-helpers.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/typebox-helpers.js.map +0 -1
- package/ecagent/dist/runtime/utils/validation.d.ts.map +0 -1
- package/ecagent/dist/runtime/utils/validation.js.map +0 -1
- package/ecagent/dist/types.d.ts.map +0 -1
- package/ecagent/dist/types.js.map +0 -1
- package/ecagent/package.json +0 -93
- package/ecagent/src/agent-loop.ts +0 -792
- package/ecagent/src/agent.ts +0 -575
- package/ecagent/src/harness/agent-harness.ts +0 -1029
- package/ecagent/src/harness/compaction/branch-summarization.ts +0 -261
- package/ecagent/src/harness/compaction/compaction.ts +0 -753
- package/ecagent/src/harness/compaction/utils.ts +0 -144
- package/ecagent/src/harness/env/nodejs.ts +0 -569
- package/ecagent/src/harness/messages.ts +0 -164
- package/ecagent/src/harness/prompt-templates.ts +0 -267
- package/ecagent/src/harness/session/jsonl-repo.ts +0 -179
- package/ecagent/src/harness/session/jsonl-storage.ts +0 -314
- package/ecagent/src/harness/session/memory-repo.ts +0 -50
- package/ecagent/src/harness/session/memory-storage.ts +0 -133
- package/ecagent/src/harness/session/repo-utils.ts +0 -51
- package/ecagent/src/harness/session/session.ts +0 -338
- package/ecagent/src/harness/session/uuid.ts +0 -54
- package/ecagent/src/harness/skills.ts +0 -375
- package/ecagent/src/harness/system-prompt.ts +0 -34
- package/ecagent/src/harness/types.ts +0 -838
- package/ecagent/src/harness/utils/shell-output.ts +0 -135
- package/ecagent/src/harness/utils/truncate.ts +0 -344
- package/ecagent/src/index.ts +0 -46
- package/ecagent/src/node.ts +0 -2
- package/ecagent/src/proxy.ts +0 -367
- package/ecagent/src/runtime/api/lazy.ts +0 -70
- package/ecagent/src/runtime/api/pi-messages.lazy.ts +0 -4
- package/ecagent/src/runtime/api/pi-messages.ts +0 -436
- package/ecagent/src/runtime/auth/context.ts +0 -45
- package/ecagent/src/runtime/auth/credential-store.ts +0 -47
- package/ecagent/src/runtime/auth/helpers.ts +0 -46
- package/ecagent/src/runtime/auth/resolve.ts +0 -141
- package/ecagent/src/runtime/auth/types.ts +0 -182
- package/ecagent/src/runtime/compat.ts +0 -158
- package/ecagent/src/runtime/index.ts +0 -31
- package/ecagent/src/runtime/models.ts +0 -452
- package/ecagent/src/runtime/oauth.ts +0 -1
- package/ecagent/src/runtime/providers/faux.ts +0 -538
- package/ecagent/src/runtime/types.ts +0 -718
- package/ecagent/src/runtime/utils/diagnostics.ts +0 -45
- package/ecagent/src/runtime/utils/event-stream.ts +0 -88
- package/ecagent/src/runtime/utils/headers.ts +0 -18
- package/ecagent/src/runtime/utils/json-parse.ts +0 -124
- package/ecagent/src/runtime/utils/oauth/types.ts +0 -79
- package/ecagent/src/runtime/utils/overflow.ts +0 -165
- package/ecagent/src/runtime/utils/provider-env.ts +0 -52
- package/ecagent/src/runtime/utils/retry.ts +0 -101
- package/ecagent/src/runtime/utils/typebox-helpers.ts +0 -24
- package/ecagent/src/runtime/utils/validation.ts +0 -310
- package/ecagent/src/types.ts +0 -430
- package/ecagent/tsconfig.build.json +0 -32
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import type { Api, ImagesApi, ImagesModel, Model, ProviderEnv } from "../types.ts";
|
|
2
|
-
import type {
|
|
3
|
-
ApiKeyAuth,
|
|
4
|
-
ApiKeyCredential,
|
|
5
|
-
AuthContext,
|
|
6
|
-
AuthResult,
|
|
7
|
-
Credential,
|
|
8
|
-
CredentialStore,
|
|
9
|
-
OAuthAuth,
|
|
10
|
-
OAuthCredential,
|
|
11
|
-
ProviderAuth,
|
|
12
|
-
} from "./types.ts";
|
|
13
|
-
|
|
14
|
-
export type ModelsErrorCode = "model_source" | "model_validation" | "provider" | "stream" | "auth" | "oauth";
|
|
15
|
-
|
|
16
|
-
export interface AuthResolutionOverrides {
|
|
17
|
-
apiKey?: string;
|
|
18
|
-
env?: ProviderEnv;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class ModelsError extends Error {
|
|
22
|
-
readonly code: ModelsErrorCode;
|
|
23
|
-
|
|
24
|
-
constructor(code: ModelsErrorCode, message: string, options?: { cause?: unknown }) {
|
|
25
|
-
super(message, options);
|
|
26
|
-
this.name = "ModelsError";
|
|
27
|
-
this.code = code;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/** Model shape auth resolution receives: chat or image-generation models. */
|
|
32
|
-
export type AuthModel = Model<Api> | ImagesModel<ImagesApi>;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Auth resolution shared by the `Models` and `ImagesModels` collections.
|
|
36
|
-
* A stored credential owns the provider: ambient/env is consulted only when
|
|
37
|
-
* nothing is stored. No silent env fallback after a failed refresh or for a
|
|
38
|
-
* credential type without a matching handler.
|
|
39
|
-
*/
|
|
40
|
-
export async function resolveProviderAuth(
|
|
41
|
-
provider: { id: string; auth: ProviderAuth },
|
|
42
|
-
model: AuthModel,
|
|
43
|
-
credentials: CredentialStore,
|
|
44
|
-
authContext: AuthContext,
|
|
45
|
-
overrides?: AuthResolutionOverrides,
|
|
46
|
-
): Promise<AuthResult | undefined> {
|
|
47
|
-
const requestAuthContext = overrides?.env ? overlayEnvAuthContext(authContext, overrides.env) : authContext;
|
|
48
|
-
|
|
49
|
-
if (overrides?.apiKey !== undefined && provider.auth.apiKey) {
|
|
50
|
-
return resolveApiKey(requestAuthContext, provider.auth.apiKey, model, {
|
|
51
|
-
type: "api_key",
|
|
52
|
-
key: overrides.apiKey,
|
|
53
|
-
env: overrides.env,
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const stored = await readCredential(credentials, provider.id);
|
|
58
|
-
if (stored) {
|
|
59
|
-
if (stored.type === "oauth" && provider.auth.oauth) {
|
|
60
|
-
return resolveStoredOAuth(credentials, provider.id, provider.auth.oauth, stored);
|
|
61
|
-
}
|
|
62
|
-
if (stored.type === "api_key" && provider.auth.apiKey) {
|
|
63
|
-
const credential = overrides?.env ? { ...stored, env: { ...stored.env, ...overrides.env } } : stored;
|
|
64
|
-
return resolveApiKey(requestAuthContext, provider.auth.apiKey, model, credential);
|
|
65
|
-
}
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Ambient (env vars, AWS profiles, ADC files).
|
|
70
|
-
return provider.auth.apiKey ? resolveApiKey(requestAuthContext, provider.auth.apiKey, model, undefined) : undefined;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function overlayEnvAuthContext(base: AuthContext, env: ProviderEnv): AuthContext {
|
|
74
|
-
return {
|
|
75
|
-
env: async (name) => env[name] || (await base.env(name)),
|
|
76
|
-
fileExists: (path) => base.fileExists(path),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* OAuth resolution with double-checked locking (same pattern as today's
|
|
82
|
-
* AuthStorage): valid tokens cost zero locks; expired tokens lock, re-check
|
|
83
|
-
* expiry under the lock, refresh once globally, and persist the rotated
|
|
84
|
-
* credential before release.
|
|
85
|
-
*/
|
|
86
|
-
async function resolveStoredOAuth(
|
|
87
|
-
credentials: CredentialStore,
|
|
88
|
-
providerId: string,
|
|
89
|
-
oauth: OAuthAuth,
|
|
90
|
-
stored: OAuthCredential,
|
|
91
|
-
): Promise<AuthResult | undefined> {
|
|
92
|
-
let credential = stored;
|
|
93
|
-
|
|
94
|
-
if (Date.now() >= credential.expires) {
|
|
95
|
-
// Optimistic check said expired; the authoritative check runs under the lock.
|
|
96
|
-
let post: Credential | undefined;
|
|
97
|
-
try {
|
|
98
|
-
post = await credentials.modify(providerId, async (current) => {
|
|
99
|
-
if (current?.type !== "oauth") return undefined; // logged out meanwhile
|
|
100
|
-
if (Date.now() < current.expires) return undefined; // another process/request refreshed
|
|
101
|
-
try {
|
|
102
|
-
return await oauth.refresh(current);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
throw new ModelsError("oauth", `OAuth refresh failed for ${providerId}`, { cause: error });
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
} catch (error) {
|
|
108
|
-
if (error instanceof ModelsError) throw error;
|
|
109
|
-
throw new ModelsError("auth", `Credential store modify failed for ${providerId}`, { cause: error });
|
|
110
|
-
}
|
|
111
|
-
if (post?.type !== "oauth") return undefined; // logged out meanwhile
|
|
112
|
-
credential = post;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
try {
|
|
116
|
-
return { auth: await oauth.toAuth(credential), source: "OAuth" };
|
|
117
|
-
} catch (error) {
|
|
118
|
-
throw new ModelsError("oauth", `OAuth auth derivation failed for ${providerId}`, { cause: error });
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function resolveApiKey(
|
|
123
|
-
authContext: AuthContext,
|
|
124
|
-
apiKey: ApiKeyAuth,
|
|
125
|
-
model: AuthModel,
|
|
126
|
-
credential: ApiKeyCredential | undefined,
|
|
127
|
-
): Promise<AuthResult | undefined> {
|
|
128
|
-
try {
|
|
129
|
-
return await apiKey.resolve({ model, ctx: authContext, credential });
|
|
130
|
-
} catch (error) {
|
|
131
|
-
throw new ModelsError("auth", `API key auth failed for provider ${model.provider}`, { cause: error });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function readCredential(credentials: CredentialStore, providerId: string): Promise<Credential | undefined> {
|
|
136
|
-
try {
|
|
137
|
-
return await credentials.read(providerId);
|
|
138
|
-
} catch (error) {
|
|
139
|
-
throw new ModelsError("auth", `Credential store read failed for ${providerId}`, { cause: error });
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import type { Api, ImagesApi, ImagesModel, Model, ProviderEnv, ProviderHeaders } from "../types.ts";
|
|
2
|
-
import type { OAuthCredentials } from "../utils/oauth/types.ts";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Request auth for a single model request. If a value cannot be expressed as
|
|
6
|
-
* `apiKey`, `headers`, or `baseUrl`, it is provider config, not auth.
|
|
7
|
-
*/
|
|
8
|
-
export interface ModelAuth {
|
|
9
|
-
apiKey?: string;
|
|
10
|
-
headers?: ProviderHeaders;
|
|
11
|
-
baseUrl?: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Stored api-key credential. `env` holds provider-scoped environment/config
|
|
16
|
-
* values such as Cloudflare account/gateway ids.
|
|
17
|
-
*/
|
|
18
|
-
export interface ApiKeyCredential {
|
|
19
|
-
type: "api_key";
|
|
20
|
-
key?: string;
|
|
21
|
-
env?: ProviderEnv;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** Stored OAuth credential (`access`, `refresh`, `expires` from OAuthCredentials). */
|
|
25
|
-
export interface OAuthCredential extends OAuthCredentials {
|
|
26
|
-
type: "oauth";
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** One type-tagged credential per provider — the shape of today's auth.json. */
|
|
30
|
-
export type Credential = ApiKeyCredential | OAuthCredential;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* App-owned credential storage, keyed by `Provider.id`, one credential per
|
|
34
|
-
* provider. `modify` is the only write path, so every mutation is a
|
|
35
|
-
* serialized read-modify-write; `Models.getAuth()` runs OAuth refresh inside
|
|
36
|
-
* `modify` so concurrent requests cannot double-refresh a rotated token. The
|
|
37
|
-
* app persists a credential after login via
|
|
38
|
-
* `modify(provider.id, async () => credential)`. Login/logout orchestration
|
|
39
|
-
* is app-owned.
|
|
40
|
-
*
|
|
41
|
-
* Error semantics: `read` resolves `undefined` for missing entries. Methods
|
|
42
|
-
* reject only on storage failure; `Models` wraps such rejections in
|
|
43
|
-
* `ModelsError` with code "auth". Best-effort stores that serve an in-memory
|
|
44
|
-
* view and record persistence errors internally (like coding-agent's
|
|
45
|
-
* AuthStorage) are valid implementations.
|
|
46
|
-
*/
|
|
47
|
-
export interface CredentialStore {
|
|
48
|
-
/**
|
|
49
|
-
* Read the stored credential, possibly expired. Display/status use;
|
|
50
|
-
* resolved request auth comes from `Models.getAuth()`.
|
|
51
|
-
*/
|
|
52
|
-
read(providerId: string): Promise<Credential | undefined>;
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Serialized write — the only write path. `fn` sees the current credential
|
|
56
|
-
* because correct writes (refresh, login-during-refresh) depend on it;
|
|
57
|
-
* return the new credential, or undefined to leave the entry unchanged.
|
|
58
|
-
* Mutual exclusion per provider id, cross-process too where the backing
|
|
59
|
-
* store supports it (e.g. a file lock). Resolves with the post-write
|
|
60
|
-
* credential. Rejections from `fn` propagate.
|
|
61
|
-
*/
|
|
62
|
-
modify(
|
|
63
|
-
providerId: string,
|
|
64
|
-
fn: (current: Credential | undefined) => Promise<Credential | undefined>,
|
|
65
|
-
): Promise<Credential | undefined>;
|
|
66
|
-
|
|
67
|
-
/** Remove a credential (logout). Implementations serialize this against `modify`. */
|
|
68
|
-
delete(providerId: string): Promise<void>;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** Environment access for auth resolution. Injectable for tests and browsers. */
|
|
72
|
-
export interface AuthContext {
|
|
73
|
-
env(name: string): Promise<string | undefined>;
|
|
74
|
-
/** Check whether a file exists. Supports a leading `~`. Always false in browsers. */
|
|
75
|
-
fileExists(path: string): Promise<boolean>;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/** Result of resolving auth for a model. */
|
|
79
|
-
export interface AuthResult {
|
|
80
|
-
auth: ModelAuth;
|
|
81
|
-
/** Provider-scoped environment/config values resolved from credentials and ambient context. */
|
|
82
|
-
env?: ProviderEnv;
|
|
83
|
-
/** Human-readable label for status UI: "ANTHROPIC_API_KEY", "OAuth", "~/.aws/credentials". */
|
|
84
|
-
source?: string;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Prompt shown to the user during login. `signal` lets the flow cancel a
|
|
89
|
-
* pending prompt when an out-of-band event resolves the step, e.g. a
|
|
90
|
-
* `manual_code` prompt raced against a callback server, aborted when the
|
|
91
|
-
* callback wins.
|
|
92
|
-
*/
|
|
93
|
-
export type AuthPrompt = { signal?: AbortSignal } & (
|
|
94
|
-
| { type: "text"; message: string; placeholder?: string }
|
|
95
|
-
| { type: "secret"; message: string; placeholder?: string }
|
|
96
|
-
| { type: "select"; message: string; options: readonly { id: string; label: string; description?: string }[] }
|
|
97
|
-
| { type: "manual_code"; message: string; placeholder?: string }
|
|
98
|
-
);
|
|
99
|
-
|
|
100
|
-
export type AuthEvent =
|
|
101
|
-
| { type: "auth_url"; url: string; instructions?: string }
|
|
102
|
-
| {
|
|
103
|
-
type: "device_code";
|
|
104
|
-
userCode: string;
|
|
105
|
-
verificationUri: string;
|
|
106
|
-
intervalSeconds?: number;
|
|
107
|
-
expiresInSeconds?: number;
|
|
108
|
-
}
|
|
109
|
-
| { type: "progress"; message: string };
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Login interaction callbacks serving both api-key and OAuth flows.
|
|
113
|
-
*
|
|
114
|
-
* `prompt()` returns the entered/selected string (`select` returns the option
|
|
115
|
-
* id). Rejects on cancel/abort. `signal` aborts the whole login flow;
|
|
116
|
-
* per-prompt cancellation uses `AuthPrompt.signal`.
|
|
117
|
-
*/
|
|
118
|
-
export interface AuthLoginCallbacks {
|
|
119
|
-
signal?: AbortSignal;
|
|
120
|
-
|
|
121
|
-
prompt(prompt: AuthPrompt): Promise<string>;
|
|
122
|
-
notify(event: AuthEvent): void;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Api-key auth: stored key/provider env plus ambient sources (env vars, AWS
|
|
127
|
-
* profiles, ADC files). Ambient-only providers omit `login`.
|
|
128
|
-
*/
|
|
129
|
-
export interface ApiKeyAuth {
|
|
130
|
-
/** Display name, e.g. "Anthropic API key". */
|
|
131
|
-
name: string;
|
|
132
|
-
|
|
133
|
-
/** Interactive setup (prompt for key/provider env). Absent = ambient-only. */
|
|
134
|
-
login?(callbacks: AuthLoginCallbacks): Promise<ApiKeyCredential>;
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Resolve auth from the stored credential and/or ambient sources, merging
|
|
138
|
-
* per field (`credential.key ?? env("...")`, `credential.env?.NAME ?? env("...")`).
|
|
139
|
-
* undefined = not configured. Receives the chat or image-generation model
|
|
140
|
-
* the request is for (both carry `provider` and `baseUrl`).
|
|
141
|
-
*/
|
|
142
|
-
resolve(input: {
|
|
143
|
-
model: Model<Api> | ImagesModel<ImagesApi>;
|
|
144
|
-
ctx: AuthContext;
|
|
145
|
-
credential?: ApiKeyCredential;
|
|
146
|
-
}): Promise<AuthResult | undefined>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* OAuth auth. The `refresh`/`toAuth` split lets `Models` own the locked
|
|
151
|
-
* refresh pattern: `refresh` produces a credential, `toAuth` derives request
|
|
152
|
-
* auth from whatever credential ends up stored.
|
|
153
|
-
*/
|
|
154
|
-
export interface OAuthAuth {
|
|
155
|
-
/** Display name, e.g. "Anthropic (Claude Pro/Max)". */
|
|
156
|
-
name: string;
|
|
157
|
-
|
|
158
|
-
login(callbacks: AuthLoginCallbacks): Promise<OAuthCredential>;
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* Exchange the refresh token. Network call; throws on failure
|
|
162
|
-
* (invalid_grant etc.). `Models` runs this under the store lock.
|
|
163
|
-
*/
|
|
164
|
-
refresh(credential: OAuthCredential): Promise<OAuthCredential>;
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Side-effect-free derivation of request auth from a valid credential.
|
|
168
|
-
* Covers per-credential baseUrl (GitHub Copilot). Async so lazy wrappers
|
|
169
|
-
* can load the implementation on first use.
|
|
170
|
-
*/
|
|
171
|
-
toAuth(credential: OAuthCredential): Promise<ModelAuth>;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Provider auth. At least one of `apiKey`/`oauth` must be present: even
|
|
176
|
-
* ambient-credential providers and keyless local servers provide `apiKey`
|
|
177
|
-
* auth whose `resolve()` reports whether the provider is configured.
|
|
178
|
-
*/
|
|
179
|
-
export interface ProviderAuth {
|
|
180
|
-
apiKey?: ApiKeyAuth;
|
|
181
|
-
oauth?: OAuthAuth;
|
|
182
|
-
}
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
export * from "./index.ts";
|
|
2
|
-
export * from "./api/pi-messages.lazy.ts";
|
|
3
|
-
|
|
4
|
-
import { piMessagesApi } from "./api/pi-messages.lazy.ts";
|
|
5
|
-
import { createFauxCore, type FauxProviderRegistration, type RegisterFauxProviderOptions } from "./providers/faux.ts";
|
|
6
|
-
import type {
|
|
7
|
-
Api,
|
|
8
|
-
AssistantMessage,
|
|
9
|
-
AssistantMessageEventStream,
|
|
10
|
-
Context,
|
|
11
|
-
Model,
|
|
12
|
-
ProviderStreamOptions,
|
|
13
|
-
SimpleStreamOptions,
|
|
14
|
-
StreamFunction,
|
|
15
|
-
StreamOptions,
|
|
16
|
-
} from "./types.ts";
|
|
17
|
-
|
|
18
|
-
export type ApiStreamFunction = (
|
|
19
|
-
model: Model<Api>,
|
|
20
|
-
context: Context,
|
|
21
|
-
options?: StreamOptions,
|
|
22
|
-
) => AssistantMessageEventStream;
|
|
23
|
-
|
|
24
|
-
export type ApiStreamSimpleFunction = (
|
|
25
|
-
model: Model<Api>,
|
|
26
|
-
context: Context,
|
|
27
|
-
options?: SimpleStreamOptions,
|
|
28
|
-
) => AssistantMessageEventStream;
|
|
29
|
-
|
|
30
|
-
export interface ApiProvider<TApi extends Api = Api, TOptions extends StreamOptions = StreamOptions> {
|
|
31
|
-
api: TApi;
|
|
32
|
-
stream: StreamFunction<TApi, TOptions>;
|
|
33
|
-
streamSimple: StreamFunction<TApi, SimpleStreamOptions>;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
interface ApiProviderInternal {
|
|
37
|
-
api: Api;
|
|
38
|
-
stream: ApiStreamFunction;
|
|
39
|
-
streamSimple: ApiStreamSimpleFunction;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const apiProviderRegistry = new Map<string, { provider: ApiProviderInternal; sourceId?: string }>();
|
|
43
|
-
|
|
44
|
-
function wrapStream<TApi extends Api, TOptions extends StreamOptions>(
|
|
45
|
-
api: TApi,
|
|
46
|
-
streamFunction: StreamFunction<TApi, TOptions>,
|
|
47
|
-
): ApiStreamFunction {
|
|
48
|
-
return (model, context, options) => {
|
|
49
|
-
if (model.api !== api) throw new Error(`Mismatched api: ${model.api} expected ${api}`);
|
|
50
|
-
return streamFunction(model as Model<TApi>, context, options as TOptions);
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function wrapStreamSimple<TApi extends Api>(
|
|
55
|
-
api: TApi,
|
|
56
|
-
streamFunction: StreamFunction<TApi, SimpleStreamOptions>,
|
|
57
|
-
): ApiStreamSimpleFunction {
|
|
58
|
-
return (model, context, options) => {
|
|
59
|
-
if (model.api !== api) throw new Error(`Mismatched api: ${model.api} expected ${api}`);
|
|
60
|
-
return streamFunction(model as Model<TApi>, context, options);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function registerApiProvider<TApi extends Api, TOptions extends StreamOptions>(
|
|
65
|
-
provider: ApiProvider<TApi, TOptions>,
|
|
66
|
-
sourceId?: string,
|
|
67
|
-
): void {
|
|
68
|
-
apiProviderRegistry.set(provider.api, {
|
|
69
|
-
provider: {
|
|
70
|
-
api: provider.api,
|
|
71
|
-
stream: wrapStream(provider.api, provider.stream),
|
|
72
|
-
streamSimple: wrapStreamSimple(provider.api, provider.streamSimple),
|
|
73
|
-
},
|
|
74
|
-
sourceId,
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function getApiProvider(api: Api): ApiProviderInternal | undefined {
|
|
79
|
-
return apiProviderRegistry.get(api)?.provider;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function getApiProviders(): ApiProviderInternal[] {
|
|
83
|
-
return Array.from(apiProviderRegistry.values(), (entry) => entry.provider);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export function unregisterApiProviders(sourceId: string): void {
|
|
87
|
-
for (const [api, entry] of apiProviderRegistry.entries()) {
|
|
88
|
-
if (entry.sourceId === sourceId) apiProviderRegistry.delete(api);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export function registerFauxProvider(options: RegisterFauxProviderOptions = {}): FauxProviderRegistration {
|
|
93
|
-
const core = createFauxCore(options);
|
|
94
|
-
const sourceId = `faux-provider-${Math.random().toString(36).slice(2, 10)}`;
|
|
95
|
-
registerApiProvider({ api: core.api, stream: core.stream, streamSimple: core.streamSimple }, sourceId);
|
|
96
|
-
return {
|
|
97
|
-
api: core.api,
|
|
98
|
-
models: core.models,
|
|
99
|
-
getModel: core.getModel,
|
|
100
|
-
state: core.state,
|
|
101
|
-
setResponses: core.setResponses,
|
|
102
|
-
appendResponses: core.appendResponses,
|
|
103
|
-
getPendingResponseCount: core.getPendingResponseCount,
|
|
104
|
-
unregister: () => unregisterApiProviders(sourceId),
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function registerBuiltInApiProviders(): void {
|
|
109
|
-
if (!getApiProvider("pi-messages")) {
|
|
110
|
-
const streams = piMessagesApi();
|
|
111
|
-
registerApiProvider({ api: "pi-messages", stream: streams.stream, streamSimple: streams.streamSimple });
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function resetApiProviders(): void {
|
|
116
|
-
apiProviderRegistry.clear();
|
|
117
|
-
registerBuiltInApiProviders();
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
registerBuiltInApiProviders();
|
|
121
|
-
|
|
122
|
-
function requireApiProvider(api: Api): ApiProviderInternal {
|
|
123
|
-
const provider = getApiProvider(api);
|
|
124
|
-
if (!provider) throw new Error(`No API provider registered for api: ${api}`);
|
|
125
|
-
return provider;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export function stream<TApi extends Api>(
|
|
129
|
-
model: Model<TApi>,
|
|
130
|
-
context: Context,
|
|
131
|
-
options?: ProviderStreamOptions,
|
|
132
|
-
): AssistantMessageEventStream {
|
|
133
|
-
return requireApiProvider(model.api).stream(model, context, options);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export async function complete<TApi extends Api>(
|
|
137
|
-
model: Model<TApi>,
|
|
138
|
-
context: Context,
|
|
139
|
-
options?: ProviderStreamOptions,
|
|
140
|
-
): Promise<AssistantMessage> {
|
|
141
|
-
return stream(model, context, options).result();
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export function streamSimple<TApi extends Api>(
|
|
145
|
-
model: Model<TApi>,
|
|
146
|
-
context: Context,
|
|
147
|
-
options?: SimpleStreamOptions,
|
|
148
|
-
): AssistantMessageEventStream {
|
|
149
|
-
return requireApiProvider(model.api).streamSimple(model, context, options);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export async function completeSimple<TApi extends Api>(
|
|
153
|
-
model: Model<TApi>,
|
|
154
|
-
context: Context,
|
|
155
|
-
options?: SimpleStreamOptions,
|
|
156
|
-
): Promise<AssistantMessage> {
|
|
157
|
-
return streamSimple(model, context, options).result();
|
|
158
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
export type { Static, TSchema } from "typebox";
|
|
2
|
-
export { Type } from "typebox";
|
|
3
|
-
export * from "./api/lazy.ts";
|
|
4
|
-
export type { PiMessagesEvent, PiMessagesOptions, PiMessagesRewriteImpact } from "./api/pi-messages.ts";
|
|
5
|
-
export * from "./auth/context.ts";
|
|
6
|
-
export * from "./auth/credential-store.ts";
|
|
7
|
-
export * from "./auth/helpers.ts";
|
|
8
|
-
export * from "./auth/types.ts";
|
|
9
|
-
export * from "./models.ts";
|
|
10
|
-
export * from "./providers/faux.ts";
|
|
11
|
-
export * from "./types.ts";
|
|
12
|
-
export * from "./utils/diagnostics.ts";
|
|
13
|
-
export * from "./utils/event-stream.ts";
|
|
14
|
-
export * from "./utils/json-parse.ts";
|
|
15
|
-
export type {
|
|
16
|
-
OAuthAuthInfo,
|
|
17
|
-
OAuthCredentials,
|
|
18
|
-
OAuthDeviceCodeInfo,
|
|
19
|
-
OAuthLoginCallbacks,
|
|
20
|
-
OAuthPrompt,
|
|
21
|
-
OAuthProvider,
|
|
22
|
-
OAuthProviderId,
|
|
23
|
-
OAuthProviderInfo,
|
|
24
|
-
OAuthProviderInterface,
|
|
25
|
-
OAuthSelectOption,
|
|
26
|
-
OAuthSelectPrompt,
|
|
27
|
-
} from "./utils/oauth/types.ts";
|
|
28
|
-
export * from "./utils/overflow.ts";
|
|
29
|
-
export * from "./utils/retry.ts";
|
|
30
|
-
export * from "./utils/typebox-helpers.ts";
|
|
31
|
-
export * from "./utils/validation.ts";
|