@feltdb/feltkit 0.3.22 → 0.3.24
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/app.d.ts +17 -3
- package/dist/app.js +10 -0
- package/dist/app.js.map +1 -1
- package/dist/appboundry/build.js +4 -0
- package/dist/appboundry/build.js.map +1 -1
- package/dist/authorize.d.ts +1 -1
- package/dist/cli/deploy-appboundry.d.ts +26 -0
- package/dist/cli/deploy-appboundry.js +1 -1
- package/dist/cli/deploy-appboundry.js.map +1 -1
- package/dist/cli/main.js +17 -153
- package/dist/cli/main.js.map +1 -1
- package/dist/client/index.d.ts +83 -4
- package/dist/client/index.js +204 -10
- package/dist/client/index.js.map +1 -1
- package/dist/dashboard/assets/index-BEjtLLYq.js +15 -0
- package/dist/dashboard/index.html +1 -1
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +2 -0
- package/dist/docs.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js.map +1 -1
- package/dist/platform/approvals.d.ts +102 -0
- package/dist/platform/approvals.js +155 -0
- package/dist/platform/approvals.js.map +1 -0
- package/dist/platform/artifacts.d.ts +126 -0
- package/dist/platform/artifacts.js +251 -0
- package/dist/platform/artifacts.js.map +1 -0
- package/dist/platform/blobs.d.ts +25 -0
- package/dist/platform/blobs.js +78 -0
- package/dist/platform/blobs.js.map +1 -0
- package/dist/platform/diff.d.ts +23 -0
- package/dist/platform/diff.js +107 -0
- package/dist/platform/diff.js.map +1 -0
- package/dist/platform/exec.d.ts +182 -0
- package/dist/platform/exec.js +575 -0
- package/dist/platform/exec.js.map +1 -0
- package/dist/platform/managed.d.ts +43 -0
- package/dist/platform/managed.js +137 -0
- package/dist/platform/managed.js.map +1 -0
- package/dist/platform/operations.d.ts +30 -13
- package/dist/platform/operations.js +8 -17
- package/dist/platform/operations.js.map +1 -1
- package/dist/platform/permissions.d.ts +15 -0
- package/dist/platform/permissions.js +16 -0
- package/dist/platform/permissions.js.map +1 -0
- package/dist/platform/platform.d.ts +51 -0
- package/dist/platform/platform.js +105 -6
- package/dist/platform/platform.js.map +1 -1
- package/dist/platform/releases.d.ts +150 -0
- package/dist/platform/releases.js +467 -0
- package/dist/platform/releases.js.map +1 -0
- package/dist/platform/review.d.ts +10 -0
- package/dist/platform/review.js +109 -0
- package/dist/platform/review.js.map +1 -0
- package/dist/platform/server.js +7 -0
- package/dist/platform/server.js.map +1 -1
- package/dist/platform/source.d.ts +2 -0
- package/dist/platform/source.js +1 -1
- package/dist/platform/source.js.map +1 -1
- package/dist/platform/workspace-operations.d.ts +2 -0
- package/dist/platform/workspace-operations.js +605 -0
- package/dist/platform/workspace-operations.js.map +1 -0
- package/dist/platform/workspaces.d.ts +211 -0
- package/dist/platform/workspaces.js +435 -0
- package/dist/platform/workspaces.js.map +1 -0
- package/dist/react/index.d.ts +29 -1
- package/dist/react/index.js +50 -0
- package/dist/react/index.js.map +1 -1
- package/dist/runtime/activity.d.ts +1 -1
- package/dist/runtime/agent.d.ts +216 -2
- package/dist/runtime/agent.js +333 -7
- package/dist/runtime/agent.js.map +1 -1
- package/dist/runtime/approval-rules.d.ts +16 -0
- package/dist/runtime/approval-rules.js +37 -0
- package/dist/runtime/approval-rules.js.map +1 -0
- package/dist/runtime/authboundry.d.ts +53 -0
- package/dist/runtime/authboundry.js +82 -0
- package/dist/runtime/authboundry.js.map +1 -0
- package/dist/runtime/authority.d.ts +18 -1
- package/dist/runtime/authority.js +26 -1
- package/dist/runtime/authority.js.map +1 -1
- package/dist/runtime/browser-inference.d.ts +52 -0
- package/dist/runtime/browser-inference.js +53 -0
- package/dist/runtime/browser-inference.js.map +1 -0
- package/dist/runtime/context.d.ts +110 -0
- package/dist/runtime/decisions.d.ts +23 -0
- package/dist/runtime/decisions.js +54 -0
- package/dist/runtime/decisions.js.map +1 -1
- package/dist/runtime/generation.d.ts +94 -0
- package/dist/runtime/generation.js +295 -0
- package/dist/runtime/generation.js.map +1 -0
- package/dist/runtime/runtime.d.ts +10 -2
- package/dist/runtime/runtime.js +125 -1
- package/dist/runtime/runtime.js.map +1 -1
- package/dist/server/admin.d.ts +9 -1
- package/dist/server/admin.js +84 -2
- package/dist/server/admin.js.map +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +208 -11
- package/dist/server/index.js.map +1 -1
- package/dist/server/tenancy.js +1 -1
- package/dist/server/tenancy.js.map +1 -1
- package/dist/testing/index.d.ts +11 -0
- package/dist/testing/index.js +7 -3
- package/dist/testing/index.js.map +1 -1
- package/docs/AUTH.md +3 -2
- package/docs/EXTENSION-HOSTS.md +52 -0
- package/docs/GENERATION.md +136 -0
- package/docs/README.md +4 -2
- package/package.json +6 -8
- package/skills/.claude-plugin/marketplace.json +1 -1
- package/skills/.claude-plugin/plugin.json +1 -1
- package/dist/cli/compose.d.ts +0 -31
- package/dist/cli/compose.js +0 -274
- package/dist/cli/compose.js.map +0 -1
- package/dist/cli/create.d.ts +0 -219
- package/dist/cli/create.js +0 -1197
- package/dist/cli/create.js.map +0 -1
- package/dist/cli/domain.d.ts +0 -174
- package/dist/cli/domain.js +0 -1170
- package/dist/cli/domain.js.map +0 -1
- package/dist/cli/screens.d.ts +0 -25
- package/dist/cli/screens.js +0 -282
- package/dist/cli/screens.js.map +0 -1
- package/dist/cli/shell.d.ts +0 -7
- package/dist/cli/shell.js +0 -63
- package/dist/cli/shell.js.map +0 -1
- package/dist/composition/catalog.d.ts +0 -3
- package/dist/composition/catalog.js +0 -217
- package/dist/composition/catalog.js.map +0 -1
- package/dist/composition/contract.d.ts +0 -165
- package/dist/composition/contract.js +0 -12
- package/dist/composition/contract.js.map +0 -1
- package/dist/composition/execute.d.ts +0 -110
- package/dist/composition/execute.js +0 -350
- package/dist/composition/execute.js.map +0 -1
- package/dist/composition/generate.d.ts +0 -105
- package/dist/composition/generate.js +0 -274
- package/dist/composition/generate.js.map +0 -1
- package/dist/composition/plan.d.ts +0 -131
- package/dist/composition/plan.js +0 -558
- package/dist/composition/plan.js.map +0 -1
- package/dist/composition/profiles.d.ts +0 -20
- package/dist/composition/profiles.js +0 -81
- package/dist/composition/profiles.js.map +0 -1
- package/dist/composition/reconcile.d.ts +0 -153
- package/dist/composition/reconcile.js +0 -282
- package/dist/composition/reconcile.js.map +0 -1
- package/dist/composition/recover.d.ts +0 -89
- package/dist/composition/recover.js +0 -407
- package/dist/composition/recover.js.map +0 -1
- package/dist/composition/resolve.d.ts +0 -2
- package/dist/composition/resolve.js +0 -208
- package/dist/composition/resolve.js.map +0 -1
- package/dist/dashboard/assets/index-BrC1AtZ1.js +0 -15
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AuthBoundry as the authority for delegated work (docs/M2-AGENT-OPERATIONS.md G15): FeltKit asks
|
|
3
|
+
* AuthBoundry, on every call it governs, whether this principal may perform this capability now.
|
|
4
|
+
* AuthBoundry evaluates the delegation behind an agent (who delegated, to which capabilities and
|
|
5
|
+
* resources, whether it expired or was revoked, whether the agent is active); FeltKit enforces the
|
|
6
|
+
* answer. It is the contract AuthBoundry's own enforcement SDK speaks (POST
|
|
7
|
+
* /_authboundry/authorize/check, mode "enforce", with an application check credential), spoken
|
|
8
|
+
* here over HTTP so that FeltKit depends on the contract, not on a package.
|
|
9
|
+
*
|
|
10
|
+
* Fail closed: a decision that is not an exact, attributable allow (the same application,
|
|
11
|
+
* principal and capability echoed, with a decision id) is a denial, and so is an unreachable,
|
|
12
|
+
* slow or malformed authority. The check credential is configuration (FELTKIT_AUTHBOUNDRY_CHECK_CREDENTIAL),
|
|
13
|
+
* never recorded; a decision id is evidence.
|
|
14
|
+
*/
|
|
15
|
+
export function authBoundryAuthority(options) {
|
|
16
|
+
const fetchImpl = options.fetch ?? fetch;
|
|
17
|
+
const timeoutMs = options.timeoutMs ?? 3000;
|
|
18
|
+
const target = new URL("/_authboundry/authorize/check", options.url);
|
|
19
|
+
return {
|
|
20
|
+
kind: "authboundry",
|
|
21
|
+
application: options.application,
|
|
22
|
+
async decide(request) {
|
|
23
|
+
const body = {
|
|
24
|
+
application_id: options.application,
|
|
25
|
+
principal_id: request.principal.id,
|
|
26
|
+
capability: request.capability,
|
|
27
|
+
mode: "enforce",
|
|
28
|
+
enforcement_point: options.enforcementPoint ?? "feltkit",
|
|
29
|
+
...(request.resource ? { resource: request.resource } : {}),
|
|
30
|
+
...(request.context ? { context: request.context } : {}),
|
|
31
|
+
};
|
|
32
|
+
let status;
|
|
33
|
+
let decision;
|
|
34
|
+
try {
|
|
35
|
+
const response = await fetchImpl(target, {
|
|
36
|
+
method: "POST",
|
|
37
|
+
cache: "no-store",
|
|
38
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
39
|
+
headers: {
|
|
40
|
+
accept: "application/json",
|
|
41
|
+
"content-type": "application/json",
|
|
42
|
+
"x-authboundry-check-credential": options.checkCredential,
|
|
43
|
+
...(request.agentCredential ? { "x-authboundry-agent-credential": request.agentCredential } : {}),
|
|
44
|
+
},
|
|
45
|
+
body: JSON.stringify(body),
|
|
46
|
+
});
|
|
47
|
+
status = response.status;
|
|
48
|
+
decision = JSON.parse(await response.text());
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
const timedOut = error.name === "TimeoutError" || error.name === "AbortError";
|
|
52
|
+
return { allowed: false, decisionId: null, outcome: "unavailable", reason: timedOut ? `AuthBoundry did not decide within ${timeoutMs} ms` : `AuthBoundry is unreachable or answered malformed JSON: ${error.message}` };
|
|
53
|
+
}
|
|
54
|
+
const reason = decision && typeof decision === "object" && typeof decision.reason === "string" ? decision.reason : null;
|
|
55
|
+
const decisionId = decision && typeof decision.decision_id === "string" ? decision.decision_id : null;
|
|
56
|
+
if (status === 400)
|
|
57
|
+
return { allowed: false, decisionId, outcome: "invalid", reason: reason ?? "AuthBoundry rejected the request" };
|
|
58
|
+
if ([401, 403, 404, 409].includes(status))
|
|
59
|
+
return { allowed: false, decisionId, outcome: "deny", reason: reason ?? `AuthBoundry denied the request (${status})` };
|
|
60
|
+
if (status !== 200 || !decision || typeof decision !== "object")
|
|
61
|
+
return { allowed: false, decisionId, outcome: "unavailable", reason: `AuthBoundry could not decide (${status})` };
|
|
62
|
+
if (decision.decision === "deny")
|
|
63
|
+
return { allowed: false, decisionId, outcome: "deny", reason: reason ?? "denied" };
|
|
64
|
+
const exact = decision.decision === "allow" && decision.application_id === body.application_id && decision.principal_id === body.principal_id && decision.capability === body.capability && decision.mode === "enforce" && typeof decision.decision_id === "string";
|
|
65
|
+
if (!exact)
|
|
66
|
+
return { allowed: false, decisionId, outcome: "unavailable", reason: "AuthBoundry returned an unverifiable decision (not an exact allow of this application, principal and capability with a decision id)" };
|
|
67
|
+
return { allowed: true, decisionId, outcome: "allow", reason };
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** From the environment: FELTKIT_AUTHBOUNDRY_URL, _APPLICATION and _CHECK_CREDENTIAL (all three, or none). */
|
|
72
|
+
export function authBoundryFromEnvironment(env = process.env) {
|
|
73
|
+
const url = env.FELTKIT_AUTHBOUNDRY_URL;
|
|
74
|
+
const application = env.FELTKIT_AUTHBOUNDRY_APPLICATION;
|
|
75
|
+
const checkCredential = env.FELTKIT_AUTHBOUNDRY_CHECK_CREDENTIAL;
|
|
76
|
+
if (!url && !application && !checkCredential)
|
|
77
|
+
return null;
|
|
78
|
+
if (!url || !application || !checkCredential)
|
|
79
|
+
throw Object.assign(new Error("AuthBoundry needs FELTKIT_AUTHBOUNDRY_URL, FELTKIT_AUTHBOUNDRY_APPLICATION and FELTKIT_AUTHBOUNDRY_CHECK_CREDENTIAL together."), { code: "CONFIGURATION" });
|
|
80
|
+
return authBoundryAuthority({ url, application, checkCredential });
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=authboundry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authboundry.js","sourceRoot":"","sources":["../../src/runtime/authboundry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AA6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AC,+BAA+B,CAAC;IACxD,MAAM,eAAe,GAAG,GAAG,CAAC,oCAAoC,CAAC;IACjE,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,eAAe;QAAE,OAAO,IAAI,CAAC;IAC1D,IAAI,CAAC,GAAG,IAAI,CAAC,WAAW,IAAI,CAAC,eAAe;QAAE,MAAM,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,+HAA+H,CAAC,EAAE,EAAE,IAAI,EAAE,eAAe,EAAE,CAAC,CAAC;IACzO,OAAO,oBAAoB,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC,CAAC;AACrE,CAAC"}
|
|
@@ -92,9 +92,26 @@ export interface ServicePrincipalRequest {
|
|
|
92
92
|
/** Jobs, schedules, and webhook deliveries running after the request that created them. */
|
|
93
93
|
durable: boolean;
|
|
94
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Where the caller is: their IANA time zone ("Europe/Paris") and BCP 47 locale ("fr-FR"), as the
|
|
97
|
+
* FeltKit client reports them on each request (X-FeltKit-Time-Zone, X-FeltKit-Locale), validated
|
|
98
|
+
* by the server. A preference for presenting and interpreting dates, never authority. Null when
|
|
99
|
+
* the caller did not say (a job, a script, AppPort).
|
|
100
|
+
*/
|
|
101
|
+
export interface CallerContext {
|
|
102
|
+
readonly timeZone: string | null;
|
|
103
|
+
readonly locale: string | null;
|
|
104
|
+
}
|
|
105
|
+
/** A valid IANA time zone and BCP 47 locale from untrusted headers, or null for each that is not. */
|
|
106
|
+
export declare function callerContext(input: {
|
|
107
|
+
timeZone?: unknown;
|
|
108
|
+
locale?: unknown;
|
|
109
|
+
} | undefined): CallerContext;
|
|
95
110
|
export interface AuthContext {
|
|
96
111
|
/** The verified caller, or null for an anonymous call to a public function. */
|
|
97
112
|
readonly principal: Principal | null;
|
|
113
|
+
/** The caller's time zone and locale for this request (see CallerContext). */
|
|
114
|
+
readonly context: CallerContext;
|
|
98
115
|
/** The tenant this call works in (`auth.tenant`), from the session and the live membership; null when none. Typed: `app.tenant(ctx)`. */
|
|
99
116
|
readonly tenant: import("./tenancy.js").TenantContext | null;
|
|
100
117
|
readonly permissions: readonly string[];
|
|
@@ -104,5 +121,5 @@ export interface AuthContext {
|
|
|
104
121
|
/** Return the caller, or throw UNAUTHORIZED. */
|
|
105
122
|
requirePrincipal(): Principal;
|
|
106
123
|
}
|
|
107
|
-
export declare function authContext(authority: Authority, principal: Principal | null): AuthContext;
|
|
124
|
+
export declare function authContext(authority: Authority, principal: Principal | null, context?: CallerContext): AuthContext;
|
|
108
125
|
export {};
|
|
@@ -234,11 +234,36 @@ const OWNED_BY_ATTRIBUTE = {
|
|
|
234
234
|
"notifications.update": "recipient",
|
|
235
235
|
"notifications.delete": "recipient",
|
|
236
236
|
};
|
|
237
|
-
|
|
237
|
+
/** A valid IANA time zone and BCP 47 locale from untrusted headers, or null for each that is not. */
|
|
238
|
+
export function callerContext(input) {
|
|
239
|
+
const zone = typeof input?.timeZone === "string" && input.timeZone.length <= 64 ? input.timeZone : null;
|
|
240
|
+
const locale = typeof input?.locale === "string" && input.locale.length <= 64 ? input.locale : null;
|
|
241
|
+
let timeZone = null;
|
|
242
|
+
if (zone) {
|
|
243
|
+
try {
|
|
244
|
+
timeZone = new Intl.DateTimeFormat("en-US", { timeZone: zone }).resolvedOptions().timeZone;
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
timeZone = null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
let lang = null;
|
|
251
|
+
if (locale) {
|
|
252
|
+
try {
|
|
253
|
+
lang = Intl.getCanonicalLocales(locale)[0] ?? null;
|
|
254
|
+
}
|
|
255
|
+
catch {
|
|
256
|
+
lang = null;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return Object.freeze({ timeZone, locale: lang });
|
|
260
|
+
}
|
|
261
|
+
export function authContext(authority, principal, context = callerContext(undefined)) {
|
|
238
262
|
const grants = (granted, permission) => grantsPermission(granted, permission);
|
|
239
263
|
const permissions = Object.freeze(authority.permissionsFor(principal));
|
|
240
264
|
return Object.freeze({
|
|
241
265
|
principal,
|
|
266
|
+
context,
|
|
242
267
|
tenant: principal?.tenant ?? null,
|
|
243
268
|
permissions,
|
|
244
269
|
has: (permission) => grants([...permissions], permission),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authority.js","sourceRoot":"","sources":["../../src/runtime/authority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,oBAAoB,EAAmB,MAAM,cAAc,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AA4B5C,MAAM,UAAU,kBAAkB,CAAC,KAAiC;IAClE,IAAI,CAAC,KAAK,IAAI,OAAO,KAAK,CAAC,EAAE,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE;QAAE,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,0BAA0B,CAAC,CAAC;IACvI,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,MAAM,CAAC;IAClC,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,2BAA2B,IAAI,IAAI,CAAC,CAAC;IAClI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,YAAY,CAAC,kBAAkB,EAAE,kCAAkC,CAAC,CAAC;IAChH,OAAO;QACL,EAAE,EAAE,KAAK,CAAC,EAAE;QACZ,IAAI;QACJ,KAAK,EAAE,CAAC,GAAG,KAAK,CAAC,KAAK,CAA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ACxB,IAAI,CAAC,SAAS;gBAAE,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,4BAA4B,CAAC,CAAC;YACrF,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,WAAW,CAAC,EAAE,UAAU,CAAC;gBAAE,MAAM,IAAI,YAAY,CAAC,WAAW,EAAE,uBAAuB,UAAU,EAAE,CAAC,CAAC;QACtH,CAAC;QACD,gBAAgB;YACd,IAAI,CAAC,SAAS;gBAAE,MAAM,IAAI,YAAY,CAAC,cAAc,EAAE,4BAA4B,CAAC,CAAC;YACrF,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Studio's browser-inference opt-in: whether this environment's operator has authorized Studio to run a model in
|
|
3
|
+
* their own browser (`@mlc-ai/web-llm` through `@feltdb/webllm`).
|
|
4
|
+
*
|
|
5
|
+
* It exists because Studio's Content-Security-Policy is deliberately tight — `default-src 'self'; script-src
|
|
6
|
+
* 'self'; connect-src 'self'` — and a browser model cannot run under it: WebAssembly needs `'wasm-unsafe-eval'`,
|
|
7
|
+
* the engine runs in a blob worker, and the model's weights come from Hugging Face. Widening that policy for
|
|
8
|
+
* everyone, to serve a feature most environments will never use, is not a trade anyone agreed to. So the policy
|
|
9
|
+
* stays as it is until an operator turns this on, and goes straight back when they turn it off.
|
|
10
|
+
*
|
|
11
|
+
* Four properties, each of which a test asserts:
|
|
12
|
+
*
|
|
13
|
+
* - **Reversible.** The policy is computed per request from this flag, so enabling and disabling both take
|
|
14
|
+
* effect on the next page load. Disabling restores the original policy exactly, not an approximation.
|
|
15
|
+
* - **Scoped.** The record lives in this environment's own FeltDB state, so it is an environment-level operator
|
|
16
|
+
* decision: not global, not per-user, and not shared with another environment.
|
|
17
|
+
* - **Durable.** It is a committed record, so a Studio restart keeps the operator's choice.
|
|
18
|
+
* - **Fail closed.** Every read is wrapped: an unreadable, missing or malformed record is `disabled`, which is
|
|
19
|
+
* the tight policy. A write that fails leaves the in-memory flag alone, so the policy never widens because a
|
|
20
|
+
* write half-happened.
|
|
21
|
+
*
|
|
22
|
+
* This authorizes *Studio's browser* to run a model. It does not change where the agent decides: `runtime/
|
|
23
|
+
* decisions.ts` runs the agent's decisions on the server, and a model running in an operator's browser is not
|
|
24
|
+
* available to it.
|
|
25
|
+
*/
|
|
26
|
+
import type { FeltKitRuntime } from "./runtime.js";
|
|
27
|
+
/** The environment's own Studio settings. One record per setting; this module owns `browser-inference`. */
|
|
28
|
+
export declare const STUDIO_SETTINGS = "_feltkit_studio";
|
|
29
|
+
/**
|
|
30
|
+
* The hosts the weights come from, taken from `@mlc-ai/web-llm`'s own bundle rather than from documentation:
|
|
31
|
+
* the model manifest and the WebAssembly libraries are on raw.githubusercontent.com, and the weight shards are on
|
|
32
|
+
* Hugging Face, which redirects large files to its CDN.
|
|
33
|
+
*/
|
|
34
|
+
export declare const BROWSER_INFERENCE_HOSTS: readonly string[];
|
|
35
|
+
export interface BrowserInferenceState {
|
|
36
|
+
readonly enabled: boolean;
|
|
37
|
+
/** When it was last turned on or off, and by whom, so the decision has provenance like any other. */
|
|
38
|
+
readonly at?: string;
|
|
39
|
+
readonly by?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* This environment's setting, or `disabled` when it cannot be read.
|
|
43
|
+
*
|
|
44
|
+
* Never throws. A missing collection, an unreadable store, a record of the wrong shape: each one means the
|
|
45
|
+
* operator has not authorized anything, and the tight policy is what an unauthorized environment gets.
|
|
46
|
+
*/
|
|
47
|
+
export declare function readBrowserInference(runtime: FeltKitRuntime): Promise<BrowserInferenceState>;
|
|
48
|
+
/**
|
|
49
|
+
* Record the operator's decision. Throws if it cannot be committed, so the caller keeps the policy it had: a
|
|
50
|
+
* setting that did not persist must not widen the policy of a process that is about to forget it.
|
|
51
|
+
*/
|
|
52
|
+
export declare function setBrowserInference(runtime: FeltKitRuntime, enabled: boolean, by: string): Promise<BrowserInferenceState>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { readAll } from "./data.js";
|
|
2
|
+
/** The environment's own Studio settings. One record per setting; this module owns `browser-inference`. */
|
|
3
|
+
export const STUDIO_SETTINGS = "_feltkit_studio";
|
|
4
|
+
const RECORD_ID = "browser-inference";
|
|
5
|
+
/**
|
|
6
|
+
* The hosts the weights come from, taken from `@mlc-ai/web-llm`'s own bundle rather than from documentation:
|
|
7
|
+
* the model manifest and the WebAssembly libraries are on raw.githubusercontent.com, and the weight shards are on
|
|
8
|
+
* Hugging Face, which redirects large files to its CDN.
|
|
9
|
+
*/
|
|
10
|
+
export const BROWSER_INFERENCE_HOSTS = Object.freeze([
|
|
11
|
+
"https://huggingface.co",
|
|
12
|
+
"https://cdn-lfs.huggingface.co",
|
|
13
|
+
"https://cdn-lfs-us-1.hf.co",
|
|
14
|
+
"https://raw.githubusercontent.com",
|
|
15
|
+
]);
|
|
16
|
+
const DISABLED = Object.freeze({ enabled: false });
|
|
17
|
+
/**
|
|
18
|
+
* This environment's setting, or `disabled` when it cannot be read.
|
|
19
|
+
*
|
|
20
|
+
* Never throws. A missing collection, an unreadable store, a record of the wrong shape: each one means the
|
|
21
|
+
* operator has not authorized anything, and the tight policy is what an unauthorized environment gets.
|
|
22
|
+
*/
|
|
23
|
+
export async function readBrowserInference(runtime) {
|
|
24
|
+
try {
|
|
25
|
+
const rows = (await readAll(runtime.instance.handle("feltkit.models"), { collection: STUDIO_SETTINGS }));
|
|
26
|
+
const record = rows.find((r) => r.id === RECORD_ID);
|
|
27
|
+
if (!record || record.enabled !== true)
|
|
28
|
+
return DISABLED;
|
|
29
|
+
return Object.freeze({
|
|
30
|
+
enabled: true,
|
|
31
|
+
...(typeof record.at === "string" ? { at: record.at } : {}),
|
|
32
|
+
...(typeof record.by === "string" ? { by: record.by } : {}),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return DISABLED;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Record the operator's decision. Throws if it cannot be committed, so the caller keeps the policy it had: a
|
|
41
|
+
* setting that did not persist must not widen the policy of a process that is about to forget it.
|
|
42
|
+
*/
|
|
43
|
+
export async function setBrowserInference(runtime, enabled, by) {
|
|
44
|
+
const handle = runtime.instance.handle("feltkit.models");
|
|
45
|
+
const rows = (await readAll(handle, { collection: STUDIO_SETTINGS }));
|
|
46
|
+
const current = rows.find((r) => r.id === RECORD_ID);
|
|
47
|
+
const value = { id: RECORD_ID, enabled, at: new Date().toISOString(), by };
|
|
48
|
+
await handle.transaction({
|
|
49
|
+
operations: [{ collection: STUDIO_SETTINGS, id: RECORD_ID, ...(current ? { ifVersion: current.__version } : {}), value }],
|
|
50
|
+
});
|
|
51
|
+
return enabled ? Object.freeze({ enabled: true, at: value.at, by }) : DISABLED;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=browser-inference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-inference.js","sourceRoot":"","sources":["../../src/runtime/browser-inference.ts"],"names":[],"mappings":"AA0BA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,2GAA2G;AAC3G,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC;AACjD,MAAM,SAAS,GAAG,mBAAmB,CAAC;AAEtC;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,MAAM,CAAC,MAAM,CAAC;IACnD,wBAAwB;IACxB,gCAAgC;IAChC,4BAA4B;IAC5B,mCAAmC;CACpC,CAAC,CAAC;AASH,MAAM,QAAQ,GAA0B,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;AAE1E;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAAuB;IAChE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,MAAM,OAAO,CAAC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AE,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,CAAC;IAC3E,MAAM,MAAM,CAAC,WAAW,CAAC;QACvB,UAAU,EAAE,CAAC,EAAE,UAAU,EAAE,eAAe,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC;KACjH,CAAC,CAAC;IACZ,OAAO,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;AACjF,CAAC"}
|
|
@@ -143,3 +143,113 @@ export interface AgentWriter {
|
|
|
143
143
|
taskId: string;
|
|
144
144
|
};
|
|
145
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* What an action handler (`app.action`) receives. An action is not a transaction: it holds no
|
|
148
|
+
* database handle, so it changes state only through mutations (`runMutation`) or through the
|
|
149
|
+
* agent's proposals (`agent.propose`), each authorized as the caller. It may call the
|
|
150
|
+
* environment's model and stream to its caller.
|
|
151
|
+
*/
|
|
152
|
+
export interface ActionCtx {
|
|
153
|
+
readonly auth: AuthContext;
|
|
154
|
+
readonly environment: EnvironmentInfo;
|
|
155
|
+
readonly requestId: string;
|
|
156
|
+
readonly log: Logger;
|
|
157
|
+
/** Aborted when the caller cancels (closes the stream) or the action's deadline passes. */
|
|
158
|
+
readonly signal: AbortSignal;
|
|
159
|
+
/** Run a query as the caller. */
|
|
160
|
+
runQuery<F extends import("../client/index.js").FunctionReference<"query">>(fn: F, args?: import("../client/index.js").ArgsOf<F>): Promise<import("../client/index.js").ResultOf<F>>;
|
|
161
|
+
/** Run a mutation as the caller. */
|
|
162
|
+
runMutation<F extends import("../client/index.js").FunctionReference<"mutation">>(fn: F, args?: import("../client/index.js").ArgsOf<F>): Promise<import("../client/index.js").ResultOf<F>>;
|
|
163
|
+
/** Send an event to the caller's stream (`client.action(…, { onEvent })`). Dropped when the caller is not streaming. */
|
|
164
|
+
emit(event: {
|
|
165
|
+
type: string;
|
|
166
|
+
} & Record<string, unknown>): void;
|
|
167
|
+
readonly model: ActionModel;
|
|
168
|
+
readonly agent: ActionAgent;
|
|
169
|
+
}
|
|
170
|
+
export interface ActionModel {
|
|
171
|
+
/** The environment's model: where it comes from and whether it is ready. Never a secret. */
|
|
172
|
+
status(): Promise<{
|
|
173
|
+
ready: boolean;
|
|
174
|
+
provider: string | null;
|
|
175
|
+
model: string | null;
|
|
176
|
+
source: string;
|
|
177
|
+
reference: {
|
|
178
|
+
ref: string;
|
|
179
|
+
revision: number | null;
|
|
180
|
+
} | null;
|
|
181
|
+
problems: Array<{
|
|
182
|
+
problem: string;
|
|
183
|
+
message: string;
|
|
184
|
+
fix: string;
|
|
185
|
+
}>;
|
|
186
|
+
}>;
|
|
187
|
+
/**
|
|
188
|
+
* Generate with the environment's model. Text streams to the caller as `{ type: "delta", text }`
|
|
189
|
+
* events (unless `stream: false`); tool calls come back as data. Every generation is recorded as
|
|
190
|
+
* durable evidence on `taskId` (a turn from `agent.openTask`), whatever its outcome.
|
|
191
|
+
*/
|
|
192
|
+
generate(request: {
|
|
193
|
+
taskId: string;
|
|
194
|
+
messages: import("./generation.js").GenerationMessage[];
|
|
195
|
+
tools?: import("./generation.js").ToolDefinition[];
|
|
196
|
+
maxTokens?: number;
|
|
197
|
+
temperature?: number;
|
|
198
|
+
stream?: boolean;
|
|
199
|
+
}): Promise<import("./generation.js").GenerationResult & {
|
|
200
|
+
receipt: import("./generation.js").GenerationReceipt;
|
|
201
|
+
memoryId: string;
|
|
202
|
+
generationId: string;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
export interface ActionAgent {
|
|
206
|
+
/** The capabilities the caller may use, as model tools (name, description, input schema), with their effect and approval rule. */
|
|
207
|
+
tools(): Promise<Array<import("./generation.js").ToolDefinition & {
|
|
208
|
+
effect: "observation" | "consequential";
|
|
209
|
+
approval?: "required";
|
|
210
|
+
}>>;
|
|
211
|
+
/** Open (or reopen) the task for one conversation turn, keyed by something stable such as the message id. */
|
|
212
|
+
openTask(input: {
|
|
213
|
+
key: string;
|
|
214
|
+
objective: string;
|
|
215
|
+
}): Promise<{
|
|
216
|
+
taskId: string;
|
|
217
|
+
created: boolean;
|
|
218
|
+
}>;
|
|
219
|
+
/**
|
|
220
|
+
* Propose a capability call on a turn's task, for the caller. An observation runs now (through
|
|
221
|
+
* AppPort, as the caller) and returns its output; a consequential call waits for the caller's
|
|
222
|
+
* approval. `model` attributes the proposal to the model whose tool call it is. The same
|
|
223
|
+
* `idempotencyKey` on the same task returns the first proposal instead of making another.
|
|
224
|
+
*/
|
|
225
|
+
/** Every action of a turn (oldest first): what a retried turn returns instead of asking the model again. */
|
|
226
|
+
actions(taskId: string): Promise<ActionProposal[]>;
|
|
227
|
+
propose(taskId: string, proposal: {
|
|
228
|
+
capability: string;
|
|
229
|
+
input: Record<string, unknown>;
|
|
230
|
+
reason: string;
|
|
231
|
+
idempotencyKey: string;
|
|
232
|
+
model?: {
|
|
233
|
+
provider: string;
|
|
234
|
+
model: string;
|
|
235
|
+
generation?: {
|
|
236
|
+
generationId?: string;
|
|
237
|
+
memoryId: string;
|
|
238
|
+
toolCallId: string;
|
|
239
|
+
};
|
|
240
|
+
};
|
|
241
|
+
}): Promise<ActionProposal>;
|
|
242
|
+
}
|
|
243
|
+
export interface ActionProposal {
|
|
244
|
+
taskId: string;
|
|
245
|
+
actionId: string;
|
|
246
|
+
capability: string;
|
|
247
|
+
effect: "observation" | "consequential";
|
|
248
|
+
/** "proposed": waits for approval. "succeeded" / "failed": an observation that ran. */
|
|
249
|
+
state: string;
|
|
250
|
+
output?: unknown;
|
|
251
|
+
error?: {
|
|
252
|
+
code: string;
|
|
253
|
+
message: string;
|
|
254
|
+
};
|
|
255
|
+
}
|
|
@@ -27,6 +27,7 @@ import type { DecisionBatch, DecisionBatchEvaluation, DecisionRequest, DecisionR
|
|
|
27
27
|
import { FeltKitError } from "../errors.js";
|
|
28
28
|
import { type Principal } from "./authority.js";
|
|
29
29
|
import type { FeltKitRuntime } from "./runtime.js";
|
|
30
|
+
import { type GenerationReceipt, type GenerationRequest, type GenerationResult } from "./generation.js";
|
|
30
31
|
/**
|
|
31
32
|
* Models saved for this environment. Intelligence holds the one the agent decides with; this
|
|
32
33
|
* collection remembers the others, so switching is one step. A saved model holds a
|
|
@@ -209,4 +210,26 @@ export declare class ModelHost {
|
|
|
209
210
|
* request's labels. Errors carry the problem and the fix; nothing is retried.
|
|
210
211
|
*/
|
|
211
212
|
decide(request: DecisionRequest): Promise<DecisionOutcome>;
|
|
213
|
+
/**
|
|
214
|
+
* Generate open-ended text with the environment's model, streamed through `request.onDelta`,
|
|
215
|
+
* with tool calls returned as data (never executed here). Resolution, custody and receipts are
|
|
216
|
+
* the decision path's: a Resolver reference is resolved once per generation (a change landing
|
|
217
|
+
* mid-call cannot mix two revisions), an Intelligence credential is used inside custody's
|
|
218
|
+
* callback and never leaves it. The receipt names what ran; it never holds a secret or the prompt.
|
|
219
|
+
*/
|
|
220
|
+
generate(request: GenerationRequest & {
|
|
221
|
+
/** Called once the model is resolved, before the provider is contacted (the generation is then "running"). */
|
|
222
|
+
onStart?: (model: {
|
|
223
|
+
provider: string;
|
|
224
|
+
model: string;
|
|
225
|
+
protocol: string;
|
|
226
|
+
endpoint: string;
|
|
227
|
+
source: "resolver" | "intelligence";
|
|
228
|
+
credential: string | null;
|
|
229
|
+
resolution?: ModelResolution;
|
|
230
|
+
}) => Promise<void> | void;
|
|
231
|
+
}): Promise<{
|
|
232
|
+
result: GenerationResult;
|
|
233
|
+
receipt: GenerationReceipt;
|
|
234
|
+
}>;
|
|
212
235
|
}
|
|
@@ -5,6 +5,7 @@ import { systemPrincipal } from "./authority.js";
|
|
|
5
5
|
import { redactSecret } from "./credentials.js";
|
|
6
6
|
import { createHash } from "node:crypto";
|
|
7
7
|
import { readAll } from "./data.js";
|
|
8
|
+
import { DEFAULT_GENERATION_TIMEOUT_MS, generationDigest, streamGeneration, supportsGeneration } from "./generation.js";
|
|
8
9
|
/**
|
|
9
10
|
* Models saved for this environment. Intelligence holds the one the agent decides with; this
|
|
10
11
|
* collection remembers the others, so switching is one step. A saved model holds a
|
|
@@ -490,6 +491,59 @@ export class ModelHost {
|
|
|
490
491
|
const runtime = connect();
|
|
491
492
|
return { result, metadata: runtime.metadata(), capabilities: runtime.capabilities(), provider: status.provider, source: "intelligence", durationMs: Date.now() - started };
|
|
492
493
|
}
|
|
494
|
+
/**
|
|
495
|
+
* Generate open-ended text with the environment's model, streamed through `request.onDelta`,
|
|
496
|
+
* with tool calls returned as data (never executed here). Resolution, custody and receipts are
|
|
497
|
+
* the decision path's: a Resolver reference is resolved once per generation (a change landing
|
|
498
|
+
* mid-call cannot mix two revisions), an Intelligence credential is used inside custody's
|
|
499
|
+
* callback and never leaves it. The receipt names what ran; it never holds a secret or the prompt.
|
|
500
|
+
*/
|
|
501
|
+
async generate(request) {
|
|
502
|
+
const started = Date.now();
|
|
503
|
+
const inputDigest = generationDigest(request);
|
|
504
|
+
const timeoutMs = this.#runtime.app.options.agent?.generationTimeoutMs ?? DEFAULT_GENERATION_TIMEOUT_MS;
|
|
505
|
+
const receipt = (result, base) => ({
|
|
506
|
+
result,
|
|
507
|
+
receipt: { ...base, finish: result.finish, usage: result.usage, toolCalls: result.toolCalls.map((c) => ({ id: c.id, name: c.name })), startedAt: new Date(started).toISOString(), durationMs: Date.now() - started, inputDigest },
|
|
508
|
+
});
|
|
509
|
+
const ref = this.reference();
|
|
510
|
+
if (ref) {
|
|
511
|
+
let resolved;
|
|
512
|
+
try {
|
|
513
|
+
resolved = await this.#client(ref).model(ref);
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
throw isFeltKitError(error) ? error : resolverProblem(ref, error);
|
|
517
|
+
}
|
|
518
|
+
const { provider, endpoint } = this.#connectionFor(ref, resolved);
|
|
519
|
+
if (!supportsGeneration(provider.protocol))
|
|
520
|
+
throw modelError("unknown_protocol", `FeltKit cannot generate with the "${provider.protocol}" protocol (${resolved.provider}).`, "Rebind the reference to an OpenAI, OpenAI-compatible or Anthropic provider.", { ref });
|
|
521
|
+
if (provider.credential === "required" && !resolved.apiKey) {
|
|
522
|
+
throw modelError("credential_missing", `${ref} resolves to ${resolved.provider}, which needs an API key, and none was revealed.`, `Add model.credential to ${ref}'s binding, and grant this deployment's Resolver key reveal on it.`, { ref });
|
|
523
|
+
}
|
|
524
|
+
const resolution = { ref, revision: resolved.revision, label: resolved.label ?? null, provider: resolved.provider, model: resolved.model, endpoint, credential: resolved.credential ?? null, credentialRevision: resolved.credentialRevision ?? null, resolvedAt: new Date(started).toISOString() };
|
|
525
|
+
await request.onStart?.({ provider: resolved.provider, model: resolved.model, protocol: provider.protocol, endpoint, source: "resolver", credential: resolved.credential ?? null, resolution });
|
|
526
|
+
const result = await streamGeneration(provider.protocol, { provider: resolved.provider, model: resolved.model, endpoint, ...(resolved.apiKey ? { credential: resolved.apiKey } : {}), timeoutMs, ...(this.#fetch ? { fetch: this.#fetch } : {}) }, request);
|
|
527
|
+
return receipt(result, { provider: resolved.provider, model: resolved.model, protocol: provider.protocol, endpoint, source: "resolver", resolution, credential: resolved.credential ?? null });
|
|
528
|
+
}
|
|
529
|
+
const status = await this.status();
|
|
530
|
+
if (status.source === "application") {
|
|
531
|
+
throw modelError("unsupported", "This application supplies its own decision runtime (agent.decisions), which makes decisions only; generation needs a provider.", "Configure Intelligence (Studio → Models, `feltkit model set`) or a Resolver reference (agent.model) for generation.");
|
|
532
|
+
}
|
|
533
|
+
if (!status.ready || !status.provider || !status.protocol) {
|
|
534
|
+
const first = status.problems[0];
|
|
535
|
+
throw modelError(first.problem, first.message, first.fix);
|
|
536
|
+
}
|
|
537
|
+
if (!supportsGeneration(status.protocol))
|
|
538
|
+
throw modelError("unknown_protocol", `FeltKit cannot generate with the "${status.protocol}" protocol.`, "Choose an OpenAI, OpenAI-compatible or Anthropic provider.");
|
|
539
|
+
const connection = (credential) => ({ provider: status.provider, model: status.model, endpoint: status.endpoint, ...(credential ? { credential } : {}), timeoutMs, ...(this.#fetch ? { fetch: this.#fetch } : {}) });
|
|
540
|
+
const ref2 = status.credential.ref;
|
|
541
|
+
await request.onStart?.({ provider: status.provider, model: status.model, protocol: status.protocol, endpoint: status.endpoint, source: "intelligence", credential: ref2 });
|
|
542
|
+
const result = ref2
|
|
543
|
+
? await this.#runtime.services.credentials.withSecret({ reference: { secretId: ref2.slice("credential-ref:".length), tenantId: this.#runtime.services.scope.tenantId }, context: { purpose: "model generation" } }, (secret) => streamGeneration(status.protocol, connection(secret.value), request))
|
|
544
|
+
: await streamGeneration(status.protocol, connection(), request);
|
|
545
|
+
return receipt(result, { provider: status.provider, model: status.model, protocol: status.protocol, endpoint: status.endpoint, source: "intelligence", credential: ref2 });
|
|
546
|
+
}
|
|
493
547
|
/** The provider's protocol and endpoint for a resolved target, from the Intelligence catalog. */
|
|
494
548
|
#connectionFor(ref, target) {
|
|
495
549
|
const provider = getIntelligenceProvider(target.provider);
|