@cef-ai/cli 1.6.0 → 1.8.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/cli-program.d.ts.map +1 -1
- package/dist/cli-program.js +43 -5
- package/dist/cli-program.js.map +1 -1
- package/dist/commands/build.d.ts +11 -0
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +48 -8
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/dev.d.ts +61 -0
- package/dist/commands/dev.d.ts.map +1 -0
- package/dist/commands/dev.js +250 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/init.js +33 -4
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +61 -0
- package/dist/commands/push.js.map +1 -1
- package/dist/lib/env.d.ts +41 -8
- package/dist/lib/env.d.ts.map +1 -1
- package/dist/lib/env.js +42 -9
- package/dist/lib/env.js.map +1 -1
- package/dist/lib/widget-manifest.d.ts +50 -0
- package/dist/lib/widget-manifest.d.ts.map +1 -0
- package/dist/lib/widget-manifest.js +85 -0
- package/dist/lib/widget-manifest.js.map +1 -0
- package/dist/lib/widget-runtime-bundle.d.ts +7 -0
- package/dist/lib/widget-runtime-bundle.d.ts.map +1 -0
- package/dist/lib/widget-runtime-bundle.js +31 -0
- package/dist/lib/widget-runtime-bundle.js.map +1 -0
- package/dist/lib.d.ts +4 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +2 -0
- package/dist/lib.js.map +1 -1
- package/package.json +4 -3
- package/templates/hello-world/cef.config.ts +14 -2
- package/templates/hello-world/package.json +8 -2
- package/templates/hello-world/src/agent.ts +7 -2
- package/templates/hello-world/widgets/hello/app.js +117 -7
- package/templates/hello-world/widgets/hello/index.html +16 -1
package/dist/lib/env.js
CHANGED
|
@@ -1,29 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Cere embed-wallet `appId` for CEF widgets. `cere-widget` is the shared
|
|
3
|
+
* widget app identity (distinct from demo apps like `cef-chat`). Override per
|
|
4
|
+
* deployment via `buildWidgetManifestForDecl`'s `walletAppId` arg or
|
|
5
|
+
* `$CEF_WALLET_APP_ID`.
|
|
6
|
+
*/
|
|
7
|
+
export const WIDGET_WALLET_APP_ID = "cere-widget";
|
|
8
|
+
/**
|
|
9
|
+
* Per-environment endpoint table. One flat set of endpoints per env.
|
|
3
10
|
*
|
|
4
|
-
* DDC presets
|
|
11
|
+
* DDC presets: dev=devnet, stage=testnet, prod=mainnet.
|
|
5
12
|
*
|
|
6
|
-
* `dev`
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `--marketplace` explicitly for stage/prod if these are wrong.
|
|
13
|
+
* `dev` and `stage` (= the `compute.test` cluster) hosts are verified against
|
|
14
|
+
* the cef-chat reference config. `prod` hosts are UNVERIFIED (no prod config
|
|
15
|
+
* on disk) and mirror the pattern — pass `--endpoint` / `--marketplace`
|
|
16
|
+
* explicitly for prod if they're wrong.
|
|
11
17
|
*/
|
|
12
18
|
export const ENVIRONMENTS = {
|
|
19
|
+
// All dev endpoints verified against the cef-chat reference app
|
|
20
|
+
// (`cef-chat/.env.example`): the user-vault host is `vault-api.compute…`
|
|
21
|
+
// (not `vault.compute…`).
|
|
13
22
|
dev: {
|
|
14
23
|
ddcPreset: "DEVNET",
|
|
15
24
|
orchestrator: "https://orchestrator.compute.dev.ddcdragon.com/",
|
|
16
25
|
marketplace: "https://agent-marketplace.compute.dev.ddcdragon.com",
|
|
26
|
+
vault: "https://vault-api.compute.dev.ddcdragon.com/",
|
|
27
|
+
gar: "https://gar.compute.dev.ddcdragon.com",
|
|
28
|
+
s3GatewayAuthInfo: "https://ddc-s3-gateway.compute.dev.ddcdragon.com/auth/info",
|
|
29
|
+
rpc: "wss://rpc.devnet.cere.network/ws",
|
|
30
|
+
// Wallet env follows the CEF env. NOTE: cef-chat historically pinned the
|
|
31
|
+
// embed-wallet to `prod` even against dev compute — if the `dev` wallet
|
|
32
|
+
// backend doesn't hold your account, override this or use `--env prod`.
|
|
33
|
+
wallet: { appId: WIDGET_WALLET_APP_ID, env: "dev" },
|
|
17
34
|
},
|
|
35
|
+
// "stage" = the TEST cluster (`compute.test`), verified against
|
|
36
|
+
// `cef-chat/.env.stage`. Not `compute.stage`.
|
|
18
37
|
stage: {
|
|
19
38
|
ddcPreset: "TESTNET",
|
|
20
|
-
orchestrator: "https://orchestrator.compute.
|
|
21
|
-
marketplace: "https://agent-marketplace.compute.
|
|
39
|
+
orchestrator: "https://orchestrator.compute.test.ddcdragon.com/",
|
|
40
|
+
marketplace: "https://agent-marketplace.compute.test.ddcdragon.com",
|
|
41
|
+
vault: "https://vault-api.compute.test.ddcdragon.com/",
|
|
42
|
+
gar: "https://gar.compute.test.ddcdragon.com",
|
|
43
|
+
s3GatewayAuthInfo: "https://ddc-s3-gateway.compute.test.ddcdragon.com/auth/info",
|
|
44
|
+
rpc: "wss://rpc.testnet.cere.network/ws",
|
|
45
|
+
wallet: { appId: WIDGET_WALLET_APP_ID, env: "stage" },
|
|
22
46
|
},
|
|
47
|
+
// FLAG — prod endpoints are UNVERIFIED (no prod config found on disk; prod
|
|
48
|
+
// may use distinct hosts such as `vault.cere.io` / `marketplace.cere.network`).
|
|
49
|
+
// The `compute.prod.ddcdragon.com` hosts mirror the verified dev/test pattern.
|
|
50
|
+
// Override with explicit `--endpoint` / `--marketplace` for prod.
|
|
23
51
|
prod: {
|
|
24
52
|
ddcPreset: "MAINNET",
|
|
25
53
|
orchestrator: "https://orchestrator.compute.prod.ddcdragon.com/",
|
|
26
54
|
marketplace: "https://agent-marketplace.compute.prod.ddcdragon.com",
|
|
55
|
+
vault: "https://vault-api.compute.prod.ddcdragon.com/",
|
|
56
|
+
gar: "https://gar.compute.prod.ddcdragon.com",
|
|
57
|
+
s3GatewayAuthInfo: "https://ddc-s3-gateway.compute.prod.ddcdragon.com/auth/info",
|
|
58
|
+
rpc: "wss://rpc.mainnet.cere.network/ws",
|
|
59
|
+
wallet: { appId: WIDGET_WALLET_APP_ID, env: "prod" },
|
|
27
60
|
},
|
|
28
61
|
};
|
|
29
62
|
export const DEFAULT_ENV = "dev";
|
package/dist/lib/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/lib/env.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../../src/lib/env.ts"],"names":[],"mappings":"AAmDA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,YAAY,GAA8B;IACrD,gEAAgE;IAChE,yEAAyE;IACzE,0BAA0B;IAC1B,GAAG,EAAE;QACH,SAAS,EAAE,QAAQ;QACnB,YAAY,EAAE,iDAAiD;QAC/D,WAAW,EAAE,qDAAqD;QAClE,KAAK,EAAE,8CAA8C;QACrD,GAAG,EAAE,uCAAuC;QAC5C,iBAAiB,EAAE,4DAA4D;QAC/E,GAAG,EAAE,kCAAkC;QACvC,yEAAyE;QACzE,wEAAwE;QACxE,wEAAwE;QACxE,MAAM,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,KAAK,EAAE;KACpD;IACD,gEAAgE;IAChE,8CAA8C;IAC9C,KAAK,EAAE;QACL,SAAS,EAAE,SAAS;QACpB,YAAY,EAAE,kDAAkD;QAChE,WAAW,EAAE,sDAAsD;QACnE,KAAK,EAAE,+CAA+C;QACtD,GAAG,EAAE,wCAAwC;QAC7C,iBAAiB,EAAE,6DAA6D;QAChF,GAAG,EAAE,mCAAmC;QACxC,MAAM,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,OAAO,EAAE;KACtD;IACD,2EAA2E;IAC3E,gFAAgF;IAChF,+EAA+E;IAC/E,kEAAkE;IAClE,IAAI,EAAE;QACJ,SAAS,EAAE,SAAS;QACpB,YAAY,EAAE,kDAAkD;QAChE,WAAW,EAAE,sDAAsD;QACnE,KAAK,EAAE,+CAA+C;QACtD,GAAG,EAAE,wCAAwC;QAC7C,iBAAiB,EAAE,6DAA6D;QAChF,GAAG,EAAE,mCAAmC;QACxC,MAAM,EAAE,EAAE,KAAK,EAAE,oBAAoB,EAAE,GAAG,EAAE,MAAM,EAAE;KACrD;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAW,KAAK,CAAC;AAEzC,iFAAiF;AACjF,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,MAAM,MAAM,GAAG,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC;IAC3C,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,WAAW,CAAC;IAC9D,MAAM,EAAE,GAAG,MAAM,CAAC,WAAW,EAAE,CAAC;IAChC,IAAI,EAAE,KAAK,KAAK,IAAI,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,MAAM,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,2CAA2C,MAAM,IAAI,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,6DAA6D;AAC7D,MAAM,UAAU,SAAS,CAAC,IAAa;IACrC,OAAO,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget manifest builder (build-time tooling).
|
|
3
|
+
*
|
|
4
|
+
* `@cef-ai/widget-runtime` *reads* a `WidgetManifest` at boot but never builds
|
|
5
|
+
* one — that is the CLI's job. This module assembles the arguments for the
|
|
6
|
+
* runtime's `buildWidgetManifest` from a `cef.config.ts` widget declaration, the
|
|
7
|
+
* resolved `--env` endpoints (see `./env.ts`), and the agent's AS pubkey.
|
|
8
|
+
*
|
|
9
|
+
* Used by both `cef build` (bakes the manifest into `dist/…/widgets/<id>/`) and
|
|
10
|
+
* `cef dev` (serves it inline), so the embedded and standalone paths get an
|
|
11
|
+
* identical manifest.
|
|
12
|
+
*/
|
|
13
|
+
import { type WidgetManifest } from "@cef-ai/widget-runtime/build-tools";
|
|
14
|
+
import type { ConfigWidget } from "../build/load-config.js";
|
|
15
|
+
import { type CefEnv } from "./env.js";
|
|
16
|
+
export interface BuildWidgetManifestArgs {
|
|
17
|
+
/** The widget declaration from `cef.config.ts`. */
|
|
18
|
+
widget: ConfigWidget;
|
|
19
|
+
/** Agent alias — the `cef.config.ts` `id`. Forms the manifest `agentId`. */
|
|
20
|
+
alias: string;
|
|
21
|
+
/** `--env` flag (falls back to `$CEF_ENV`, then `dev`). */
|
|
22
|
+
env?: string;
|
|
23
|
+
/**
|
|
24
|
+
* On-platform AS pubkey (bare hex). When present the manifest `agentId` is
|
|
25
|
+
* `<asPubkey>:<alias>`; when absent it falls back to the bare alias. The bare
|
|
26
|
+
* alias is expected at `cef build` time — `cef push` completes the `agentId`
|
|
27
|
+
* to `<asPubkey>:<alias>` when it stamps the uploaded widget manifest, the
|
|
28
|
+
* same way it stamps the agent manifest (so `cef build` needs no AS pubkey).
|
|
29
|
+
*/
|
|
30
|
+
asPubkey?: string;
|
|
31
|
+
/** Override the wallet `appId` from the env table (e.g. `$CEF_WALLET_APP_ID`). */
|
|
32
|
+
walletAppId?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface BuildWidgetManifestOutput {
|
|
35
|
+
manifest: WidgetManifest;
|
|
36
|
+
/** Resolved env the endpoints came from. */
|
|
37
|
+
env: CefEnv;
|
|
38
|
+
/** Non-fatal advisories (dropped unknown kind, …). */
|
|
39
|
+
warnings: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a `WidgetManifest` for one widget declaration + resolved env.
|
|
43
|
+
*
|
|
44
|
+
* Deliberately tolerant: an unknown `kind` (WidgetDecl.kind is free-form) is
|
|
45
|
+
* dropped with a warning rather than throwing, so a `cef build` never fails on
|
|
46
|
+
* a widget the runtime doesn't render as a config-driven kind — the widget can
|
|
47
|
+
* still query the cubby via `window.WidgetRuntime`.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildWidgetManifestForDecl(args: BuildWidgetManifestArgs): BuildWidgetManifestOutput;
|
|
50
|
+
//# sourceMappingURL=widget-manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-manifest.d.ts","sourceRoot":"","sources":["../../src/lib/widget-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAEL,KAAK,cAAc,EACpB,MAAM,oCAAoC,CAAC;AAG5C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAyB,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AAc9D,MAAM,WAAW,uBAAuB;IACtC,mDAAmD;IACnD,MAAM,EAAE,YAAY,CAAC;IACrB,4EAA4E;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,2DAA2D;IAC3D,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,yBAAyB;IACxC,QAAQ,EAAE,cAAc,CAAC;IACzB,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,sDAAsD;IACtD,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,IAAI,EAAE,uBAAuB,GAC5B,yBAAyB,CAuD3B"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Widget manifest builder (build-time tooling).
|
|
3
|
+
*
|
|
4
|
+
* `@cef-ai/widget-runtime` *reads* a `WidgetManifest` at boot but never builds
|
|
5
|
+
* one — that is the CLI's job. This module assembles the arguments for the
|
|
6
|
+
* runtime's `buildWidgetManifest` from a `cef.config.ts` widget declaration, the
|
|
7
|
+
* resolved `--env` endpoints (see `./env.ts`), and the agent's AS pubkey.
|
|
8
|
+
*
|
|
9
|
+
* Used by both `cef build` (bakes the manifest into `dist/…/widgets/<id>/`) and
|
|
10
|
+
* `cef dev` (serves it inline), so the embedded and standalone paths get an
|
|
11
|
+
* identical manifest.
|
|
12
|
+
*/
|
|
13
|
+
import { buildWidgetManifest, } from "@cef-ai/widget-runtime/build-tools";
|
|
14
|
+
import { envConfig, resolveEnv } from "./env.js";
|
|
15
|
+
/** Runtime-known widget kinds. `WidgetDecl.kind` is free-form, so unrecognized
|
|
16
|
+
* values are dropped from the baked manifest (see below). */
|
|
17
|
+
const KNOWN_KINDS = new Set([
|
|
18
|
+
"record",
|
|
19
|
+
"list",
|
|
20
|
+
"dashboard",
|
|
21
|
+
"submit",
|
|
22
|
+
"conversation",
|
|
23
|
+
"custom",
|
|
24
|
+
"composite",
|
|
25
|
+
]);
|
|
26
|
+
/**
|
|
27
|
+
* Build a `WidgetManifest` for one widget declaration + resolved env.
|
|
28
|
+
*
|
|
29
|
+
* Deliberately tolerant: an unknown `kind` (WidgetDecl.kind is free-form) is
|
|
30
|
+
* dropped with a warning rather than throwing, so a `cef build` never fails on
|
|
31
|
+
* a widget the runtime doesn't render as a config-driven kind — the widget can
|
|
32
|
+
* still query the cubby via `window.WidgetRuntime`.
|
|
33
|
+
*/
|
|
34
|
+
export function buildWidgetManifestForDecl(args) {
|
|
35
|
+
const { widget, alias } = args;
|
|
36
|
+
const env = resolveEnv(args.env);
|
|
37
|
+
const cfg = envConfig(args.env);
|
|
38
|
+
const warnings = [];
|
|
39
|
+
// `agentId` is completed at `cef push`: build bakes the bare alias
|
|
40
|
+
// (identity-free) and push stamps `<asPubkey>:<alias>` into the uploaded
|
|
41
|
+
// widget manifest, mirroring how it stamps the agent manifest.
|
|
42
|
+
const asPubkey = args.asPubkey?.trim();
|
|
43
|
+
const agentId = asPubkey ? `${asPubkey}:${alias}` : alias;
|
|
44
|
+
// `WidgetDecl.kind` is a free-form string; only forward it (and its config)
|
|
45
|
+
// when it maps to a runtime kind, so buildWidgetManifest's validateConfig
|
|
46
|
+
// doesn't reject an author's host-specific hint (e.g. "panel").
|
|
47
|
+
let kind;
|
|
48
|
+
let config;
|
|
49
|
+
if (widget.kind !== undefined) {
|
|
50
|
+
if (KNOWN_KINDS.has(widget.kind)) {
|
|
51
|
+
kind = widget.kind;
|
|
52
|
+
config = widget.config;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
warnings.push(`widget "${widget.id}": kind "${widget.kind}" is not a runtime widget ` +
|
|
56
|
+
`kind (${[...KNOWN_KINDS].join(", ")}); dropping kind/config from the ` +
|
|
57
|
+
`baked manifest (the widget still runs as a custom UI).`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const manifest = buildWidgetManifest({
|
|
61
|
+
widgetId: widget.id,
|
|
62
|
+
name: widget.name ?? widget.id,
|
|
63
|
+
agentId,
|
|
64
|
+
...(widget.cubbyAlias !== undefined ? { cubbyAlias: widget.cubbyAlias } : { cubbyAlias: "" }),
|
|
65
|
+
wallet: {
|
|
66
|
+
appId: args.walletAppId ?? process.env.CEF_WALLET_APP_ID ?? cfg.wallet.appId,
|
|
67
|
+
env: cfg.wallet.env,
|
|
68
|
+
},
|
|
69
|
+
endpoints: {
|
|
70
|
+
vault: cfg.vault,
|
|
71
|
+
gar: cfg.gar,
|
|
72
|
+
marketplace: cfg.marketplace,
|
|
73
|
+
s3GatewayAuthInfo: cfg.s3GatewayAuthInfo,
|
|
74
|
+
rpc: cfg.rpc,
|
|
75
|
+
},
|
|
76
|
+
...(widget.queries && widget.queries.length > 0 ? { queries: widget.queries } : {}),
|
|
77
|
+
...(widget.events && widget.events.length > 0
|
|
78
|
+
? { events: widget.events.map((type) => ({ type })) }
|
|
79
|
+
: {}),
|
|
80
|
+
...(kind !== undefined ? { kind } : {}),
|
|
81
|
+
...(config !== undefined ? { config } : {}),
|
|
82
|
+
});
|
|
83
|
+
return { manifest, env, warnings };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=widget-manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-manifest.js","sourceRoot":"","sources":["../../src/lib/widget-manifest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,mBAAmB,GAEpB,MAAM,oCAAoC,CAAC;AAI5C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAe,MAAM,UAAU,CAAC;AAE9D;8DAC8D;AAC9D,MAAM,WAAW,GAAwB,IAAI,GAAG,CAAa;IAC3D,QAAQ;IACR,MAAM;IACN,WAAW;IACX,QAAQ;IACR,cAAc;IACd,QAAQ;IACR,WAAW;CACZ,CAAC,CAAC;AA6BH;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,IAA6B;IAE7B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;IAC/B,MAAM,GAAG,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAChC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,mEAAmE;IACnE,yEAAyE;IACzE,+DAA+D;IAC/D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC;IACvC,MAAM,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,QAAQ,IAAI,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC;IAE1D,4EAA4E;IAC5E,0EAA0E;IAC1E,gEAAgE;IAChE,IAAI,IAA4B,CAAC;IACjC,IAAI,MAAgC,CAAC;IACrC,IAAI,MAAM,CAAC,IAAI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AAO,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACnF,GAAG,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC;YAC3C,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE;YACrD,CAAC,CAAC,EAAE,CAAC;QACP,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5C,CAAC,CAAC;IAEH,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const WIDGET_RUNTIME_BUNDLE_BASENAME = "widget-runtime.js";
|
|
2
|
+
/**
|
|
3
|
+
* Absolute path to `@cef-ai/widget-runtime/dist/widget-runtime.js`, or `null`
|
|
4
|
+
* if the package (or its build output) can't be resolved.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveWidgetRuntimeBundle(): string | null;
|
|
7
|
+
//# sourceMappingURL=widget-runtime-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-runtime-bundle.d.ts","sourceRoot":"","sources":["../../src/lib/widget-runtime-bundle.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,8BAA8B,sBAAsB,CAAC;AAElE;;;GAGG;AACH,wBAAgB,0BAA0B,IAAI,MAAM,GAAG,IAAI,CAY1D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locate the built `@cef-ai/widget-runtime` IIFE bundle
|
|
3
|
+
* (`dist/widget-runtime.js`) that `cef build` vendors into each widget's dist
|
|
4
|
+
* dir and `cef dev` serves at `/widget-runtime.js`.
|
|
5
|
+
*
|
|
6
|
+
* The package's `.` export resolves to `dist/index.js`; the IIFE sits next to
|
|
7
|
+
* it as `dist/widget-runtime.js`. Resolving through `createRequire` keeps this
|
|
8
|
+
* working both in the monorepo (workspace symlink) and in a published install
|
|
9
|
+
* (real dependency).
|
|
10
|
+
*/
|
|
11
|
+
import { createRequire } from "node:module";
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
export const WIDGET_RUNTIME_BUNDLE_BASENAME = "widget-runtime.js";
|
|
16
|
+
/**
|
|
17
|
+
* Absolute path to `@cef-ai/widget-runtime/dist/widget-runtime.js`, or `null`
|
|
18
|
+
* if the package (or its build output) can't be resolved.
|
|
19
|
+
*/
|
|
20
|
+
export function resolveWidgetRuntimeBundle() {
|
|
21
|
+
let mainEntry;
|
|
22
|
+
try {
|
|
23
|
+
mainEntry = require.resolve("@cef-ai/widget-runtime");
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
const bundle = path.join(path.dirname(mainEntry), WIDGET_RUNTIME_BUNDLE_BASENAME);
|
|
29
|
+
return fs.existsSync(bundle) ? bundle : null;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=widget-runtime-bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widget-runtime-bundle.js","sourceRoot":"","sources":["../../src/lib/widget-runtime-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,MAAM,CAAC,MAAM,8BAA8B,GAAG,mBAAmB,CAAC;AAElE;;;GAGG;AACH,MAAM,UAAU,0BAA0B;IACxC,IAAI,SAAiB,CAAC;IACtB,IAAI,CAAC;QACH,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CACtB,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EACvB,8BAA8B,CAC/B,CAAC;IACF,OAAO,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC"}
|
package/dist/lib.d.ts
CHANGED
|
@@ -7,6 +7,10 @@ export { cefInit, detectPackageManager } from "./commands/init.js";
|
|
|
7
7
|
export type { CefInitOptions, CefInitResult, PackageManager, } from "./commands/init.js";
|
|
8
8
|
export { cefBuild } from "./commands/build.js";
|
|
9
9
|
export type { CefBuildOptions, CefBuildResult } from "./commands/build.js";
|
|
10
|
+
export { cefDev } from "./commands/dev.js";
|
|
11
|
+
export type { CefDevOptions, CefDevHandle } from "./commands/dev.js";
|
|
12
|
+
export { buildWidgetManifestForDecl } from "./lib/widget-manifest.js";
|
|
13
|
+
export type { BuildWidgetManifestArgs, BuildWidgetManifestOutput, } from "./lib/widget-manifest.js";
|
|
10
14
|
export { cefTypegen } from "./commands/typegen.js";
|
|
11
15
|
export type { CefTypegenOptions, CefTypegenResult, } from "./commands/typegen.js";
|
|
12
16
|
export { cefInspect } from "./commands/inspect.js";
|
package/dist/lib.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;GA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B,GAC3B,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,yBAAyB,GAC1B,MAAM,sBAAsB,CAAC"}
|
package/dist/lib.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export { cefInit, detectPackageManager } from "./commands/init.js";
|
|
7
7
|
export { cefBuild } from "./commands/build.js";
|
|
8
|
+
export { cefDev } from "./commands/dev.js";
|
|
9
|
+
export { buildWidgetManifestForDecl } from "./lib/widget-manifest.js";
|
|
8
10
|
export { cefTypegen } from "./commands/typegen.js";
|
|
9
11
|
export { cefInspect } from "./commands/inspect.js";
|
|
10
12
|
export { cefPublish } from "./commands/publish.js";
|
package/dist/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAOnE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAM3D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAOnE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAG/C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AAMtE,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAMnD,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAGjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAM3D,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cef-ai/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -21,8 +21,9 @@
|
|
|
21
21
|
"esbuild": "^0.21.0",
|
|
22
22
|
"json-schema-to-typescript": "^14.0.0",
|
|
23
23
|
"typescript": "^5.4.0",
|
|
24
|
-
"@cef-ai/
|
|
25
|
-
"@cef-ai/
|
|
24
|
+
"@cef-ai/transport": "1.0.0",
|
|
25
|
+
"@cef-ai/widget-runtime": "0.2.0",
|
|
26
|
+
"@cef-ai/agent-sdk": "2.0.0"
|
|
26
27
|
},
|
|
27
28
|
"optionalDependencies": {
|
|
28
29
|
"@cere-ddc-sdk/ddc-client": "^2.16.1"
|
|
@@ -13,13 +13,25 @@ export default defineAgent({
|
|
|
13
13
|
},
|
|
14
14
|
// One cubby (SQLite) for durable per-stream state.
|
|
15
15
|
cubbies: [{ alias: "history", migrations: "./migrations/history" }],
|
|
16
|
-
// One self-contained widget shipped with the agent.
|
|
16
|
+
// One self-contained widget shipped with the agent. `cef dev` serves it
|
|
17
|
+
// locally (browser wallet connect → queries your dev vault); `cef build`
|
|
18
|
+
// bakes the manifest + runtime so the pushed widget works standalone too.
|
|
17
19
|
widgets: [
|
|
18
20
|
{
|
|
19
21
|
id: "hello",
|
|
20
22
|
name: "Hello",
|
|
21
|
-
description: "
|
|
23
|
+
description: "Lists recent messages from the history cubby.",
|
|
22
24
|
cubbyAlias: "history",
|
|
25
|
+
// A "list" widget. The named query below reads the cubby; `app.js` calls
|
|
26
|
+
// `window.WidgetRuntime.query("recent")` and renders the rows.
|
|
27
|
+
kind: "list",
|
|
28
|
+
queries: [
|
|
29
|
+
{
|
|
30
|
+
id: "recent",
|
|
31
|
+
label: "Recent messages",
|
|
32
|
+
sql: "SELECT text, ts FROM messages ORDER BY ts DESC LIMIT 20",
|
|
33
|
+
},
|
|
34
|
+
],
|
|
23
35
|
dir: "./widgets/hello",
|
|
24
36
|
// index.html so the CDN serves it at the widget's directory URL
|
|
25
37
|
// (…/widgets/hello) without naming the file.
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
|
+
"dev": "cef dev",
|
|
7
8
|
"build": "cef build",
|
|
8
9
|
"typegen": "cef typegen",
|
|
9
10
|
"test": "vitest run",
|
|
@@ -12,12 +13,17 @@
|
|
|
12
13
|
"publish": "cef publish"
|
|
13
14
|
},
|
|
14
15
|
"dependencies": {
|
|
15
|
-
"@cef-ai/agent-sdk": "^
|
|
16
|
+
"@cef-ai/agent-sdk": "^2.0.0"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"@cef-ai/cli": "^1.4.0",
|
|
19
|
-
"@cef-ai/testing": "^
|
|
20
|
+
"@cef-ai/testing": "^2.0.0",
|
|
20
21
|
"typescript": "^5.4.0",
|
|
21
22
|
"vitest": "^1.5.0"
|
|
23
|
+
},
|
|
24
|
+
"pnpm": {
|
|
25
|
+
"onlyBuiltDependencies": [
|
|
26
|
+
"better-sqlite3"
|
|
27
|
+
]
|
|
22
28
|
}
|
|
23
29
|
}
|
|
@@ -35,12 +35,17 @@ export default class HelloAgent {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
try {
|
|
38
|
+
// Record time = now. (The runtime hands handlers the published event
|
|
39
|
+
// verbatim — it carries an ISO `timestamp` string, not the `ts: number`
|
|
40
|
+
// the SDK `Event` type currently claims — so `event.ts` is undefined;
|
|
41
|
+
// don't bind a missing value into the NOT NULL `ts` column.)
|
|
42
|
+
const now = Date.now();
|
|
38
43
|
await ctx
|
|
39
44
|
.cubby("history")
|
|
40
45
|
.exec("INSERT INTO messages(id, text, ts) VALUES (?, ?, ?)", [
|
|
41
|
-
|
|
46
|
+
now,
|
|
42
47
|
text,
|
|
43
|
-
|
|
48
|
+
now,
|
|
44
49
|
]);
|
|
45
50
|
} catch (err) {
|
|
46
51
|
// A storage hiccup shouldn't crash the handler; log and still reply.
|
|
@@ -1,8 +1,118 @@
|
|
|
1
|
-
// A
|
|
1
|
+
// A real, self-contained widget (plain HTML + JS — no build step).
|
|
2
2
|
//
|
|
3
|
-
//
|
|
4
|
-
// and
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
// It reads this agent's `history` cubby through the injected
|
|
4
|
+
// `window.WidgetRuntime` and renders the rows. `window.WidgetRuntime` is
|
|
5
|
+
// provided by `@cef-ai/widget-runtime`, whose <script> + manifest are baked
|
|
6
|
+
// into the page head by `cef dev` (local) and `cef build` (production).
|
|
7
|
+
//
|
|
8
|
+
// Run it locally with: cef dev
|
|
9
|
+
// → opens a URL; connect your Cere wallet in the browser; the widget then
|
|
10
|
+
// queries your dev vault. Publish messages (e.g. via the agent) and refresh.
|
|
11
|
+
|
|
12
|
+
(function () {
|
|
13
|
+
var app = document.getElementById("app");
|
|
14
|
+
|
|
15
|
+
function el(tag, attrs, text) {
|
|
16
|
+
var node = document.createElement(tag);
|
|
17
|
+
if (attrs) for (var k in attrs) node.setAttribute(k, attrs[k]);
|
|
18
|
+
if (text != null) node.textContent = text;
|
|
19
|
+
return node;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function clear() {
|
|
23
|
+
while (app.firstChild) app.removeChild(app.firstChild);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function fmtTime(ts) {
|
|
27
|
+
var n = Number(ts);
|
|
28
|
+
if (!isFinite(n)) return String(ts);
|
|
29
|
+
// Rows store epoch millis; fall back gracefully for seconds.
|
|
30
|
+
var d = new Date(n < 1e12 ? n * 1000 : n);
|
|
31
|
+
return isNaN(d.getTime()) ? String(ts) : d.toLocaleString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function renderHeader() {
|
|
35
|
+
app.appendChild(el("h1", null, "{{agentId}}"));
|
|
36
|
+
app.appendChild(el("p", { class: "sub" }, "Recent messages from the history cubby"));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function renderRefresh() {
|
|
40
|
+
var btn = el("button", null, "Refresh");
|
|
41
|
+
btn.addEventListener("click", function () {
|
|
42
|
+
btn.disabled = true;
|
|
43
|
+
btn.textContent = "Refreshing…";
|
|
44
|
+
load(); // re-runs the "recent" query; load() re-renders (button included)
|
|
45
|
+
});
|
|
46
|
+
app.appendChild(btn);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function renderRows(result) {
|
|
50
|
+
clear();
|
|
51
|
+
renderHeader();
|
|
52
|
+
renderRefresh();
|
|
53
|
+
var cols = result.columns || [];
|
|
54
|
+
var textIdx = cols.indexOf("text");
|
|
55
|
+
var tsIdx = cols.indexOf("ts");
|
|
56
|
+
var rows = result.rows || [];
|
|
57
|
+
if (rows.length === 0) {
|
|
58
|
+
app.appendChild(el("p", { class: "muted" }, "No messages yet."));
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
var ul = el("ul");
|
|
62
|
+
rows.forEach(function (row) {
|
|
63
|
+
var li = el("li");
|
|
64
|
+
li.appendChild(el("div", null, textIdx >= 0 ? String(row[textIdx]) : JSON.stringify(row)));
|
|
65
|
+
if (tsIdx >= 0) li.appendChild(el("div", { class: "time" }, fmtTime(row[tsIdx])));
|
|
66
|
+
ul.appendChild(li);
|
|
67
|
+
});
|
|
68
|
+
app.appendChild(ul);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function renderConnect() {
|
|
72
|
+
clear();
|
|
73
|
+
renderHeader();
|
|
74
|
+
app.appendChild(el("p", { class: "muted" }, "Connect your account to load your messages."));
|
|
75
|
+
var btn = el("button", null, "Connect");
|
|
76
|
+
btn.addEventListener("click", function () {
|
|
77
|
+
btn.disabled = true;
|
|
78
|
+
btn.textContent = "Connecting…";
|
|
79
|
+
window.WidgetRuntime
|
|
80
|
+
.connectAgent()
|
|
81
|
+
.then(load)
|
|
82
|
+
.catch(function (err) {
|
|
83
|
+
btn.disabled = false;
|
|
84
|
+
btn.textContent = "Connect";
|
|
85
|
+
renderError(err);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
app.appendChild(btn);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function renderError(err) {
|
|
92
|
+
clear();
|
|
93
|
+
renderHeader();
|
|
94
|
+
app.appendChild(el("p", { class: "error" }, "Error: " + (err && err.message ? err.message : String(err))));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function load() {
|
|
98
|
+
if (!window.WidgetRuntime) {
|
|
99
|
+
renderError(new Error("WidgetRuntime unavailable — open this widget via `cef dev` or the CDN link."));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
window.WidgetRuntime
|
|
103
|
+
.query("recent")
|
|
104
|
+
.then(renderRows)
|
|
105
|
+
.catch(function (err) {
|
|
106
|
+
// The cubby throws AgentNotConnectedError until the user connects the
|
|
107
|
+
// agent to their vault. Offer a Connect button in that case.
|
|
108
|
+
if (err && err.name === "AgentNotConnectedError") renderConnect();
|
|
109
|
+
else renderError(err);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (document.readyState === "loading") {
|
|
114
|
+
document.addEventListener("DOMContentLoaded", load, { once: true });
|
|
115
|
+
} else {
|
|
116
|
+
load();
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<meta charset="utf-8" />
|
|
3
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
3
4
|
<title>Hello — {{agentId}}</title>
|
|
4
|
-
<
|
|
5
|
+
<style>
|
|
6
|
+
body { font: 15px/1.5 system-ui, sans-serif; margin: 0; padding: 24px; color: #111; background: #fafafa; }
|
|
7
|
+
h1 { font-size: 18px; margin: 0 0 4px; }
|
|
8
|
+
.sub { color: #666; margin: 0 0 16px; }
|
|
9
|
+
ul { list-style: none; padding: 0; margin: 0; }
|
|
10
|
+
li { padding: 10px 12px; background: #fff; border: 1px solid #eee; border-radius: 8px; margin-bottom: 8px; }
|
|
11
|
+
.time { color: #888; font-size: 12px; }
|
|
12
|
+
button { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid #ccc; background: #fff; cursor: pointer; }
|
|
13
|
+
.muted { color: #888; }
|
|
14
|
+
.error { color: #b00020; }
|
|
15
|
+
</style>
|
|
16
|
+
<div id="app">Loading…</div>
|
|
17
|
+
<!-- The @cef-ai/widget-runtime <script> + window.WidgetSandbox manifest are
|
|
18
|
+
injected into <head> by `cef dev` / `cef build`, so window.WidgetRuntime is
|
|
19
|
+
ready by the time app.js runs. -->
|
|
5
20
|
<script src="./app.js"></script>
|