@intutic/shared-types 2.2.0 → 2.4.0
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/dist/anomaly.d.ts +6 -10
- package/dist/anomaly.d.ts.map +1 -1
- package/dist/anomaly.js +0 -2
- package/dist/anomaly.js.map +1 -1
- package/dist/api-contracts.d.ts +1 -1
- package/dist/api-contracts.js +1 -1
- package/dist/attenuation.d.ts +1 -1
- package/dist/attenuation.js +1 -1
- package/dist/auth.d.ts +116 -9
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +20 -5
- package/dist/auth.js.map +1 -1
- package/dist/billing.d.ts +1 -1
- package/dist/billing.js +1 -1
- package/dist/cloudProbe.d.ts +54 -0
- package/dist/cloudProbe.d.ts.map +1 -0
- package/dist/cloudProbe.js +254 -0
- package/dist/cloudProbe.js.map +1 -0
- package/dist/destructiveSql.d.ts +48 -0
- package/dist/destructiveSql.d.ts.map +1 -0
- package/dist/destructiveSql.js +43 -0
- package/dist/destructiveSql.js.map +1 -0
- package/dist/devInventory.d.ts +120 -0
- package/dist/devInventory.d.ts.map +1 -0
- package/dist/devInventory.js +80 -0
- package/dist/devInventory.js.map +1 -0
- package/dist/enums.d.ts +66 -21
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +55 -31
- package/dist/enums.js.map +1 -1
- package/dist/errors.js +3 -3
- package/dist/errors.js.map +1 -1
- package/dist/finops.d.ts +52 -2
- package/dist/finops.d.ts.map +1 -1
- package/dist/finops.js +15 -1
- package/dist/finops.js.map +1 -1
- package/dist/gateDecisions.d.ts +18 -0
- package/dist/gateDecisions.d.ts.map +1 -0
- package/dist/gateDecisions.js +20 -0
- package/dist/gateDecisions.js.map +1 -0
- package/dist/gateIdentity.d.ts +23 -0
- package/dist/gateIdentity.d.ts.map +1 -0
- package/dist/gateIdentity.js +32 -0
- package/dist/gateIdentity.js.map +1 -0
- package/dist/gateKind.d.ts +172 -0
- package/dist/gateKind.d.ts.map +1 -0
- package/dist/gateKind.js +160 -0
- package/dist/gateKind.js.map +1 -0
- package/dist/gateLimits.d.ts +170 -0
- package/dist/gateLimits.d.ts.map +1 -0
- package/dist/gateLimits.js +96 -0
- package/dist/gateLimits.js.map +1 -0
- package/dist/gitRemote.d.ts +17 -0
- package/dist/gitRemote.d.ts.map +1 -0
- package/dist/gitRemote.js +71 -0
- package/dist/gitRemote.js.map +1 -0
- package/dist/governanceCoverage.d.ts +1 -1
- package/dist/governanceCoverage.js +1 -1
- package/dist/guardrailIr.d.ts +9 -9
- package/dist/guardrailIr.d.ts.map +1 -1
- package/dist/guardrailIr.js +3 -3
- package/dist/guardrailIr.js.map +1 -1
- package/dist/guardrailRender.d.ts +1 -1
- package/dist/guardrailRender.js +1 -1
- package/dist/harnessRules.d.ts +74 -0
- package/dist/harnessRules.d.ts.map +1 -0
- package/dist/harnessRules.js +142 -0
- package/dist/harnessRules.js.map +1 -0
- package/dist/holdMessages.d.ts +25 -0
- package/dist/holdMessages.d.ts.map +1 -0
- package/dist/holdMessages.js +34 -0
- package/dist/holdMessages.js.map +1 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.js +2 -2
- package/dist/identity.js.map +1 -1
- package/dist/index.d.ts +42 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +161 -10
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +1 -1
- package/dist/mcpBudgets.d.ts +191 -0
- package/dist/mcpBudgets.d.ts.map +1 -0
- package/dist/mcpBudgets.js +144 -0
- package/dist/mcpBudgets.js.map +1 -0
- package/dist/mcpRegistryRecord.d.ts +143 -0
- package/dist/mcpRegistryRecord.d.ts.map +1 -0
- package/dist/mcpRegistryRecord.js +229 -0
- package/dist/mcpRegistryRecord.js.map +1 -0
- package/dist/mcpToolRisk.d.ts +82 -0
- package/dist/mcpToolRisk.d.ts.map +1 -0
- package/dist/mcpToolRisk.js +334 -0
- package/dist/mcpToolRisk.js.map +1 -0
- package/dist/modelCatalog.d.ts +2 -2
- package/dist/modelCatalog.generated.js +1 -1
- package/dist/modelCatalog.generated.js.map +1 -1
- package/dist/modelCatalog.js +2 -2
- package/dist/notifications.d.ts +24 -151
- package/dist/notifications.d.ts.map +1 -1
- package/dist/notifications.js +266 -1
- package/dist/notifications.js.map +1 -1
- package/dist/phrases.d.ts +87 -0
- package/dist/phrases.d.ts.map +1 -0
- package/dist/phrases.js +241 -0
- package/dist/phrases.js.map +1 -0
- package/dist/piiDetectors.d.ts +97 -0
- package/dist/piiDetectors.d.ts.map +1 -0
- package/dist/piiDetectors.js +96 -0
- package/dist/piiDetectors.js.map +1 -0
- package/dist/piiDetectors.json +71 -0
- package/dist/policy.d.ts +1 -1
- package/dist/policy.js +1 -1
- package/dist/policyGuardrails.d.ts +127 -10
- package/dist/policyGuardrails.d.ts.map +1 -1
- package/dist/policyGuardrails.js +59 -6
- package/dist/policyGuardrails.js.map +1 -1
- package/dist/posturePresets.js +1 -1
- package/dist/posturePresets.js.map +1 -1
- package/dist/providerVerification.d.ts +36 -10
- package/dist/providerVerification.d.ts.map +1 -1
- package/dist/providerVerification.js +80 -20
- package/dist/providerVerification.js.map +1 -1
- package/dist/providers.d.ts +54 -17
- package/dist/providers.d.ts.map +1 -1
- package/dist/providers.js +135 -26
- package/dist/providers.js.map +1 -1
- package/dist/regoBuiltins.d.ts +42 -0
- package/dist/regoBuiltins.d.ts.map +1 -0
- package/dist/regoBuiltins.js +732 -0
- package/dist/regoBuiltins.js.map +1 -0
- package/dist/regoRules.d.ts +105 -0
- package/dist/regoRules.d.ts.map +1 -0
- package/dist/regoRules.js +407 -0
- package/dist/regoRules.js.map +1 -0
- package/dist/ruleLoadFailures.d.ts +15 -0
- package/dist/ruleLoadFailures.d.ts.map +1 -0
- package/dist/ruleLoadFailures.js +26 -0
- package/dist/ruleLoadFailures.js.map +1 -0
- package/dist/scriptScan.d.ts +5 -5
- package/dist/scriptScan.js +3 -3
- package/dist/sequence.d.ts +52 -0
- package/dist/sequence.d.ts.map +1 -0
- package/dist/sequence.js +127 -0
- package/dist/sequence.js.map +1 -0
- package/dist/session.d.ts +1 -1
- package/dist/session.js +1 -1
- package/dist/skillScan.d.ts +3 -3
- package/dist/skillScan.d.ts.map +1 -1
- package/dist/skillScan.js +26 -4
- package/dist/skillScan.js.map +1 -1
- package/dist/sop.d.ts +5 -5
- package/dist/sop.js +2 -2
- package/dist/sourceProviders.d.ts +1 -8
- package/dist/sourceProviders.d.ts.map +1 -1
- package/dist/sourceProviders.js +2 -9
- package/dist/sourceProviders.js.map +1 -1
- package/dist/spendBudgets.d.ts +122 -0
- package/dist/spendBudgets.d.ts.map +1 -0
- package/dist/spendBudgets.js +92 -0
- package/dist/spendBudgets.js.map +1 -0
- package/dist/ssoGroupClearance.d.ts +18 -2
- package/dist/ssoGroupClearance.d.ts.map +1 -1
- package/dist/ssoGroupClearance.js +43 -4
- package/dist/ssoGroupClearance.js.map +1 -1
- package/dist/sync.d.ts +0 -1
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +0 -1
- package/dist/sync.js.map +1 -1
- package/dist/taskManagement.d.ts +0 -2
- package/dist/taskManagement.d.ts.map +1 -1
- package/dist/taskManagement.js +0 -2
- package/dist/taskManagement.js.map +1 -1
- package/dist/toolPoison.d.ts +33 -0
- package/dist/toolPoison.d.ts.map +1 -0
- package/dist/toolPoison.js +85 -0
- package/dist/toolPoison.js.map +1 -0
- package/dist/upstreamRetry.d.ts +121 -0
- package/dist/upstreamRetry.d.ts.map +1 -0
- package/dist/upstreamRetry.js +90 -0
- package/dist/upstreamRetry.js.map +1 -0
- package/dist/usage.d.ts +186 -0
- package/dist/usage.d.ts.map +1 -1
- package/dist/wasmBinary.d.ts +25 -0
- package/dist/wasmBinary.d.ts.map +1 -0
- package/dist/wasmBinary.js +111 -0
- package/dist/wasmBinary.js.map +1 -0
- package/dist/wasmFuel.d.ts +52 -0
- package/dist/wasmFuel.d.ts.map +1 -0
- package/dist/wasmFuel.js +320 -0
- package/dist/wasmFuel.js.map +1 -0
- package/dist/wasmMemoryCap.d.ts +21 -0
- package/dist/wasmMemoryCap.d.ts.map +1 -0
- package/dist/wasmMemoryCap.js +58 -0
- package/dist/wasmMemoryCap.js.map +1 -0
- package/dist/wasmRuleDescriptor.d.ts +43 -0
- package/dist/wasmRuleDescriptor.d.ts.map +1 -0
- package/dist/wasmRuleDescriptor.js +65 -0
- package/dist/wasmRuleDescriptor.js.map +1 -0
- package/dist/workspaceSettings.d.ts +95 -17
- package/dist/workspaceSettings.d.ts.map +1 -1
- package/dist/workspaceSettings.js +2 -1
- package/dist/workspaceSettings.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The workspace setting `upstreamRetry`: how the LLM proxy retries a provider
|
|
3
|
+
* call that failed before any response reached the client, and where it falls
|
|
4
|
+
* back when those retries run out.
|
|
5
|
+
*
|
|
6
|
+
* Every field is optional and overrides the proxy's own `config.yaml` value
|
|
7
|
+
* (`intutic_settings.routing.retry` / `.fallbacks`) field by field, so a
|
|
8
|
+
* workspace can change one knob without restating the rest. The proxy reads
|
|
9
|
+
* it from `/api/v1/auth/key-context` (`packages/proxy/src/routing/retry.rs`,
|
|
10
|
+
* `WorkspaceRetry`); `fixtures/upstream-retry-vectors.json` holds the two
|
|
11
|
+
* readings together.
|
|
12
|
+
*/
|
|
13
|
+
import { z } from 'zod';
|
|
14
|
+
/**
|
|
15
|
+
* The ceilings both the schema and the proxy enforce, so no setting can
|
|
16
|
+
* configure a retry storm. The proxy clamps `config.yaml` to the same values
|
|
17
|
+
* (`RetryConfig::bounded`); a test holds the two equal.
|
|
18
|
+
*/
|
|
19
|
+
export declare const UPSTREAM_RETRY_LIMITS: {
|
|
20
|
+
readonly maxAttempts: 5;
|
|
21
|
+
readonly maxBackoffMs: 60000;
|
|
22
|
+
readonly budgetMs: 120000;
|
|
23
|
+
readonly fallbackTargets: 5;
|
|
24
|
+
readonly fallbackModels: 50;
|
|
25
|
+
};
|
|
26
|
+
/** Retried by default: 429, 500, 502, 503, 504 and Anthropic's 529 overloaded. */
|
|
27
|
+
export declare const DEFAULT_UPSTREAM_RETRY_STATUSES: readonly [429, 500, 502, 503, 504, 529];
|
|
28
|
+
/** The defaults the proxy applies when neither config.yaml nor the workspace sets a field. */
|
|
29
|
+
export declare const DEFAULT_UPSTREAM_RETRY: {
|
|
30
|
+
readonly enabled: true;
|
|
31
|
+
readonly maxAttempts: 3;
|
|
32
|
+
readonly initialBackoffMs: 500;
|
|
33
|
+
readonly maxBackoffMs: 8000;
|
|
34
|
+
readonly budgetMs: 30000;
|
|
35
|
+
readonly onStatus: readonly [429, 500, 502, 503, 504, 529];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Providers a fallback target may name: every id the proxy resolves
|
|
39
|
+
* (`provider_from_wire_id` in packages/proxy/src/proxy.rs), the cloud
|
|
40
|
+
* providers' aliases included, so a target copied from config.yaml is valid
|
|
41
|
+
* here too. A test holds the two lists equal.
|
|
42
|
+
*/
|
|
43
|
+
export declare const UPSTREAM_PROVIDERS: readonly ["anthropic", "openai", "gemini", "mistral", "openrouter", "deepseek", "bedrock", "vertex_ai", "vertex", "azure_openai", "azure"];
|
|
44
|
+
export type UpstreamProvider = (typeof UPSTREAM_PROVIDERS)[number];
|
|
45
|
+
/**
|
|
46
|
+
* One fallback target. `model` alone switches model on the provider that
|
|
47
|
+
* model resolves to; `provider` alone sends the same model to another
|
|
48
|
+
* provider; both pin the pair.
|
|
49
|
+
*/
|
|
50
|
+
export declare const UpstreamFallbackTargetSchema: z.ZodEffects<z.ZodObject<{
|
|
51
|
+
model: z.ZodOptional<z.ZodString>;
|
|
52
|
+
provider: z.ZodOptional<z.ZodEnum<["anthropic", "openai", "gemini", "mistral", "openrouter", "deepseek", "bedrock", "vertex_ai", "vertex", "azure_openai", "azure"]>>;
|
|
53
|
+
}, "strict", z.ZodTypeAny, {
|
|
54
|
+
model?: string | undefined;
|
|
55
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
56
|
+
}, {
|
|
57
|
+
model?: string | undefined;
|
|
58
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
59
|
+
}>, {
|
|
60
|
+
model?: string | undefined;
|
|
61
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
62
|
+
}, {
|
|
63
|
+
model?: string | undefined;
|
|
64
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
export type UpstreamFallbackTarget = z.infer<typeof UpstreamFallbackTargetSchema>;
|
|
67
|
+
export declare const UpstreamRetrySettingsSchema: z.ZodObject<{
|
|
68
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
69
|
+
maxAttempts: z.ZodOptional<z.ZodNumber>;
|
|
70
|
+
initialBackoffMs: z.ZodOptional<z.ZodNumber>;
|
|
71
|
+
maxBackoffMs: z.ZodOptional<z.ZodNumber>;
|
|
72
|
+
budgetMs: z.ZodOptional<z.ZodNumber>;
|
|
73
|
+
onStatus: z.ZodOptional<z.ZodArray<z.ZodNumber, "many">>;
|
|
74
|
+
/** Ordered targets, keyed by the model whose retries ran out. */
|
|
75
|
+
fallbacks: z.ZodOptional<z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodEffects<z.ZodObject<{
|
|
76
|
+
model: z.ZodOptional<z.ZodString>;
|
|
77
|
+
provider: z.ZodOptional<z.ZodEnum<["anthropic", "openai", "gemini", "mistral", "openrouter", "deepseek", "bedrock", "vertex_ai", "vertex", "azure_openai", "azure"]>>;
|
|
78
|
+
}, "strict", z.ZodTypeAny, {
|
|
79
|
+
model?: string | undefined;
|
|
80
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
81
|
+
}, {
|
|
82
|
+
model?: string | undefined;
|
|
83
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
84
|
+
}>, {
|
|
85
|
+
model?: string | undefined;
|
|
86
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
87
|
+
}, {
|
|
88
|
+
model?: string | undefined;
|
|
89
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
90
|
+
}>, "many">>, Record<string, {
|
|
91
|
+
model?: string | undefined;
|
|
92
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
93
|
+
}[]>, Record<string, {
|
|
94
|
+
model?: string | undefined;
|
|
95
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
96
|
+
}[]>>>;
|
|
97
|
+
}, "strict", z.ZodTypeAny, {
|
|
98
|
+
enabled?: boolean | undefined;
|
|
99
|
+
maxAttempts?: number | undefined;
|
|
100
|
+
initialBackoffMs?: number | undefined;
|
|
101
|
+
maxBackoffMs?: number | undefined;
|
|
102
|
+
budgetMs?: number | undefined;
|
|
103
|
+
onStatus?: number[] | undefined;
|
|
104
|
+
fallbacks?: Record<string, {
|
|
105
|
+
model?: string | undefined;
|
|
106
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
107
|
+
}[]> | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
enabled?: boolean | undefined;
|
|
110
|
+
maxAttempts?: number | undefined;
|
|
111
|
+
initialBackoffMs?: number | undefined;
|
|
112
|
+
maxBackoffMs?: number | undefined;
|
|
113
|
+
budgetMs?: number | undefined;
|
|
114
|
+
onStatus?: number[] | undefined;
|
|
115
|
+
fallbacks?: Record<string, {
|
|
116
|
+
model?: string | undefined;
|
|
117
|
+
provider?: "anthropic" | "openai" | "mistral" | "openrouter" | "deepseek" | "gemini" | "azure_openai" | "bedrock" | "vertex_ai" | "vertex" | "azure" | undefined;
|
|
118
|
+
}[]> | undefined;
|
|
119
|
+
}>;
|
|
120
|
+
export type UpstreamRetrySettings = z.infer<typeof UpstreamRetrySettingsSchema>;
|
|
121
|
+
//# sourceMappingURL=upstreamRetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstreamRetry.d.ts","sourceRoot":"","sources":["../src/upstreamRetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB;;;;GAIG;AACH,eAAO,MAAM,qBAAqB;;;;;;CAMxB,CAAA;AAEV,kFAAkF;AAClF,eAAO,MAAM,+BAA+B,yCAA0C,CAAA;AAEtF,8FAA8F;AAC9F,eAAO,MAAM,sBAAsB;;;;;;;CAOzB,CAAA;AAEV;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,4IAYrB,CAAA;AACV,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AAElE;;;;GAIG;AACH,eAAO,MAAM,4BAA4B;;;;;;;;;;;;;;;EAQrC,CAAA;AACJ,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,4BAA4B,CAAC,CAAA;AAEjF,eAAO,MAAM,2BAA2B;;;;;;;IAQpC,iEAAiE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW1D,CAAA;AACX,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,2BAA2B,CAAC,CAAA"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UpstreamRetrySettingsSchema = exports.UpstreamFallbackTargetSchema = exports.UPSTREAM_PROVIDERS = exports.DEFAULT_UPSTREAM_RETRY = exports.DEFAULT_UPSTREAM_RETRY_STATUSES = exports.UPSTREAM_RETRY_LIMITS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The workspace setting `upstreamRetry`: how the LLM proxy retries a provider
|
|
6
|
+
* call that failed before any response reached the client, and where it falls
|
|
7
|
+
* back when those retries run out.
|
|
8
|
+
*
|
|
9
|
+
* Every field is optional and overrides the proxy's own `config.yaml` value
|
|
10
|
+
* (`intutic_settings.routing.retry` / `.fallbacks`) field by field, so a
|
|
11
|
+
* workspace can change one knob without restating the rest. The proxy reads
|
|
12
|
+
* it from `/api/v1/auth/key-context` (`packages/proxy/src/routing/retry.rs`,
|
|
13
|
+
* `WorkspaceRetry`); `fixtures/upstream-retry-vectors.json` holds the two
|
|
14
|
+
* readings together.
|
|
15
|
+
*/
|
|
16
|
+
const zod_1 = require("zod");
|
|
17
|
+
/**
|
|
18
|
+
* The ceilings both the schema and the proxy enforce, so no setting can
|
|
19
|
+
* configure a retry storm. The proxy clamps `config.yaml` to the same values
|
|
20
|
+
* (`RetryConfig::bounded`); a test holds the two equal.
|
|
21
|
+
*/
|
|
22
|
+
exports.UPSTREAM_RETRY_LIMITS = {
|
|
23
|
+
maxAttempts: 5,
|
|
24
|
+
maxBackoffMs: 60_000,
|
|
25
|
+
budgetMs: 120_000,
|
|
26
|
+
fallbackTargets: 5,
|
|
27
|
+
fallbackModels: 50,
|
|
28
|
+
};
|
|
29
|
+
/** Retried by default: 429, 500, 502, 503, 504 and Anthropic's 529 overloaded. */
|
|
30
|
+
exports.DEFAULT_UPSTREAM_RETRY_STATUSES = [429, 500, 502, 503, 504, 529];
|
|
31
|
+
/** The defaults the proxy applies when neither config.yaml nor the workspace sets a field. */
|
|
32
|
+
exports.DEFAULT_UPSTREAM_RETRY = {
|
|
33
|
+
enabled: true,
|
|
34
|
+
maxAttempts: 3,
|
|
35
|
+
initialBackoffMs: 500,
|
|
36
|
+
maxBackoffMs: 8_000,
|
|
37
|
+
budgetMs: 30_000,
|
|
38
|
+
onStatus: [...exports.DEFAULT_UPSTREAM_RETRY_STATUSES],
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Providers a fallback target may name: every id the proxy resolves
|
|
42
|
+
* (`provider_from_wire_id` in packages/proxy/src/proxy.rs), the cloud
|
|
43
|
+
* providers' aliases included, so a target copied from config.yaml is valid
|
|
44
|
+
* here too. A test holds the two lists equal.
|
|
45
|
+
*/
|
|
46
|
+
exports.UPSTREAM_PROVIDERS = [
|
|
47
|
+
'anthropic',
|
|
48
|
+
'openai',
|
|
49
|
+
'gemini',
|
|
50
|
+
'mistral',
|
|
51
|
+
'openrouter',
|
|
52
|
+
'deepseek',
|
|
53
|
+
'bedrock',
|
|
54
|
+
'vertex_ai',
|
|
55
|
+
'vertex',
|
|
56
|
+
'azure_openai',
|
|
57
|
+
'azure',
|
|
58
|
+
];
|
|
59
|
+
/**
|
|
60
|
+
* One fallback target. `model` alone switches model on the provider that
|
|
61
|
+
* model resolves to; `provider` alone sends the same model to another
|
|
62
|
+
* provider; both pin the pair.
|
|
63
|
+
*/
|
|
64
|
+
exports.UpstreamFallbackTargetSchema = zod_1.z
|
|
65
|
+
.object({
|
|
66
|
+
model: zod_1.z.string().trim().min(1).max(200).optional(),
|
|
67
|
+
provider: zod_1.z.enum(exports.UPSTREAM_PROVIDERS).optional(),
|
|
68
|
+
})
|
|
69
|
+
.strict()
|
|
70
|
+
.refine((t) => t.model !== undefined || t.provider !== undefined, {
|
|
71
|
+
message: 'A fallback target names a model, a provider, or both',
|
|
72
|
+
});
|
|
73
|
+
exports.UpstreamRetrySettingsSchema = zod_1.z
|
|
74
|
+
.object({
|
|
75
|
+
enabled: zod_1.z.boolean().optional(),
|
|
76
|
+
maxAttempts: zod_1.z.number().int().min(1).max(exports.UPSTREAM_RETRY_LIMITS.maxAttempts).optional(),
|
|
77
|
+
initialBackoffMs: zod_1.z.number().int().min(0).max(exports.UPSTREAM_RETRY_LIMITS.maxBackoffMs).optional(),
|
|
78
|
+
maxBackoffMs: zod_1.z.number().int().min(0).max(exports.UPSTREAM_RETRY_LIMITS.maxBackoffMs).optional(),
|
|
79
|
+
budgetMs: zod_1.z.number().int().min(0).max(exports.UPSTREAM_RETRY_LIMITS.budgetMs).optional(),
|
|
80
|
+
onStatus: zod_1.z.array(zod_1.z.number().int().min(400).max(599)).max(20).optional(),
|
|
81
|
+
/** Ordered targets, keyed by the model whose retries ran out. */
|
|
82
|
+
fallbacks: zod_1.z
|
|
83
|
+
.record(zod_1.z.string().trim().min(1).max(200), zod_1.z.array(exports.UpstreamFallbackTargetSchema).min(1).max(exports.UPSTREAM_RETRY_LIMITS.fallbackTargets))
|
|
84
|
+
.refine((f) => Object.keys(f).length <= exports.UPSTREAM_RETRY_LIMITS.fallbackModels, {
|
|
85
|
+
message: `At most ${exports.UPSTREAM_RETRY_LIMITS.fallbackModels} models may have fallbacks`,
|
|
86
|
+
})
|
|
87
|
+
.optional(),
|
|
88
|
+
})
|
|
89
|
+
.strict();
|
|
90
|
+
//# sourceMappingURL=upstreamRetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstreamRetry.js","sourceRoot":"","sources":["../src/upstreamRetry.ts"],"names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AAC,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,6BAAqB,CAAC,cAAc,EAAE;QAC5E,OAAO,EAAE,WAAW,6BAAqB,CAAC,cAAc,4BAA4B;KACrF,CAAC;SACD,QAAQ,EAAE;CACd,CAAC;KACD,MAAM,EAAE,CAAA"}
|
package/dist/usage.d.ts
CHANGED
|
@@ -54,4 +54,190 @@ export interface VirtualKeyBreakdown {
|
|
|
54
54
|
totalOutputTokens: number;
|
|
55
55
|
traceCount: number;
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* One developer's usage for a period (`GET /api/v1/usage/members`).
|
|
59
|
+
*
|
|
60
|
+
* A call is attributed to the workspace member who owns the virtual key that
|
|
61
|
+
* authenticated it. `memberId: null` is the unattributed bucket: calls with no
|
|
62
|
+
* virtual-key auth context, and calls whose key prefix no single member owns.
|
|
63
|
+
*/
|
|
64
|
+
export interface MemberUsage {
|
|
65
|
+
memberId: string | null;
|
|
66
|
+
/** Null for the unattributed bucket, and for a member since removed. */
|
|
67
|
+
displayName: string | null;
|
|
68
|
+
email: string | null;
|
|
69
|
+
totalCostUsd: number;
|
|
70
|
+
totalRawCostUsd: number;
|
|
71
|
+
totalInputTokens: number;
|
|
72
|
+
totalOutputTokens: number;
|
|
73
|
+
traceCount: number;
|
|
74
|
+
/** Distinct requested models, sorted. */
|
|
75
|
+
models: string[];
|
|
76
|
+
/** Distinct UTC calendar days with at least one call. */
|
|
77
|
+
activeDays: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* `GET /api/v1/usage/members`. `scope: 'self'` when the caller may only see
|
|
81
|
+
* their own row (DEVELOPER and VIEWER); `'workspace'` for OWNER, ADMIN and EM.
|
|
82
|
+
*/
|
|
83
|
+
export interface MemberUsageResponse {
|
|
84
|
+
scope: 'workspace' | 'self';
|
|
85
|
+
members: MemberUsage[];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One SCIM group's usage for a period (`GET /api/v1/usage/teams`): the sum over
|
|
89
|
+
* every member in the group, directly or through nested groups. A member in
|
|
90
|
+
* several groups counts in each, so team totals can add up to more than the
|
|
91
|
+
* workspace total.
|
|
92
|
+
*/
|
|
93
|
+
export interface TeamUsage {
|
|
94
|
+
groupId: string;
|
|
95
|
+
displayName: string;
|
|
96
|
+
/** Members in the group, transitively. */
|
|
97
|
+
memberCount: number;
|
|
98
|
+
/** Members of the group with at least one attributed call in the period. */
|
|
99
|
+
activeMembers: number;
|
|
100
|
+
totalCostUsd: number;
|
|
101
|
+
totalRawCostUsd: number;
|
|
102
|
+
totalInputTokens: number;
|
|
103
|
+
totalOutputTokens: number;
|
|
104
|
+
traceCount: number;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* `GET /api/v1/usage/teams`. `scimGroups: false` means the workspace has no
|
|
108
|
+
* SCIM groups, so there are no teams to roll up to; per-member usage is the
|
|
109
|
+
* finest grouping available.
|
|
110
|
+
*/
|
|
111
|
+
export interface TeamUsageResponse {
|
|
112
|
+
scimGroups: boolean;
|
|
113
|
+
teams: TeamUsage[];
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Usage per repository and branch (`GET /api/v1/usage/branches`), from the git
|
|
117
|
+
* context copied onto each trace when it was recorded. `repo` and `branch` are
|
|
118
|
+
* both null on the row for calls made with no git context.
|
|
119
|
+
*/
|
|
120
|
+
export interface BranchUsage {
|
|
121
|
+
/** Normalised `origin` remote, host/path. Null when the directory had no `origin`. */
|
|
122
|
+
repo: string | null;
|
|
123
|
+
branch: string | null;
|
|
124
|
+
/** Distinct HEAD commits the calls were made at. */
|
|
125
|
+
commitCount: number;
|
|
126
|
+
totalCostUsd: number;
|
|
127
|
+
totalRawCostUsd: number;
|
|
128
|
+
totalInputTokens: number;
|
|
129
|
+
totalOutputTokens: number;
|
|
130
|
+
traceCount: number;
|
|
131
|
+
/** Latest call, ISO 8601. */
|
|
132
|
+
lastCallAt: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Usage per HEAD commit (`GET /api/v1/usage/commits`): the calls made while
|
|
136
|
+
* that commit was checked out, which is the work that led to the next commit,
|
|
137
|
+
* not the work that produced this one.
|
|
138
|
+
*/
|
|
139
|
+
export interface CommitUsage {
|
|
140
|
+
repo: string | null;
|
|
141
|
+
branch: string | null;
|
|
142
|
+
commit: string | null;
|
|
143
|
+
totalCostUsd: number;
|
|
144
|
+
totalRawCostUsd: number;
|
|
145
|
+
totalInputTokens: number;
|
|
146
|
+
totalOutputTokens: number;
|
|
147
|
+
traceCount: number;
|
|
148
|
+
/** First and latest call at this commit, ISO 8601. */
|
|
149
|
+
firstCallAt: string;
|
|
150
|
+
lastCallAt: string;
|
|
151
|
+
}
|
|
152
|
+
/** `scope` as on {@link MemberUsageResponse}: `'self'` counts only the caller's own calls. */
|
|
153
|
+
export interface BranchUsageResponse {
|
|
154
|
+
scope: 'workspace' | 'self';
|
|
155
|
+
branches: BranchUsage[];
|
|
156
|
+
}
|
|
157
|
+
export interface CommitUsageResponse {
|
|
158
|
+
scope: 'workspace' | 'self';
|
|
159
|
+
commits: CommitUsage[];
|
|
160
|
+
}
|
|
161
|
+
export type PullRequestState = 'open' | 'closed' | 'merged';
|
|
162
|
+
/**
|
|
163
|
+
* One pull request's usage for a period (`GET /api/v1/usage/pull-requests`):
|
|
164
|
+
* the calls made on its head branch, in its repository, between the end of
|
|
165
|
+
* the previous pull request from that branch (or the branch's first call) and
|
|
166
|
+
* this one's merge or close. A call belongs to one pull request at most.
|
|
167
|
+
*/
|
|
168
|
+
export interface PullRequestUsage {
|
|
169
|
+
/** Normalised host/owner/name, lower-cased. */
|
|
170
|
+
repo: string;
|
|
171
|
+
number: number;
|
|
172
|
+
title: string;
|
|
173
|
+
/** GitHub login of whoever opened it. */
|
|
174
|
+
author: string | null;
|
|
175
|
+
state: PullRequestState;
|
|
176
|
+
headBranch: string;
|
|
177
|
+
baseBranch: string | null;
|
|
178
|
+
/** The pull request on GitHub. */
|
|
179
|
+
url: string;
|
|
180
|
+
/** ISO 8601. */
|
|
181
|
+
openedAt: string;
|
|
182
|
+
mergedAt: string | null;
|
|
183
|
+
closedAt: string | null;
|
|
184
|
+
totalCostUsd: number;
|
|
185
|
+
totalRawCostUsd: number;
|
|
186
|
+
totalInputTokens: number;
|
|
187
|
+
totalOutputTokens: number;
|
|
188
|
+
traceCount: number;
|
|
189
|
+
/** Members with an attributed call on it in the period. */
|
|
190
|
+
memberCount: number;
|
|
191
|
+
/** First and latest call in the period, ISO 8601. */
|
|
192
|
+
firstCallAt: string;
|
|
193
|
+
lastCallAt: string;
|
|
194
|
+
}
|
|
195
|
+
/** Where pull requests come from, and whether that is working, for the empty states. */
|
|
196
|
+
export interface PullRequestSources {
|
|
197
|
+
/** The workspace has a GitHub source connector whose token lists pull requests. */
|
|
198
|
+
connector: boolean;
|
|
199
|
+
/** The pull-request webhook is set up. */
|
|
200
|
+
webhook: boolean;
|
|
201
|
+
/** The GitHub host the connector's token is used against, e.g. `github.com`. */
|
|
202
|
+
apiHost: string;
|
|
203
|
+
/** Repositories whose pull requests the connector's token was refused (missing scope or access). */
|
|
204
|
+
noAccessRepos: string[];
|
|
205
|
+
/** Pull requests mapped in the workspace, any period. */
|
|
206
|
+
mappedPullRequests: number;
|
|
207
|
+
/** Last time a branch was looked up through the connector, ISO 8601. */
|
|
208
|
+
lastCheckedAt: string | null;
|
|
209
|
+
}
|
|
210
|
+
/** `scope` as on {@link MemberUsageResponse}: `'self'` counts only the caller's own calls. */
|
|
211
|
+
export interface PullRequestUsageResponse {
|
|
212
|
+
scope: 'workspace' | 'self';
|
|
213
|
+
github: PullRequestSources;
|
|
214
|
+
pullRequests: PullRequestUsage[];
|
|
215
|
+
}
|
|
216
|
+
/** `POST /api/v1/usage/pull-requests/refresh`. */
|
|
217
|
+
export interface PullRequestRefreshResult {
|
|
218
|
+
/** Branches looked up. */
|
|
219
|
+
checked: number;
|
|
220
|
+
/** Answered 304: the ETag matched and nothing changed. */
|
|
221
|
+
notModified: number;
|
|
222
|
+
/** Pull requests written or updated. */
|
|
223
|
+
pullRequests: number;
|
|
224
|
+
/** Branches the token could not list. */
|
|
225
|
+
noAccess: number;
|
|
226
|
+
/** True when GitHub's rate limit stopped the run early. */
|
|
227
|
+
rateLimited: boolean;
|
|
228
|
+
}
|
|
229
|
+
/** `GET /api/v1/integrations/github/webhook`. The secret is never returned here. */
|
|
230
|
+
export interface GitHubWebhookInfo {
|
|
231
|
+
configured: boolean;
|
|
232
|
+
/** Payload URL to paste into GitHub. Null until a secret has been made. */
|
|
233
|
+
url: string | null;
|
|
234
|
+
createdAt: string | null;
|
|
235
|
+
secretRotatedAt: string | null;
|
|
236
|
+
lastDeliveryAt: string | null;
|
|
237
|
+
}
|
|
238
|
+
/** `POST /api/v1/integrations/github/webhook/secret`: the new secret, shown once. */
|
|
239
|
+
export interface GitHubWebhookSecret {
|
|
240
|
+
url: string;
|
|
241
|
+
secret: string;
|
|
242
|
+
}
|
|
57
243
|
//# sourceMappingURL=usage.d.ts.map
|
package/dist/usage.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../src/usage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAA;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,YAAY,EAAE,MAAM,CAAA;IACpB,eAAe,EAAE,MAAM,CAAA;IACvB,eAAe,EAAE,MAAM,CAAA;IACvB,gBAAgB,EAAE,MAAM,CAAA;IACxB,iBAAiB,EAAE,MAAM,CAAA;IACzB,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,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,OAAO,CAAA;IAClB,0CAA0C;IAC1C,OAAO,EAAE,OAAO,CAAA;IAChB,gFAAgF;IAChF,OAAO,EAAE,MAAM,CAAA;IACf,oGAAoG;IACpG,aAAa,EAAE,MAAM,EAAE,CAAA;IACvB,yDAAyD;IACzD,kBAAkB,EAAE,MAAM,CAAA;IAC1B,wEAAwE;IACxE,aAAa,EAAE,MAAM,GAAG,IAAI,CAAA;CAC7B;AAED,8FAA8F;AAC9F,MAAM,WAAW,wBAAwB;IACvC,KAAK,EAAE,WAAW,GAAG,MAAM,CAAA;IAC3B,MAAM,EAAE,kBAAkB,CAAA;IAC1B,YAAY,EAAE,gBAAgB,EAAE,CAAA;CACjC;AAED,kDAAkD;AAClD,MAAM,WAAW,wBAAwB;IACvC,0BAA0B;IAC1B,OAAO,EAAE,MAAM,CAAA;IACf,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAA;IACnB,wCAAwC;IACxC,YAAY,EAAE,MAAM,CAAA;IACpB,yCAAyC;IACzC,QAAQ,EAAE,MAAM,CAAA;IAChB,2DAA2D;IAC3D,WAAW,EAAE,OAAO,CAAA;CACrB;AAED,oFAAoF;AACpF,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,OAAO,CAAA;IACnB,2EAA2E;IAC3E,GAAG,EAAE,MAAM,GAAG,IAAI,CAAA;IAClB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;CAC9B;AAED,qFAAqF;AACrF,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,MAAM,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The few pieces of the WebAssembly binary format the load-time rewrites
|
|
3
|
+
* (`wasmMemoryCap.ts`, `wasmFuel.ts`) share: LEB128 integers, the section list, and
|
|
4
|
+
* reassembly. Not a general decoder; each rewrite parses only what it changes.
|
|
5
|
+
*/
|
|
6
|
+
export interface Section {
|
|
7
|
+
id: number;
|
|
8
|
+
payload: Uint8Array<ArrayBuffer>;
|
|
9
|
+
}
|
|
10
|
+
export declare function malformed(what: string): Error;
|
|
11
|
+
export declare function readU32(bytes: Uint8Array, at: number): {
|
|
12
|
+
value: number;
|
|
13
|
+
next: number;
|
|
14
|
+
};
|
|
15
|
+
/** Skip any LEB128 integer, signed or unsigned, up to 64 bits. */
|
|
16
|
+
export declare function skipLeb(bytes: Uint8Array, at: number): number;
|
|
17
|
+
export declare function writeU32(value: number): number[];
|
|
18
|
+
/** Signed LEB128, for `i32.const` immediates. */
|
|
19
|
+
export declare function writeS32(value: number): number[];
|
|
20
|
+
export declare function readSections(bytes: Uint8Array<ArrayBuffer>): Section[];
|
|
21
|
+
/** Replace the section with `id`, or insert it where the spec's order puts it. */
|
|
22
|
+
export declare function putSection(sections: Section[], id: number, payload: Uint8Array<ArrayBuffer>): void;
|
|
23
|
+
export declare function assembleModule(header: Uint8Array, sections: Section[]): Uint8Array<ArrayBuffer>;
|
|
24
|
+
export declare function concat(parts: Uint8Array[]): Uint8Array<ArrayBuffer>;
|
|
25
|
+
//# sourceMappingURL=wasmBinary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasmBinary.d.ts","sourceRoot":"","sources":["../src/wasmBinary.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;CACjC;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAE7C;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAUtF;AAED,kEAAkE;AAClE,wBAAgB,OAAO,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,CAK7D;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAShD;AAED,iDAAiD;AACjD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAShD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,OAAO,EAAE,CAYtE;AAKD,kFAAkF;AAClF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,CAAC,WAAW,CAAC,GAAG,IAAI,CAYlG;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAM/F;AAED,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,CAQnE"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The few pieces of the WebAssembly binary format the load-time rewrites
|
|
4
|
+
* (`wasmMemoryCap.ts`, `wasmFuel.ts`) share: LEB128 integers, the section list, and
|
|
5
|
+
* reassembly. Not a general decoder; each rewrite parses only what it changes.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.malformed = malformed;
|
|
9
|
+
exports.readU32 = readU32;
|
|
10
|
+
exports.skipLeb = skipLeb;
|
|
11
|
+
exports.writeU32 = writeU32;
|
|
12
|
+
exports.writeS32 = writeS32;
|
|
13
|
+
exports.readSections = readSections;
|
|
14
|
+
exports.putSection = putSection;
|
|
15
|
+
exports.assembleModule = assembleModule;
|
|
16
|
+
exports.concat = concat;
|
|
17
|
+
const HEADER_BYTES = 8; // `\0asm` + version
|
|
18
|
+
function malformed(what) {
|
|
19
|
+
return new Error(`malformed WASM module: ${what}`);
|
|
20
|
+
}
|
|
21
|
+
function readU32(bytes, at) {
|
|
22
|
+
let value = 0;
|
|
23
|
+
let shift = 0;
|
|
24
|
+
for (let i = at; i < bytes.length && i < at + 5; i++) {
|
|
25
|
+
const byte = bytes[i];
|
|
26
|
+
value += (byte & 0x7f) * 2 ** shift;
|
|
27
|
+
if ((byte & 0x80) === 0)
|
|
28
|
+
return { value, next: i + 1 };
|
|
29
|
+
shift += 7;
|
|
30
|
+
}
|
|
31
|
+
throw malformed('truncated or oversized LEB128 integer');
|
|
32
|
+
}
|
|
33
|
+
/** Skip any LEB128 integer, signed or unsigned, up to 64 bits. */
|
|
34
|
+
function skipLeb(bytes, at) {
|
|
35
|
+
for (let i = at; i < bytes.length && i < at + 10; i++) {
|
|
36
|
+
if ((bytes[i] & 0x80) === 0)
|
|
37
|
+
return i + 1;
|
|
38
|
+
}
|
|
39
|
+
throw malformed('truncated or oversized LEB128 integer');
|
|
40
|
+
}
|
|
41
|
+
function writeU32(value) {
|
|
42
|
+
const out = [];
|
|
43
|
+
do {
|
|
44
|
+
let byte = value & 0x7f;
|
|
45
|
+
value = Math.floor(value / 128);
|
|
46
|
+
if (value !== 0)
|
|
47
|
+
byte |= 0x80;
|
|
48
|
+
out.push(byte);
|
|
49
|
+
} while (value !== 0);
|
|
50
|
+
return out;
|
|
51
|
+
}
|
|
52
|
+
/** Signed LEB128, for `i32.const` immediates. */
|
|
53
|
+
function writeS32(value) {
|
|
54
|
+
const out = [];
|
|
55
|
+
for (;;) {
|
|
56
|
+
const byte = value & 0x7f;
|
|
57
|
+
value >>= 7;
|
|
58
|
+
const done = (value === 0 && (byte & 0x40) === 0) || (value === -1 && (byte & 0x40) !== 0);
|
|
59
|
+
out.push(done ? byte : byte | 0x80);
|
|
60
|
+
if (done)
|
|
61
|
+
return out;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function readSections(bytes) {
|
|
65
|
+
const sections = [];
|
|
66
|
+
let at = HEADER_BYTES;
|
|
67
|
+
while (at < bytes.length) {
|
|
68
|
+
const id = bytes[at];
|
|
69
|
+
const size = readU32(bytes, at + 1);
|
|
70
|
+
const end = size.next + size.value;
|
|
71
|
+
if (end > bytes.length)
|
|
72
|
+
throw malformed('section runs past the end');
|
|
73
|
+
sections.push({ id, payload: bytes.subarray(size.next, end) });
|
|
74
|
+
at = end;
|
|
75
|
+
}
|
|
76
|
+
return sections;
|
|
77
|
+
}
|
|
78
|
+
/** Section order the spec requires; custom sections (id 0) may sit anywhere. */
|
|
79
|
+
const SECTION_RANK = { 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 13: 6, 6: 7, 7: 8, 8: 9, 9: 10, 12: 11, 10: 12, 11: 13 };
|
|
80
|
+
/** Replace the section with `id`, or insert it where the spec's order puts it. */
|
|
81
|
+
function putSection(sections, id, payload) {
|
|
82
|
+
const existing = sections.findIndex((s) => s.id === id);
|
|
83
|
+
if (existing >= 0) {
|
|
84
|
+
sections[existing] = { id, payload };
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const rank = SECTION_RANK[id];
|
|
88
|
+
let insertAt = 0;
|
|
89
|
+
sections.forEach((s, i) => {
|
|
90
|
+
if (s.id !== 0 && SECTION_RANK[s.id] < rank)
|
|
91
|
+
insertAt = i + 1;
|
|
92
|
+
});
|
|
93
|
+
sections.splice(insertAt, 0, { id, payload });
|
|
94
|
+
}
|
|
95
|
+
function assembleModule(header, sections) {
|
|
96
|
+
const parts = [header.subarray(0, HEADER_BYTES)];
|
|
97
|
+
for (const s of sections) {
|
|
98
|
+
parts.push(Uint8Array.from([s.id, ...writeU32(s.payload.length)]), s.payload);
|
|
99
|
+
}
|
|
100
|
+
return concat(parts);
|
|
101
|
+
}
|
|
102
|
+
function concat(parts) {
|
|
103
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
104
|
+
let at = 0;
|
|
105
|
+
for (const p of parts) {
|
|
106
|
+
out.set(p, at);
|
|
107
|
+
at += p.length;
|
|
108
|
+
}
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=wasmBinary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasmBinary.js","sourceRoot":"","sources":["../src/wasmBinary.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AASH,8BAEC;AAED,0BAUC;AAGD,0BAKC;AAED,4BASC;AAGD,4BASC;AAED,oCAYC;AAMD,gCAYC;AAED,wCAMC;AAED,wBAQC;AAtGD,MAAM,YAAY,GAAG,CAAC,CAAA,CAAC,oBAAoB;AAO3C,SAAgB,SAAS,CAAC,IAAY;IACpC,OAAO,IAAI,KAAK,CAAC,0BAA0B,IAAI,EAAE,CAAC,CAAA;AACpD,CAAC;AAED,SAAgB,OAAO,CAAC,KAAiB,EAAE,EAAU;IACnD,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QACrD,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAE,CAAA;QACtB,KAAK,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,KAAK,CAAA;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,GAAG,CAAC,EAAE,CAAA;QACtD,KAAK,IAAI,CAAC,CAAA;IACZ,CAAC;IACD,MAAM,SAAS,CAAC,uCAAuC,CAAC,CAAA;AAC1D,CAAC;AAED,kEAAkE;AAClE,SAAgB,OAAO,CAAC,KAAiB,EAAE,EAAU;IACnD,KAAK,IAAI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AI,EAAE,GAAG,CAAC,CAAA;IACV,KAAK,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC;QACtB,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;QACd,EAAE,IAAI,CAAC,CAAC,MAAM,CAAA;IAChB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Instruction budget for WASM rules: the stand-in for Wasmtime fuel, which
|
|
3
|
+
* the Rust proxy sets to 1,000,000 per evaluation (`limits.rs`), wherever a
|
|
4
|
+
* rule runs on V8 — the MCP proxy, and `intutic rules test`, `policy test`
|
|
5
|
+
* and `policy install`, so a rule that runs out in a proxy runs out there.
|
|
6
|
+
*
|
|
7
|
+
* V8 has no metering hook, so the rule's own code is rewritten at load to
|
|
8
|
+
* count. A new mutable i32 global starts at the budget, and a charge is
|
|
9
|
+
* inserted at every function entry and every loop header: subtract the number
|
|
10
|
+
* of instructions that can run before the next charge point, and trap
|
|
11
|
+
* (`unreachable`) once the counter goes negative. Code between two charge
|
|
12
|
+
* points is straight-line apart from forward branches, so each charge is an
|
|
13
|
+
* upper bound on what it pays for, and the budget bounds the instructions the
|
|
14
|
+
* rule actually executes. Structural instructions (`block`, `loop`, `end`,
|
|
15
|
+
* `else`, `nop`, `drop`, `return`, `unreachable`) cost nothing, roughly as
|
|
16
|
+
* Wasmtime prices them.
|
|
17
|
+
*
|
|
18
|
+
* The global is exported as `FUEL_EXPORT` so the worker can tell a trap caused
|
|
19
|
+
* by the budget from any other trap. Each evaluation instantiates the module
|
|
20
|
+
* afresh, so the budget is per evaluation, like a Wasmtime `Store`.
|
|
21
|
+
*
|
|
22
|
+
* The decoder knows the MVP instruction set plus the extensions compilers
|
|
23
|
+
* emit by default (sign extension, saturating truncation, bulk memory,
|
|
24
|
+
* reference types, multi-value, tail calls, SIMD). A module using anything
|
|
25
|
+
* else (exceptions, GC, threads) is refused at load rather than run unmetered.
|
|
26
|
+
*/
|
|
27
|
+
/** `runner.rs`: `store.set_fuel(1_000_000)`. */
|
|
28
|
+
export declare const DEFAULT_FUEL_BUDGET = 1000000;
|
|
29
|
+
/**
|
|
30
|
+
* A Rego rule's budget: three times the Rust proxy's 100,000,000
|
|
31
|
+
* (`limits::REGO`), because this meter counts differently.
|
|
32
|
+
*
|
|
33
|
+
* It charges each straight-line run in full at its entry, branches skipped or
|
|
34
|
+
* not, and an OPA build is mostly short runs with early exits: on the largest
|
|
35
|
+
* input (a 64 KB command) the destructive-shell and production-deploy examples
|
|
36
|
+
* count 74,000,000 here against 21,000,000 under Wasmtime, and the
|
|
37
|
+
* deny-writes and conformance policies about 8,000,000. The budget is four
|
|
38
|
+
* times the largest, so a heavier policy on the largest input still fits, and
|
|
39
|
+
* a rule that does not fit is stopped deterministically, whatever the load.
|
|
40
|
+
* Using it all up takes at most 350 ms idle and 4.4 s on a loaded machine;
|
|
41
|
+
* the deadline (`REGO_EVALUATE_TIMEOUT_MS`) is set above that.
|
|
42
|
+
*/
|
|
43
|
+
export declare const REGO_FUEL_BUDGET = 300000000;
|
|
44
|
+
/** The export the worker reads to tell budget exhaustion from other traps. */
|
|
45
|
+
export declare const FUEL_EXPORT = "__intutic_fuel";
|
|
46
|
+
/**
|
|
47
|
+
* The module with every function metered against `budget` instructions per
|
|
48
|
+
* instantiation, and the counter exported as `FUEL_EXPORT`. Throws for a
|
|
49
|
+
* module the decoder cannot meter.
|
|
50
|
+
*/
|
|
51
|
+
export declare function meterFuel(bytes: Uint8Array<ArrayBuffer>, budget: number): Uint8Array<ArrayBuffer>;
|
|
52
|
+
//# sourceMappingURL=wasmFuel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wasmFuel.d.ts","sourceRoot":"","sources":["../src/wasmFuel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAeH,gDAAgD;AAChD,eAAO,MAAM,mBAAmB,UAAY,CAAA;AAE5C;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,YAAc,CAAA;AAE3C,8EAA8E;AAC9E,eAAO,MAAM,WAAW,mBAAmB,CAAA;AAoM3C;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CA+BjG"}
|