@humain/humain-code 0.4.9 → 0.4.10
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 +22 -0
- package/dist/bundle/agent-monitor.js +1 -1
- package/dist/bundle/chunks/bedrock-converse-stream.js +39 -45
- package/dist/bundle/chunks/{chunk-6FVNSW6B.js → chunk-2QTTNAD4.js} +3353 -3938
- package/dist/bundle/chunks/chunk-76X5KOIA.js +28 -0
- package/dist/bundle/chunks/{chunk-KRMTBTWU.js → chunk-77EWF2NW.js} +1 -1
- package/dist/bundle/chunks/{chunk-RBKDBF5G.js → chunk-AS2Y2MO6.js} +36 -36
- package/dist/bundle/chunks/{chunk-4LAKI5IL.js → chunk-AUFEF24K.js} +1 -1
- package/dist/bundle/chunks/{chunk-P4YMUUSK.js → chunk-BCF7KZ3R.js} +739 -730
- package/dist/bundle/chunks/{chunk-W2QRCQBX.js → chunk-FF26YENK.js} +3 -4
- package/dist/bundle/chunks/{chunk-UZ5FVVCP.js → chunk-HMWAH7ZY.js} +1 -1
- package/dist/bundle/chunks/{chunk-F7UMX5BV.js → chunk-HSDTSUZE.js} +13 -2
- package/dist/bundle/chunks/chunk-I2ZWZAIV.js +751 -0
- package/dist/bundle/chunks/{chunk-GUUAEK6G.js → chunk-LCOHFEZZ.js} +1 -1
- package/dist/bundle/chunks/{chunk-Z5LYSSTY.js → chunk-QSPDLT2R.js} +2 -2
- package/dist/bundle/chunks/{chunk-UBQSONVR.js → chunk-R5VIAWGA.js} +103 -145
- package/dist/bundle/chunks/{chunk-EMYNPLY5.js → chunk-V5ZF7Q7L.js} +1 -1
- package/dist/bundle/chunks/{chunk-LQ4S7CRR.js → chunk-VYIIPF57.js} +1 -1
- package/dist/bundle/chunks/chunk-WBJN6PEI.js +43 -0
- package/dist/bundle/chunks/{chunk-SWRU4BOC.js → chunk-XGO43DKL.js} +1 -1
- package/dist/bundle/chunks/{chunk-PMISFIBM.js → chunk-XMHLSV3I.js} +1 -1
- package/dist/bundle/chunks/{chunk-3E4SMILM.js → chunk-YJBE3IGR.js} +14 -14
- package/dist/bundle/chunks/{cli-ZKT34WPW.js → cli-5ACW3WND.js} +2 -2
- package/dist/bundle/chunks/{compat-HEUVP6UJ.js → compat-TQKA4I7M.js} +1 -1
- package/dist/bundle/chunks/{dist-NU2EIVT6.js → dist-WHC67QRM.js} +676 -550
- package/dist/bundle/chunks/dist-cjs-RL2OCAP2.js +179 -0
- package/dist/bundle/chunks/{easter-egg-3d-5KKDWEIA.js → easter-egg-3d-3L3IKAT6.js} +1 -1
- package/dist/bundle/chunks/{esm-NCUV2DF7.js → esm-763X2IA7.js} +1 -1
- package/dist/bundle/chunks/event-streams-R5OECII4.js +2 -0
- package/dist/bundle/chunks/{execute-OSBDNQU5.js → execute-4X6G65NZ.js} +1 -1
- package/dist/bundle/chunks/{extract-PYRMDATF.js → extract-DLZ425VI.js} +4 -4
- package/dist/bundle/chunks/github-copilot.js +32 -31
- package/dist/bundle/chunks/{google-generative-ai-H2F5Y5H2.js → google-generative-ai-JD2FVOIX.js} +1 -1
- package/dist/bundle/chunks/{google-vertex-LFWD2AOO.js → google-vertex-PFBMDCBW.js} +1 -1
- package/dist/bundle/chunks/{host-6ZA6LK4C.js → host-4J7H7KDS.js} +1 -1
- package/dist/bundle/chunks/{node-XGNY74WT.js → node-W47VUEGE.js} +1 -1
- package/dist/bundle/chunks/{runtime-JFLZUNYP.js → runtime-SI76JZNE.js} +1 -1
- package/dist/bundle/chunks/virtual-modules-ID2GA4GE.js +5 -0
- package/dist/bundle/cli-runtime.js +3 -3
- package/dist/bundle/flow/package.json +1 -1
- package/dist/bundle/index.js +17 -17
- package/dist/bundle/rpc-entry.js +3 -2
- package/dist/core/account-reporting.d.ts +109 -0
- package/dist/core/account-reporting.d.ts.map +1 -0
- package/dist/core/account-reporting.js +328 -0
- package/dist/core/account-reporting.js.map +1 -0
- package/dist/core/agent-session.d.ts +22 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +131 -0
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/anthropic-account-reporting.d.ts +76 -0
- package/dist/core/anthropic-account-reporting.d.ts.map +1 -0
- package/dist/core/anthropic-account-reporting.js +380 -0
- package/dist/core/anthropic-account-reporting.js.map +1 -0
- package/dist/core/bedrock-account-reporting.d.ts +82 -0
- package/dist/core/bedrock-account-reporting.d.ts.map +1 -0
- package/dist/core/bedrock-account-reporting.js +402 -0
- package/dist/core/bedrock-account-reporting.js.map +1 -0
- package/dist/core/model-runtime.d.ts +17 -0
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +64 -10
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/oauth-account-pool.d.ts +4 -0
- package/dist/core/oauth-account-pool.d.ts.map +1 -1
- package/dist/core/oauth-account-pool.js +10 -3
- package/dist/core/oauth-account-pool.js.map +1 -1
- package/dist/humain/flow-accounts-host.d.ts +120 -0
- package/dist/humain/flow-accounts-host.d.ts.map +1 -0
- package/dist/humain/flow-accounts-host.js +346 -0
- package/dist/humain/flow-accounts-host.js.map +1 -0
- package/dist/humain/flow-command.d.ts +28 -0
- package/dist/humain/flow-command.d.ts.map +1 -0
- package/dist/humain/flow-command.js +226 -0
- package/dist/humain/flow-command.js.map +1 -0
- package/dist/humain/flow-loader.d.ts +4 -2
- package/dist/humain/flow-loader.d.ts.map +1 -1
- package/dist/humain/flow-loader.js +120 -91
- package/dist/humain/flow-loader.js.map +1 -1
- package/dist/humain/node-account-failure.d.ts +18 -0
- package/dist/humain/node-account-failure.d.ts.map +1 -0
- package/dist/humain/node-account-failure.js +73 -0
- package/dist/humain/node-account-failure.js.map +1 -0
- package/dist/humain/node-account-fallback.d.ts +85 -0
- package/dist/humain/node-account-fallback.d.ts.map +1 -0
- package/dist/humain/node-account-fallback.js +175 -0
- package/dist/humain/node-account-fallback.js.map +1 -0
- package/dist/humain/node-http.d.ts.map +1 -1
- package/dist/humain/node-http.js +11 -0
- package/dist/humain/node-http.js.map +1 -1
- package/dist/humain/node-provider.d.ts +4 -0
- package/dist/humain/node-provider.d.ts.map +1 -1
- package/dist/humain/node-provider.js +11 -0
- package/dist/humain/node-provider.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts +2 -0
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +5 -0
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +26 -0
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +242 -19
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/docs/flow-profiles.md +57 -5
- package/docs/flow.md +119 -37
- package/docs/providers.md +37 -0
- package/npm-shrinkwrap.json +48 -6
- package/package.json +3 -2
- package/dist/bundle/chunks/chunk-JOKJ3CEL.js +0 -27
- package/dist/bundle/chunks/event-streams-CGCQQL5M.js +0 -2
- package/dist/bundle/chunks/virtual-modules-NPWQ6NBS.js +0 -5
|
@@ -5,7 +5,9 @@ import { findEnvKeys } from "@earendil-works/pi-ai/compat";
|
|
|
5
5
|
import * as builtinProviderCatalog from "@earendil-works/pi-ai/providers/all";
|
|
6
6
|
import { assertChatModel, assertClassifierInputSupported, assertClassifierModel, assertImageModel, classifierErrorResult, imageErrorResult, } from "@earendil-works/pi-ai/utils/model-operations";
|
|
7
7
|
import { getAgentDir } from "../config.js";
|
|
8
|
+
import { FileNodeAccountMetadataStore, InMemoryNodeAccountMetadataStore, } from "../humain/node-account-fallback.js";
|
|
8
9
|
import { operationSignal, raceWithAbortSignal } from "../utils/abort.js";
|
|
10
|
+
import { ANTHROPIC_PROVIDER_ID, AnthropicRateLimitStore, isOfficialAnthropicBaseUrl, parseAnthropicRateLimits, } from "./anthropic-account-reporting.js";
|
|
9
11
|
import { AccountSourceReplacementError, AuthStorage as DefaultAuthStorage } from "./auth-storage.js";
|
|
10
12
|
import { filterBedrockCatalog } from "./model-catalog-filter.js";
|
|
11
13
|
import { ModelConfig } from "./model-config.js";
|
|
@@ -48,6 +50,17 @@ function mergeHeaders(base, override) {
|
|
|
48
50
|
}
|
|
49
51
|
return merged;
|
|
50
52
|
}
|
|
53
|
+
const CREDENTIAL_HEADERS = ["x-api-key", "authorization"];
|
|
54
|
+
function headerValue(headers, lowerName) {
|
|
55
|
+
for (const [name, value] of Object.entries(headers ?? {}))
|
|
56
|
+
if (name.toLowerCase() === lowerName)
|
|
57
|
+
return value;
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
/** True when the final request headers replace or add a credential header the resolved auth did not supply. */
|
|
61
|
+
function overridesCredentialHeaders(resolved, final) {
|
|
62
|
+
return CREDENTIAL_HEADERS.some((name) => headerValue(final, name) !== headerValue(resolved, name));
|
|
63
|
+
}
|
|
51
64
|
function swallow(fn) {
|
|
52
65
|
try {
|
|
53
66
|
const result = fn();
|
|
@@ -140,6 +153,10 @@ export class ModelRuntime {
|
|
|
140
153
|
models;
|
|
141
154
|
credentials;
|
|
142
155
|
oauthAccountPool;
|
|
156
|
+
/** Secret-free HUMAIN Node fallback policy and user labels; keys stay in the credential pool. */
|
|
157
|
+
nodeAccountMetadata;
|
|
158
|
+
/** Latest Anthropic API rate-limit headers per account, observed from this runtime's own responses. */
|
|
159
|
+
anthropicRateLimits = new AnthropicRateLimitStore();
|
|
143
160
|
defaultBuiltins;
|
|
144
161
|
builtins = new Map();
|
|
145
162
|
nativeExtensionProviders = new Map();
|
|
@@ -166,9 +183,10 @@ export class ModelRuntime {
|
|
|
166
183
|
requestScope = new AsyncLocalStorage();
|
|
167
184
|
/** Observers of sessions that own this runtime; they attribute direct calls made outside any request scope. */
|
|
168
185
|
ownerObservers = new Set();
|
|
169
|
-
constructor(credentials, oauthAccountPool, config, modelsPath, modelsStore, providers, modelNetworkEnabled) {
|
|
186
|
+
constructor(credentials, oauthAccountPool, nodeAccountMetadata, config, modelsPath, modelsStore, providers, modelNetworkEnabled) {
|
|
170
187
|
this.credentials = credentials;
|
|
171
188
|
this.oauthAccountPool = oauthAccountPool;
|
|
189
|
+
this.nodeAccountMetadata = nodeAccountMetadata;
|
|
172
190
|
this.config = config;
|
|
173
191
|
this.modelsPath = modelsPath;
|
|
174
192
|
this.modelNetworkEnabled = modelNetworkEnabled;
|
|
@@ -184,6 +202,10 @@ export class ModelRuntime {
|
|
|
184
202
|
(options.credentials
|
|
185
203
|
? OAuthAccountPool.inMemory(credentials.accountStore)
|
|
186
204
|
: OAuthAccountPool.create(credentials.accountStore, join(dirname(options.authPath ?? join(getAgentDir(), "auth.json")), "oauth-accounts.json")));
|
|
205
|
+
const nodeAccountMetadata = options.nodeAccountMetadata ??
|
|
206
|
+
(options.credentials
|
|
207
|
+
? new InMemoryNodeAccountMetadataStore()
|
|
208
|
+
: new FileNodeAccountMetadataStore(join(dirname(options.authPath ?? join(getAgentDir(), "auth.json")), "humain-node-accounts.json")));
|
|
187
209
|
const modelsPath = options.modelsPath === null ? undefined : (options.modelsPath ?? join(getAgentDir(), "models.json"));
|
|
188
210
|
const config = await ModelConfig.load(modelsPath);
|
|
189
211
|
const modelsStore = options.modelsStore ??
|
|
@@ -202,7 +224,7 @@ export class ModelRuntime {
|
|
|
202
224
|
const getModels = provider.getModels.bind(provider);
|
|
203
225
|
return { ...provider, getModels: () => filterBedrockCatalog(getModels()) };
|
|
204
226
|
});
|
|
205
|
-
const runtime = new ModelRuntime(credentials, oauthAccountPool, config, modelsPath, modelsStore, providers, process.env.PI_OFFLINE === undefined);
|
|
227
|
+
const runtime = new ModelRuntime(credentials, oauthAccountPool, nodeAccountMetadata, config, modelsPath, modelsStore, providers, process.env.PI_OFFLINE === undefined);
|
|
206
228
|
runtime.configureRadiusProviders();
|
|
207
229
|
runtime.rebuildProviders();
|
|
208
230
|
const refreshFromNetwork = runtime.modelNetworkEnabled && options.allowModelNetwork === true;
|
|
@@ -638,6 +660,13 @@ export class ModelRuntime {
|
|
|
638
660
|
await this.synchronizeCredentialState(providerId, "removeRuntimeApiKey", signal);
|
|
639
661
|
});
|
|
640
662
|
}
|
|
663
|
+
/**
|
|
664
|
+
* Raw stored credential for host-owned reporting: no command or environment resolution, so reading it runs nothing.
|
|
665
|
+
* Sensitive; callers must never display, log or persist it.
|
|
666
|
+
*/
|
|
667
|
+
readStoredCredential(providerId, options) {
|
|
668
|
+
return this.protectCredentialOperation(this.credentials.readStored(providerId, options), options?.signal, false);
|
|
669
|
+
}
|
|
641
670
|
listCredentials(options) {
|
|
642
671
|
return this.protectCredentialOperation(this.credentials.list(options), options?.signal, false);
|
|
643
672
|
}
|
|
@@ -842,11 +871,13 @@ export class ModelRuntime {
|
|
|
842
871
|
if (!provider)
|
|
843
872
|
throw new ModelsError("provider", `Unknown provider: ${model.provider}`);
|
|
844
873
|
let resolvedAccount;
|
|
874
|
+
// Anthropic rate-limit headers are only recorded for a credential whose account is identified for this request.
|
|
875
|
+
const observesAnthropicLimits = model.provider === ANTHROPIC_PROVIDER_ID;
|
|
845
876
|
const resolution = await this.getAuth(model, {
|
|
846
877
|
apiKey: options?.apiKey,
|
|
847
878
|
env: options?.env,
|
|
848
879
|
signal: options?.signal,
|
|
849
|
-
onOAuthAccount: options?.onOAuthAccount
|
|
880
|
+
onOAuthAccount: options?.onOAuthAccount || observesAnthropicLimits
|
|
850
881
|
? (provider, key) => {
|
|
851
882
|
resolvedAccount = { provider, key };
|
|
852
883
|
}
|
|
@@ -864,17 +895,29 @@ export class ModelRuntime {
|
|
|
864
895
|
: undefined;
|
|
865
896
|
const requestModel = resolution.auth.baseUrl ? { ...model, baseUrl: resolution.auth.baseUrl } : model;
|
|
866
897
|
const apiKey = providerOptions.apiKey ?? resolution.auth.apiKey;
|
|
867
|
-
|
|
898
|
+
let attributedAccountKey;
|
|
899
|
+
if ((options?.onOAuthAccount || observesAnthropicLimits) && this.oauthAccountPool.isPooled(model.provider)) {
|
|
868
900
|
// OAuth-only providers still resolve stored auth even with an explicit request key. That
|
|
869
901
|
// credential is not necessarily dispatched: preserve the key override and attribute it,
|
|
870
902
|
// failing closed if its account is unknown. A resolved/refreshed key keeps its identity.
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
903
|
+
attributedAccountKey =
|
|
904
|
+
resolvedAccount?.provider === model.provider && apiKey === resolution.auth.apiKey
|
|
905
|
+
? resolvedAccount.key
|
|
906
|
+
: apiKey
|
|
907
|
+
? this.oauthAccountPool.getAccountKeyForAccessToken(model.provider, apiKey)
|
|
908
|
+
: undefined;
|
|
909
|
+
options?.onOAuthAccount?.(model.provider, attributedAccountKey);
|
|
877
910
|
}
|
|
911
|
+
const callerOnResponse = providerOptions.onResponse;
|
|
912
|
+
const onResponse = observesAnthropicLimits &&
|
|
913
|
+
attributedAccountKey !== undefined &&
|
|
914
|
+
!overridesCredentialHeaders(resolution.auth.headers, headers) &&
|
|
915
|
+
isOfficialAnthropicBaseUrl(requestModel.baseUrl)
|
|
916
|
+
? async (response, responseModel) => {
|
|
917
|
+
this.observeAnthropicLimits(attributedAccountKey, response);
|
|
918
|
+
await callerOnResponse?.(response, responseModel);
|
|
919
|
+
}
|
|
920
|
+
: callerOnResponse;
|
|
878
921
|
// The one request boundary: every chat, image, classifier and deferred call is prepared here, so
|
|
879
922
|
// the scope bound by the owning session observes it exactly once per real submission.
|
|
880
923
|
const scope = this.currentScope();
|
|
@@ -893,11 +936,22 @@ export class ModelRuntime {
|
|
|
893
936
|
headers,
|
|
894
937
|
env,
|
|
895
938
|
...(onPayload ? { onPayload } : {}),
|
|
939
|
+
...(onResponse ? { onResponse } : {}),
|
|
896
940
|
...(tracker ? { onRequest: tracker.hook(providerOptions.onRequest) } : {}),
|
|
897
941
|
},
|
|
898
942
|
tracker,
|
|
899
943
|
};
|
|
900
944
|
}
|
|
945
|
+
observeAnthropicLimits(accountKey, response) {
|
|
946
|
+
try {
|
|
947
|
+
const snapshot = parseAnthropicRateLimits(response.headers, Date.now());
|
|
948
|
+
if (snapshot)
|
|
949
|
+
this.anthropicRateLimits.record(accountKey, snapshot);
|
|
950
|
+
}
|
|
951
|
+
catch {
|
|
952
|
+
// Observation is best effort and never affects the request.
|
|
953
|
+
}
|
|
954
|
+
}
|
|
901
955
|
/**
|
|
902
956
|
* Run `fn` so every request it starts (including background work it schedules) is reported to
|
|
903
957
|
* `observer`. The binding follows async context, so concurrent sessions sharing this runtime keep
|