@hasna-internal/kai-cordis-client-runner 0.1.1-rc.2
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/LICENSE +21 -0
- package/README.i18n.yaml +6 -0
- package/README.md +68 -0
- package/README.zh.md +68 -0
- package/lib/client.js +4219 -0
- package/lib/index.js +11 -0
- package/lib/invariant.js +26 -0
- package/lib/types/client/api-catalog.d.ts +96 -0
- package/lib/types/client/evaluator.d.ts +67 -0
- package/lib/types/client/guard.d.ts +52 -0
- package/lib/types/client/index.d.ts +113 -0
- package/lib/types/client/inspect-registry.d.ts +67 -0
- package/lib/types/client/orchestrator.d.ts +131 -0
- package/lib/types/client/providers.d.ts +13 -0
- package/lib/types/client/runtime.d.ts +228 -0
- package/lib/types/client/slot-catalog.d.ts +67 -0
- package/lib/types/client/timer.d.ts +84 -0
- package/lib/types/index.d.ts +9 -0
- package/lib/types/invariant.d.ts +16 -0
- package/package.json +76 -0
package/lib/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region lib/types/index.js
|
|
2
|
+
/**
|
|
3
|
+
* Dynamic-package runner plugin, node half. Pure browser-side capability: the
|
|
4
|
+
* empty apply exists so the row appears in the host cordis.yml / Loader, while
|
|
5
|
+
* the browser half ships through exports["./client"], discovered from the
|
|
6
|
+
* package.json dshClient declaration.
|
|
7
|
+
*/
|
|
8
|
+
/** Host plugin body — this package contributes nothing host-side. */
|
|
9
|
+
function apply() {}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { apply };
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `@hasna-internal/kai-cordis-client-runner`.
|
|
4
|
+
* @module @hasna-internal/kai-cordis-client-runner/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "@hasna-internal/kai-cordis-client-runner";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "cordis-client-runner-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: the owned relation (a live
|
|
13
|
+
* Plugin's loader entry exists exactly while one Plugin Run ID is live) is
|
|
14
|
+
* browser-only state reachable through the client half's service, which the
|
|
15
|
+
* node-plane companion cannot observe. The relation is asserted by the
|
|
16
|
+
* package's own load/teardown coverage instead.
|
|
17
|
+
*/
|
|
18
|
+
const install = () => {};
|
|
19
|
+
/**
|
|
20
|
+
* Register this package's invariant companion.
|
|
21
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
22
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
23
|
+
*/
|
|
24
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
25
|
+
//#endregion
|
|
26
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated by scripts/gen-cordis-api.ts — do not edit by hand; run
|
|
3
|
+
* `pnpm run gen-cordis-api` to regenerate (freshness-gated by
|
|
4
|
+
* `pnpm run verify-cordis-api` in doc-sync).
|
|
5
|
+
*
|
|
6
|
+
* The machine-readable cordis API catalog `cordis_inspect` serves to the
|
|
7
|
+
* model: harness services (summary + structured public method contracts),
|
|
8
|
+
* harness events (mode + structured listener contracts), and the inherited `ctx` API. Produced by
|
|
9
|
+
* the same AST walk as docs/cordis-catalog, so this data and the rendered
|
|
10
|
+
* docs cannot diverge.
|
|
11
|
+
*
|
|
12
|
+
* @module @hasna-internal/kai-cordis-client-runner/client/api-catalog
|
|
13
|
+
*/
|
|
14
|
+
/** One named parameter in a Service method or Event listener. */
|
|
15
|
+
export interface ApiParameter {
|
|
16
|
+
/** Parameter name from the exact signature. */
|
|
17
|
+
name: string;
|
|
18
|
+
/** Source-owned parameter contract. */
|
|
19
|
+
description: string;
|
|
20
|
+
}
|
|
21
|
+
/** One public service member and its source-owned contract. */
|
|
22
|
+
export interface ServiceApiMethod {
|
|
23
|
+
/** Public method signature with its body stripped. */
|
|
24
|
+
signature: string;
|
|
25
|
+
/** Method purpose and behavior. */
|
|
26
|
+
description: string;
|
|
27
|
+
/** Named parameters in signature order. */
|
|
28
|
+
parameters: readonly ApiParameter[];
|
|
29
|
+
/** Non-void result contract when documented. */
|
|
30
|
+
returns?: string;
|
|
31
|
+
/** Documented failure conditions. */
|
|
32
|
+
throws?: readonly string[];
|
|
33
|
+
}
|
|
34
|
+
/** One harness `ctx.<key>` service and its public methods. */
|
|
35
|
+
export interface ServiceApiEntry {
|
|
36
|
+
/** The `ctx.<key>` name, e.g. `tools`. */
|
|
37
|
+
key: string;
|
|
38
|
+
/** First sentence of the service class JSDoc. */
|
|
39
|
+
summary: string;
|
|
40
|
+
/** Complete service description. */
|
|
41
|
+
description: string;
|
|
42
|
+
/** Public methods, bodies stripped, in source order. */
|
|
43
|
+
methods: readonly ServiceApiMethod[];
|
|
44
|
+
}
|
|
45
|
+
/** One harness event: its dispatch mode, exact signature, and listener contract. */
|
|
46
|
+
export interface EventApiEntry {
|
|
47
|
+
/** The scoped event name, e.g. `agent/status`. */
|
|
48
|
+
name: string;
|
|
49
|
+
/** The dispatch mode from the declaration's `@mode` tag. */
|
|
50
|
+
mode: string;
|
|
51
|
+
/** The exact listener signature, whitespace-normalized. */
|
|
52
|
+
signature: string;
|
|
53
|
+
/** First sentence of the event JSDoc. */
|
|
54
|
+
summary: string;
|
|
55
|
+
/** Complete event description. */
|
|
56
|
+
description: string;
|
|
57
|
+
/** Named listener parameters in signature order. */
|
|
58
|
+
parameters: readonly ApiParameter[];
|
|
59
|
+
}
|
|
60
|
+
/** One inherited (cordis core + loader/hmr/timer) `ctx` member group with its summary. */
|
|
61
|
+
export interface InheritedApiEntry {
|
|
62
|
+
/** The `ctx` member name(s), e.g. `ctx.on / ctx.once`. */
|
|
63
|
+
name: string;
|
|
64
|
+
/** One-line summary of what the member does. */
|
|
65
|
+
summary: string;
|
|
66
|
+
}
|
|
67
|
+
/** One named type declaration referenced by a Service or Event signature. */
|
|
68
|
+
export interface TypeApiEntry {
|
|
69
|
+
/** The exported type/interface name, e.g. `ShellRunResult`. */
|
|
70
|
+
name: string;
|
|
71
|
+
/** The full declaration text, comments stripped. */
|
|
72
|
+
declaration: string;
|
|
73
|
+
}
|
|
74
|
+
/** Every harness `ctx.<key>` service, sorted by key. */
|
|
75
|
+
export declare const SERVICE_API: readonly ServiceApiEntry[];
|
|
76
|
+
/** Every harness event, sorted by name. */
|
|
77
|
+
export declare const EVENT_API: readonly EventApiEntry[];
|
|
78
|
+
/** Shapes of every exported type the Service and Event signatures reference (transitively), sorted by name. */
|
|
79
|
+
export declare const TYPE_API: readonly TypeApiEntry[];
|
|
80
|
+
/** The inherited `ctx` API (cordis core + loader/hmr/timer), in curated order. */
|
|
81
|
+
export declare const INHERITED_CTX_API: readonly InheritedApiEntry[];
|
|
82
|
+
/**
|
|
83
|
+
* Project the Service Catalog as a compact directory or one exact coding contract.
|
|
84
|
+
* @param key - exact Service key; omit it to list all Services and method signatures.
|
|
85
|
+
* @param services - platform-specific visible Service entries.
|
|
86
|
+
* @returns compact navigation data or one detailed Service with its referenced type closure.
|
|
87
|
+
*/
|
|
88
|
+
export declare function queryServiceApi(key?: string, services?: readonly ServiceApiEntry[]): object;
|
|
89
|
+
/**
|
|
90
|
+
* Project the Event Catalog as a compact directory or one exact listener contract.
|
|
91
|
+
* @param name - exact Event name; omit it to list all Events and listener signatures.
|
|
92
|
+
* @param events - platform-specific visible Event entries.
|
|
93
|
+
* @returns compact navigation data or one detailed Event with its referenced type closure.
|
|
94
|
+
*/
|
|
95
|
+
export declare function queryEventApi(name?: string, events?: readonly EventApiEntry[]): object;
|
|
96
|
+
//# sourceMappingURL=api-catalog.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-half closure evaluation: the package source runs as the body of an
|
|
3
|
+
* async function whose parameters ARE the symbol surface. Shadowing parameters
|
|
4
|
+
* (setTimeout/fetch/require/…) turn the ambient browser globals into teaching
|
|
5
|
+
* redirects without touching the page. The host syntax-prechecked the source at
|
|
6
|
+
* define time; SyntaxError handling here is the engine-divergence fallback and
|
|
7
|
+
* reaches the model through the load report.
|
|
8
|
+
*/
|
|
9
|
+
import type { CordisDynamicPluginId } from '@hasna-internal/kai-api-remotes/client';
|
|
10
|
+
/** A mountable plugin as the closure must return it (FUNCTION or OBJECT form). */
|
|
11
|
+
export interface DynamicCordisEvaluatedPlugin {
|
|
12
|
+
/** Optional plugin name; the runner overwrites it with the module id. */
|
|
13
|
+
name?: string;
|
|
14
|
+
/** Services the browser half declares; the runner overwrites it from the dispatched row. */
|
|
15
|
+
inject?: string[];
|
|
16
|
+
/** Plugin body receiving the guard facade. */
|
|
17
|
+
apply: (ctx: unknown, config?: unknown) => unknown;
|
|
18
|
+
}
|
|
19
|
+
/** What the evaluator needs from the runner to build one package's closure. */
|
|
20
|
+
export interface DynamicCordisClosureEnv {
|
|
21
|
+
/** Route `host.call` to this package's host half over the wire. */
|
|
22
|
+
invoke(method: string, args: unknown): Promise<unknown>;
|
|
23
|
+
/** Mirror one runtime error text into the load report (console.error copies). */
|
|
24
|
+
noteError(message: string): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Where each withheld browser global sends the author instead. One home for two
|
|
28
|
+
* consumers: the closure traps below throw these, and a render crash whose
|
|
29
|
+
* message names one of them gets the same redirect appended — a package that
|
|
30
|
+
* reached the global some other way (`window.setInterval`) crashes with the
|
|
31
|
+
* engine's own bare text, and the author needs the redirect either way.
|
|
32
|
+
*/
|
|
33
|
+
export declare const DYNAMIC_CLIENT_REDIRECTS: Readonly<Record<string, string>>;
|
|
34
|
+
/** Per-package style-tag bookkeeping behind the `styles.insert` symbol. */
|
|
35
|
+
export declare class DynamicCordisStyles {
|
|
36
|
+
private readonly pluginId;
|
|
37
|
+
private readonly tags;
|
|
38
|
+
/** @param pluginId - owning Plugin ID, stamped as `data-dyn` on every tag. */
|
|
39
|
+
constructor(pluginId: CordisDynamicPluginId);
|
|
40
|
+
/**
|
|
41
|
+
* Inject one stylesheet, removed automatically on package unload.
|
|
42
|
+
* @param css - raw CSS text.
|
|
43
|
+
* @returns disposer removing this one tag early.
|
|
44
|
+
*/
|
|
45
|
+
insert(css: string): () => void;
|
|
46
|
+
/** Live tag count (load-report contribution summary). */
|
|
47
|
+
get count(): number;
|
|
48
|
+
/** Remove every tag this package still owns (unload path). */
|
|
49
|
+
dispose(): void;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Narrow a closure return value to a mountable plugin (host guard mirror).
|
|
53
|
+
* @param value - whatever the closure returned.
|
|
54
|
+
* @returns whether the value is mountable.
|
|
55
|
+
*/
|
|
56
|
+
export declare function isDynamicCordisPlugin(value: unknown): value is DynamicCordisEvaluatedPlugin | ((ctx: unknown) => unknown);
|
|
57
|
+
/**
|
|
58
|
+
* Evaluate one package's browser half and return the (un-guarded) plugin.
|
|
59
|
+
* @param pluginId - stable Plugin ID (console tag and style ownership).
|
|
60
|
+
* @param clientCode - the browser half's source: an async function body returning a plugin.
|
|
61
|
+
* @param env - runner wiring for `host.call` and error mirroring.
|
|
62
|
+
* @param styles - the package's style bookkeeping (owned by the caller so unload can dispose it).
|
|
63
|
+
* @returns the plugin the closure returned.
|
|
64
|
+
* @throws teaching errors for syntax failures and non-plugin returns.
|
|
65
|
+
*/
|
|
66
|
+
export declare function evaluateClientHalf(pluginId: CordisDynamicPluginId, clientCode: string, env: DynamicCordisClosureEnv, styles: DynamicCordisStyles): Promise<DynamicCordisEvaluatedPlugin | ((ctx: unknown) => unknown)>;
|
|
67
|
+
//# sourceMappingURL=evaluator.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The browser twin of the tool-cordis context facade: a whitelist of
|
|
3
|
+
* lifecycle-safe verbs plus optional `ctx.get()` lookup and declared-service
|
|
4
|
+
* property access, with
|
|
5
|
+
* framework internals withheld and Context-valued returns denied. Two seats
|
|
6
|
+
* carry extra machinery: `slots`, where the register proxy assigns the
|
|
7
|
+
* shadowing priority and ledgers the registration — invoking the service with
|
|
8
|
+
* the traced receiver so the effect lands on the CALLING plugin's fiber
|
|
9
|
+
* (SlotRegistry.register must stay a prototype method for exactly that
|
|
10
|
+
* reason) — and `theme`, whose override source is pinned to the package id.
|
|
11
|
+
*
|
|
12
|
+
* This is API discipline, not a security boundary: a dynamic package's code is
|
|
13
|
+
* as trusted as the host process that accepted its definition.
|
|
14
|
+
*/
|
|
15
|
+
import { Context } from '@deepseek-ai/cordis';
|
|
16
|
+
import type { DynamicCordisPackage } from '@hasna-internal/kai-api-remotes/client';
|
|
17
|
+
/** One package's slot-registration ledger row (contribution projection source). */
|
|
18
|
+
export interface DynamicCordisSlotLedgerRow {
|
|
19
|
+
/** Target slot name. */
|
|
20
|
+
slot: string;
|
|
21
|
+
/** The assigned shadowing priority (globally unique — how winners are matched back to packages). */
|
|
22
|
+
priority: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
/** What the facade needs beyond the real ctx to govern one package. */
|
|
25
|
+
export interface DynamicCordisGuardEnv {
|
|
26
|
+
/** The dispatched Package row. */
|
|
27
|
+
pkg: DynamicCordisPackage;
|
|
28
|
+
/** Ledger sink: every slot registration this package makes. */
|
|
29
|
+
ledger: DynamicCordisSlotLedgerRow[];
|
|
30
|
+
/**
|
|
31
|
+
* Ownership index sink: the component object seated in a slot, so a later
|
|
32
|
+
* render crash reported against the stored entry can be attributed back to
|
|
33
|
+
* this package. Identity is the key — the registry stores the component
|
|
34
|
+
* verbatim — which is why nothing else has to be remembered about the entry.
|
|
35
|
+
* @param component - whatever the package passed as its component.
|
|
36
|
+
*/
|
|
37
|
+
claim(component: unknown): void;
|
|
38
|
+
/** Allocate one page-local shadowing rank; later registrations sort first. */
|
|
39
|
+
allocatePriority(): number;
|
|
40
|
+
/** Report one post-activation guard rejection to the owning Agent. */
|
|
41
|
+
reportFailure(error: Error): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Build the facade one dynamic plugin's `apply` receives (host sandboxContext
|
|
45
|
+
* twin, browser seats). `ctx.get(name)` performs optional lookup; direct
|
|
46
|
+
* `ctx.serviceName` access is gated by the fiber's `inject` declaration.
|
|
47
|
+
* @param ctx - the plugin's real fiber ctx (loader-created).
|
|
48
|
+
* @param env - package row + ledger sink.
|
|
49
|
+
* @returns the whitelisting proxy standing in for ctx.
|
|
50
|
+
*/
|
|
51
|
+
export declare function dynamicCordisContext(ctx: Context, env: DynamicCordisGuardEnv): Context;
|
|
52
|
+
//# sourceMappingURL=guard.d.ts.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dynamic-package runner, browser half: the load engine that turns one browser
|
|
3
|
+
* half's source into a live cordis plugin (closure → guard → module table →
|
|
4
|
+
* loader entry, ./runtime.ts), plus the retract announcement that unloads it.
|
|
5
|
+
*
|
|
6
|
+
* Nothing loads on activation: this page holds no dynamic package until a
|
|
7
|
+
* dispatch arrives, and a dispatch only follows a model `cordis_run` or a user
|
|
8
|
+
* pressing a card's start control. A refresh therefore starts clean by design —
|
|
9
|
+
* host process memory still holds the definition, the page simply does not run
|
|
10
|
+
* it until asked again.
|
|
11
|
+
*/
|
|
12
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
13
|
+
import type { ApprovalRequestId, CordisDynamicPluginId, DynamicCordisInventoryRow } from '@hasna-internal/kai-api-remotes/client';
|
|
14
|
+
import type { DynamicCordisLivePackage } from './runtime.ts';
|
|
15
|
+
import type { CordisRunActivity, CordisRunFailure, CordisUserRunRequest } from './orchestrator.ts';
|
|
16
|
+
import type { CordisObservable, DynamicCordisRenderFailure } from './runtime.ts';
|
|
17
|
+
export { CordisRunOrchestrator } from './orchestrator.ts';
|
|
18
|
+
export { ClientCordisInspectRegistry } from './inspect-registry.ts';
|
|
19
|
+
export type { ClientCordisInspectHost, ClientCordisInspectProviderRegistration, ClientCordisInspectQueryContext, } from './inspect-registry.ts';
|
|
20
|
+
export type { CordisRunActivity, CordisRunFailure, CordisRunHostSeam, CordisRunOrchestratorEnv, CordisRunRequest, CordisUserRunRequest, } from './orchestrator.ts';
|
|
21
|
+
export { DynamicCordisPackageRunner } from './runtime.ts';
|
|
22
|
+
export type { CordisObservable, DynamicCordisClientHalf, DynamicCordisLivePackage, DynamicCordisLoadErrorCause, DynamicCordisLoadResult, DynamicCordisRenderFailure, DynamicCordisRunnerEnv, } from './runtime.ts';
|
|
23
|
+
export { DynamicCordisStyles, evaluateClientHalf, isDynamicCordisPlugin } from './evaluator.ts';
|
|
24
|
+
export type { DynamicCordisClosureEnv, DynamicCordisEvaluatedPlugin } from './evaluator.ts';
|
|
25
|
+
export { dynamicCordisContext } from './guard.ts';
|
|
26
|
+
export type { DynamicCordisGuardEnv, DynamicCordisSlotLedgerRow } from './guard.ts';
|
|
27
|
+
export { ClientTimerService } from './timer.ts';
|
|
28
|
+
export type { ApprovalRequestId, CordisDynamicPackageId, CordisDynamicPluginId, CordisDynamicPluginRunId, DynamicCordisPackage, } from '@hasna-internal/kai-api-remotes/client';
|
|
29
|
+
/**
|
|
30
|
+
* What a run surface reads and calls. The activity map is the single home of
|
|
31
|
+
* "a run is in flight", so an affordance never keeps its own copy — that is what
|
|
32
|
+
* makes it survive a remount.
|
|
33
|
+
*/
|
|
34
|
+
export interface CordisRunnerFace {
|
|
35
|
+
/** Each definition's in-flight run activity. */
|
|
36
|
+
readonly activeRuns: CordisObservable<ReadonlyMap<CordisDynamicPluginId, CordisRunActivity>>;
|
|
37
|
+
/** The last failure of this page's own run attempt, per definition. */
|
|
38
|
+
readonly lastRunError: CordisObservable<ReadonlyMap<CordisDynamicPluginId, CordisRunFailure>>;
|
|
39
|
+
/**
|
|
40
|
+
* This page's last render crash per definition: a browser half that loaded
|
|
41
|
+
* cleanly and then broke while React rendered it. Page-local and current by
|
|
42
|
+
* construction — cleared when the package stops, is retracted, or loads again —
|
|
43
|
+
* which is what makes it safe for a row to render directly. The host keeps its
|
|
44
|
+
* own last-across-pages copy for the model; the two have different owners and
|
|
45
|
+
* lifetimes and neither is derived from the other.
|
|
46
|
+
*/
|
|
47
|
+
readonly renderFailures: CordisObservable<ReadonlyMap<CordisDynamicPluginId, DynamicCordisRenderFailure>>;
|
|
48
|
+
/**
|
|
49
|
+
* Restore pending approvals after a page reconnect or missed event.
|
|
50
|
+
* @param rows - current dynamic Plugin inventory.
|
|
51
|
+
*/
|
|
52
|
+
reconcileApprovals(rows: readonly DynamicCordisInventoryRow[]): void;
|
|
53
|
+
/**
|
|
54
|
+
* Answer one run request with "run it" and drive both halves.
|
|
55
|
+
* @param requestId - the request being answered; unknown or settled ids are a no-op.
|
|
56
|
+
* @param approveFutureVersions - whether this decision covers later Packages of the same Plugin.
|
|
57
|
+
* @returns after the orchestration settled.
|
|
58
|
+
*/
|
|
59
|
+
approve(requestId: ApprovalRequestId, approveFutureVersions: boolean): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Answer one run request with "do not run it".
|
|
62
|
+
* @param requestId - the request being answered; unknown or settled ids are a no-op.
|
|
63
|
+
* @returns after the refusal reached the host.
|
|
64
|
+
*/
|
|
65
|
+
decline(requestId: ApprovalRequestId): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Run a definition here at the user's own request (the gesture authorizes it).
|
|
68
|
+
* A definition with a browser half also loads onto this page; a host-only one
|
|
69
|
+
* only comes up in the host process.
|
|
70
|
+
* @param request - the definition to run, its session, and whether it has a browser half.
|
|
71
|
+
* @returns after the orchestration settled.
|
|
72
|
+
*/
|
|
73
|
+
startUserRun(request: CordisUserRunRequest): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
* Observe what this page has loaded.
|
|
76
|
+
* @param fn - notified after every converged load or unload.
|
|
77
|
+
* @returns unsubscribe.
|
|
78
|
+
*/
|
|
79
|
+
subscribe(fn: () => void): () => void;
|
|
80
|
+
/**
|
|
81
|
+
* Read what this page currently has loaded.
|
|
82
|
+
* @returns immutable rows for live Client halves.
|
|
83
|
+
*/
|
|
84
|
+
getSnapshot(): readonly DynamicCordisLivePackage[];
|
|
85
|
+
/**
|
|
86
|
+
* Whether this page loaded a definition's browser half — page-local truth,
|
|
87
|
+
* never the host's "it is running".
|
|
88
|
+
* @param pluginId - stable Plugin identity.
|
|
89
|
+
* @returns true while a load is live here.
|
|
90
|
+
*/
|
|
91
|
+
isLoaded(pluginId: CordisDynamicPluginId): boolean;
|
|
92
|
+
}
|
|
93
|
+
declare module '@deepseek-ai/cordis' {
|
|
94
|
+
interface Context {
|
|
95
|
+
/** Run orchestration and page-local load state: what run surfaces read and call. */
|
|
96
|
+
dynamicCordisRunner: CordisRunnerFace;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/** Stable Cordis plugin name. */
|
|
100
|
+
export declare const name = "cordis-client-runner";
|
|
101
|
+
/**
|
|
102
|
+
* Required services: the loader/module chain for entries, the slot registry for
|
|
103
|
+
* contributions, and the `dynamicCordisRunner` Remote namespace. Declaring the
|
|
104
|
+
* namespace parks this plugin until the host side exists, so a page never loads
|
|
105
|
+
* a browser half whose host half it could not reach.
|
|
106
|
+
*/
|
|
107
|
+
export declare const inject: string[];
|
|
108
|
+
/**
|
|
109
|
+
* Client plugin body: build the runner and subscribe the dispatch family.
|
|
110
|
+
* @param ctx - client root context.
|
|
111
|
+
*/
|
|
112
|
+
export declare function apply(ctx: Context): void;
|
|
113
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** Browser registry for read-only Cordis capability providers. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { CordisInspectProviderManifest, CordisInspectQueryRequest, CordisInspectQueryResolution, CordisInspectRequestId, JsonValue } from '@hasna-internal/kai-api-remotes/client';
|
|
4
|
+
import type { SessionId } from '@hasna-internal/kai-client-connection/client';
|
|
5
|
+
/** Context supplied to a Client inspect provider query. */
|
|
6
|
+
export interface ClientCordisInspectQueryContext {
|
|
7
|
+
/** Cancellation broadcast by the Host. */
|
|
8
|
+
signal: AbortSignal;
|
|
9
|
+
/** Session whose model requested the query. */
|
|
10
|
+
sessionId: SessionId;
|
|
11
|
+
}
|
|
12
|
+
/** Client provider registration retained beside its serializable manifest. */
|
|
13
|
+
export interface ClientCordisInspectProviderRegistration {
|
|
14
|
+
/** Provider and explicit query directory. */
|
|
15
|
+
manifest: CordisInspectProviderManifest;
|
|
16
|
+
/** Execute one declared read-only method. */
|
|
17
|
+
query(method: string, input: JsonValue | undefined, context: ClientCordisInspectQueryContext): Promise<JsonValue>;
|
|
18
|
+
}
|
|
19
|
+
/** Remote operations needed by the Client registry. */
|
|
20
|
+
export interface ClientCordisInspectHost {
|
|
21
|
+
/** Replace the Host's mirrored Client manifest. */
|
|
22
|
+
sync(providers: readonly CordisInspectProviderManifest[]): Promise<void>;
|
|
23
|
+
/** Submit one query result; the first accepted page wins. */
|
|
24
|
+
resolve(sessionId: SessionId, requestId: CordisInspectRequestId, resolution: CordisInspectQueryResolution): Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
/** Client provider registry, manifest publisher, and live query dispatcher. */
|
|
27
|
+
export declare class ClientCordisInspectRegistry {
|
|
28
|
+
private readonly host;
|
|
29
|
+
private readonly providers;
|
|
30
|
+
private readonly active;
|
|
31
|
+
private publishQueued;
|
|
32
|
+
private syncChain;
|
|
33
|
+
/** @param host - folded manifest and query result transport. */
|
|
34
|
+
constructor(host: ClientCordisInspectHost);
|
|
35
|
+
/**
|
|
36
|
+
* Register one Client provider and publish a new complete manifest.
|
|
37
|
+
* @param registration - provider manifest and local handler.
|
|
38
|
+
* @returns idempotent disposer.
|
|
39
|
+
*/
|
|
40
|
+
register(registration: ClientCordisInspectProviderRegistration): () => void;
|
|
41
|
+
/** Publish the current complete manifest, including after reconnect. */
|
|
42
|
+
publish(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Execute and answer one Host-broadcast query.
|
|
45
|
+
* @param request - exact provider query and Session correlation received from Host.
|
|
46
|
+
* @returns after the first local result has been sent back to Host.
|
|
47
|
+
*/
|
|
48
|
+
query(request: CordisInspectQueryRequest): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Cancel local work after another page answered or the Tool call ended.
|
|
51
|
+
* @param requestId - query correlation that is no longer answerable.
|
|
52
|
+
*/
|
|
53
|
+
close(requestId: CordisInspectRequestId): void;
|
|
54
|
+
}
|
|
55
|
+
declare module '@deepseek-ai/cordis' {
|
|
56
|
+
interface Context {
|
|
57
|
+
/** Browser registry for pre-definition Cordis capability discovery. */
|
|
58
|
+
cordisInspect: ClientCordisInspectRegistry;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Provide the registry as a normal Client service.
|
|
63
|
+
* @param ctx - Client Cordis context receiving the service.
|
|
64
|
+
* @param registry - page-local inspect registry to publish.
|
|
65
|
+
*/
|
|
66
|
+
export declare function provideClientCordisInspect(ctx: Context, registry: ClientCordisInspectRegistry): void;
|
|
67
|
+
//# sourceMappingURL=inspect-registry.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-side run orchestration for model approvals and direct panel gestures.
|
|
3
|
+
* Host activation always precedes Client loading. The same Plugin-keyed state
|
|
4
|
+
* drives every surface, so remounting a panel never loses an open approval or
|
|
5
|
+
* an in-flight transition.
|
|
6
|
+
*/
|
|
7
|
+
import type { ApprovalRequestId, CordisDynamicPackageId, CordisDynamicPluginId, CordisDynamicPluginRunId, CordisDynamicRunMode, DynamicCordisClientSource, DynamicCordisHostHalfResult, DynamicCordisInventoryRow, DynamicCordisResolveAck, DynamicCordisRunResolution, DynamicCordisRunResponse } from '@hasna-internal/kai-api-remotes/client';
|
|
8
|
+
import type { SessionId } from '@hasna-internal/kai-client-connection/client';
|
|
9
|
+
import type { CordisObservable, DynamicCordisPackageRunner } from './runtime.ts';
|
|
10
|
+
/** One Plugin's in-flight approval or activation. */
|
|
11
|
+
export type CordisRunActivity = {
|
|
12
|
+
phase: 'awaiting-approval';
|
|
13
|
+
requestId: ApprovalRequestId;
|
|
14
|
+
agentId: SessionId;
|
|
15
|
+
packageId: CordisDynamicPackageId;
|
|
16
|
+
mode: CordisDynamicRunMode;
|
|
17
|
+
name: string;
|
|
18
|
+
purpose: string;
|
|
19
|
+
} | {
|
|
20
|
+
phase: 'orchestrating';
|
|
21
|
+
agentId: SessionId;
|
|
22
|
+
packageId: CordisDynamicPackageId;
|
|
23
|
+
mode: CordisDynamicRunMode;
|
|
24
|
+
};
|
|
25
|
+
/** Why this page's latest activation attempt failed. */
|
|
26
|
+
export interface CordisRunFailure {
|
|
27
|
+
/** Package the attempt targeted. */
|
|
28
|
+
packageId: CordisDynamicPackageId;
|
|
29
|
+
/** Which half or settlement stage failed. */
|
|
30
|
+
reason: 'host-half-failed' | 'client-half-failed';
|
|
31
|
+
/** Actionable failure text. */
|
|
32
|
+
message: string;
|
|
33
|
+
/** Original failure stack when available. */
|
|
34
|
+
stack?: string;
|
|
35
|
+
}
|
|
36
|
+
/** Host operations consumed by the orchestrator after transport folding. */
|
|
37
|
+
export interface CordisRunHostSeam {
|
|
38
|
+
/** Start a new Host activation or attach this page to an existing one. */
|
|
39
|
+
runHostHalf(agentId: SessionId, pluginId: CordisDynamicPluginId, packageId: CordisDynamicPackageId, mode: CordisDynamicRunMode, requestId: ApprovalRequestId | null, approveFutureVersions: boolean): Promise<DynamicCordisHostHalfResult>;
|
|
40
|
+
/** Fetch Client source for one exact active run. */
|
|
41
|
+
getClientCode(agentId: SessionId, pluginId: CordisDynamicPluginId, pluginRunId: CordisDynamicPluginRunId): Promise<DynamicCordisClientSource>;
|
|
42
|
+
/** Settle a model-driven approval. */
|
|
43
|
+
resolveRequestRun(requestId: ApprovalRequestId, resolution: DynamicCordisRunResolution): Promise<DynamicCordisResolveAck>;
|
|
44
|
+
/** Settle a direct panel activation after this page handles its Client half. */
|
|
45
|
+
settleUserRun(agentId: SessionId, pluginId: CordisDynamicPluginId, resolution: DynamicCordisRunResolution): Promise<DynamicCordisRunResponse>;
|
|
46
|
+
}
|
|
47
|
+
/** Dependencies of one page's orchestrator. */
|
|
48
|
+
export interface CordisRunOrchestratorEnv {
|
|
49
|
+
/** Page-local Client loader. */
|
|
50
|
+
runner: DynamicCordisPackageRunner;
|
|
51
|
+
/** Folded Host RPC operations. */
|
|
52
|
+
host: CordisRunHostSeam;
|
|
53
|
+
}
|
|
54
|
+
/** Forwarded approval request fields used by this page. */
|
|
55
|
+
export interface CordisRunRequest {
|
|
56
|
+
requestId: ApprovalRequestId;
|
|
57
|
+
agentId: SessionId;
|
|
58
|
+
pluginId: CordisDynamicPluginId;
|
|
59
|
+
packageId: CordisDynamicPackageId;
|
|
60
|
+
mode: CordisDynamicRunMode;
|
|
61
|
+
name: string;
|
|
62
|
+
purpose: string;
|
|
63
|
+
requiresApproval: boolean;
|
|
64
|
+
}
|
|
65
|
+
/** Direct panel activation request. */
|
|
66
|
+
export interface CordisUserRunRequest {
|
|
67
|
+
agentId: SessionId;
|
|
68
|
+
pluginId: CordisDynamicPluginId;
|
|
69
|
+
packageId: CordisDynamicPackageId;
|
|
70
|
+
mode: CordisDynamicRunMode;
|
|
71
|
+
/** Host-only Packages finish without a Client load or settlement call. */
|
|
72
|
+
hasClientHalf: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** Drives Host → Client activation and publishes Plugin-keyed activity. */
|
|
75
|
+
export declare class CordisRunOrchestrator {
|
|
76
|
+
private readonly env;
|
|
77
|
+
private readonly requests;
|
|
78
|
+
private readonly activity;
|
|
79
|
+
private readonly failures;
|
|
80
|
+
private readonly inFlight;
|
|
81
|
+
private readonly listeners;
|
|
82
|
+
private activityCache;
|
|
83
|
+
private failureCache;
|
|
84
|
+
/** @param env - Client loader and folded Host operations. */
|
|
85
|
+
constructor(env: CordisRunOrchestratorEnv);
|
|
86
|
+
/** Open approvals and current activation attempts, keyed by stable Plugin ID. */
|
|
87
|
+
readonly activeRuns: CordisObservable<ReadonlyMap<CordisDynamicPluginId, CordisRunActivity>>;
|
|
88
|
+
/** Latest page-side activation failure for each Plugin. */
|
|
89
|
+
readonly lastRunError: CordisObservable<ReadonlyMap<CordisDynamicPluginId, CordisRunFailure>>;
|
|
90
|
+
/**
|
|
91
|
+
* Register a Client activation request, starting it immediately when the Plugin is already authorized.
|
|
92
|
+
* @param request - forwarded approval and activation metadata.
|
|
93
|
+
*/
|
|
94
|
+
open(request: CordisRunRequest): void;
|
|
95
|
+
/**
|
|
96
|
+
* Rebuild pending approvals and automatic Client activations from an authoritative Host inventory read.
|
|
97
|
+
* @param rows - complete process-wide Plugin inventory.
|
|
98
|
+
*/
|
|
99
|
+
reconcileApprovals(rows: readonly DynamicCordisInventoryRow[]): void;
|
|
100
|
+
/**
|
|
101
|
+
* Close an approval settled by another page or by cancellation.
|
|
102
|
+
* @param requestId - approval request that can no longer be answered here.
|
|
103
|
+
*/
|
|
104
|
+
close(requestId: ApprovalRequestId): void;
|
|
105
|
+
/**
|
|
106
|
+
* Approve and execute one still-open model request.
|
|
107
|
+
* @param requestId - approval request to execute.
|
|
108
|
+
* @param approveFutureVersions - whether this approval covers later Packages for the same Plugin.
|
|
109
|
+
*/
|
|
110
|
+
approve(requestId: ApprovalRequestId, approveFutureVersions: boolean): Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Reject one still-open model request without executing either half.
|
|
113
|
+
* @param requestId - approval request to reject.
|
|
114
|
+
*/
|
|
115
|
+
decline(requestId: ApprovalRequestId): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Execute a direct panel run; the user gesture itself authorizes it.
|
|
118
|
+
* @param request - exact Package activation selected by the user.
|
|
119
|
+
*/
|
|
120
|
+
startUserRun(request: CordisUserRunRequest): Promise<void>;
|
|
121
|
+
private observe;
|
|
122
|
+
private commit;
|
|
123
|
+
private orchestrate;
|
|
124
|
+
private drive;
|
|
125
|
+
private startHost;
|
|
126
|
+
private finishClientFailure;
|
|
127
|
+
private settleDirect;
|
|
128
|
+
private answer;
|
|
129
|
+
private fail;
|
|
130
|
+
}
|
|
131
|
+
//# sourceMappingURL=orchestrator.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Built-in Client inspect providers over live Client-owned services. */
|
|
2
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
3
|
+
import type { JsonValue } from '@hasna-internal/kai-api-remotes/client';
|
|
4
|
+
import type { ClientCordisInspectProviderRegistration } from './inspect-registry.ts';
|
|
5
|
+
/** Exact Client closure symbols exposed by the evaluator and guard. */
|
|
6
|
+
export declare const CLIENT_BUILTIN_INSPECTION: readonly JsonValue[];
|
|
7
|
+
/**
|
|
8
|
+
* Construct the first-party Client provider registrations.
|
|
9
|
+
* @param ctx - Client context used for live Service-backed queries.
|
|
10
|
+
* @returns registrations for static catalogs and live Client capabilities.
|
|
11
|
+
*/
|
|
12
|
+
export declare function clientInspectProviders(ctx: Context): ClientCordisInspectProviderRegistration[];
|
|
13
|
+
//# sourceMappingURL=providers.d.ts.map
|