@cognolo/runtime 0.4.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 +9 -0
- package/README.md +56 -0
- package/dist/agent.d.ts +290 -0
- package/dist/agent.js +245 -0
- package/dist/bundle.d.ts +192 -0
- package/dist/bundle.js +133 -0
- package/dist/cloud.d.ts +301 -0
- package/dist/cloud.js +383 -0
- package/dist/compact.d.ts +58 -0
- package/dist/compact.js +138 -0
- package/dist/context.d.ts +169 -0
- package/dist/context.js +144 -0
- package/dist/gate.d.ts +106 -0
- package/dist/gate.js +82 -0
- package/dist/guard.d.ts +15 -0
- package/dist/guard.js +26 -0
- package/dist/help.d.ts +44 -0
- package/dist/help.js +79 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +25 -0
- package/dist/init-cli.d.ts +40 -0
- package/dist/init-cli.js +317 -0
- package/dist/links.d.ts +39 -0
- package/dist/links.js +89 -0
- package/dist/look.d.ts +462 -0
- package/dist/look.js +362 -0
- package/dist/models.d.ts +79 -0
- package/dist/models.js +145 -0
- package/dist/outside.d.ts +102 -0
- package/dist/outside.js +204 -0
- package/dist/page.d.ts +59 -0
- package/dist/page.js +158 -0
- package/dist/passkey-browser.d.ts +40 -0
- package/dist/passkey-browser.js +48 -0
- package/dist/passkey.d.ts +64 -0
- package/dist/passkey.js +130 -0
- package/dist/pictures.d.ts +23 -0
- package/dist/pictures.js +58 -0
- package/dist/propose.d.ts +36 -0
- package/dist/propose.js +178 -0
- package/dist/rate.d.ts +97 -0
- package/dist/rate.js +147 -0
- package/dist/react/index.d.ts +7 -0
- package/dist/react/index.js +7 -0
- package/dist/react/labels.d.ts +167 -0
- package/dist/react/labels.js +114 -0
- package/dist/react/logic.d.ts +77 -0
- package/dist/react/logic.js +140 -0
- package/dist/react/page-view.d.ts +3 -0
- package/dist/react/page-view.js +308 -0
- package/dist/react/panel.d.ts +179 -0
- package/dist/react/panel.js +749 -0
- package/dist/react/use-chat.d.ts +96 -0
- package/dist/react/use-chat.js +252 -0
- package/dist/research.d.ts +109 -0
- package/dist/research.js +207 -0
- package/dist/route.d.ts +405 -0
- package/dist/route.js +1493 -0
- package/dist/search.d.ts +70 -0
- package/dist/search.js +112 -0
- package/dist/sensitive.d.ts +54 -0
- package/dist/sensitive.js +209 -0
- package/dist/setup.d.ts +93 -0
- package/dist/setup.js +658 -0
- package/dist/store-sql.d.ts +52 -0
- package/dist/store-sql.js +150 -0
- package/dist/store.d.ts +166 -0
- package/dist/store.js +201 -0
- package/dist/text.d.ts +9 -0
- package/dist/text.js +21 -0
- package/dist/tool.d.ts +66 -0
- package/dist/tool.js +36 -0
- package/dist/trust.d.ts +13 -0
- package/dist/trust.js +18 -0
- package/dist/version.d.ts +40 -0
- package/dist/version.js +133 -0
- package/dist/webmcp-browser.d.ts +20 -0
- package/dist/webmcp-browser.js +61 -0
- package/dist/workflow.d.ts +253 -0
- package/dist/workflow.js +310 -0
- package/docs/store.md +330 -0
- package/package.json +71 -0
package/dist/tool.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type Anthropic from "@anthropic-ai/sdk";
|
|
3
|
+
/**
|
|
4
|
+
* read: looks only. write: changes something that can be put back. irreversible: sends, charges or deletes.
|
|
5
|
+
* draft: saves or changes something only the person can see, and nothing else (it contacts no one, deletes nothing, and
|
|
6
|
+
* nothing else acts on it). A draft is only a claim: it is handled exactly as a write until the owner has also confirmed
|
|
7
|
+
* that tool as a draft (the bundle's `drafts`, see `trustPolicy`). Sending a draft is a separate, irreversible tool.
|
|
8
|
+
* A host writing its own policy: anything that is not "read" needs a person unless your policy knows better. Test for
|
|
9
|
+
* `risk === "read"`, never list the risky ones (`needsPerson` does this), or a new level would slip through as "auto".
|
|
10
|
+
*/
|
|
11
|
+
export type Risk = "read" | "draft" | "write" | "irreversible";
|
|
12
|
+
/** For a host's own policy: whether a call of this risk needs a person, before any owner confirmation. Only reads do not. */
|
|
13
|
+
export declare const needsPerson: (risk: Risk) => risk is "draft" | "write" | "irreversible";
|
|
14
|
+
/** Whether a call of this risk may ever run on its own at Automatic. Named, so a new level waits for a person until it is added here. */
|
|
15
|
+
export declare const mayAutoRun: (risk: Risk) => risk is "read" | "draft" | "write";
|
|
16
|
+
/** `threw` is set by the agent when the function crashed, as opposed to answering that it could not or would not. It is how a broken tool is told from one that refused. */
|
|
17
|
+
export type ToolOutcome = {
|
|
18
|
+
ok: true;
|
|
19
|
+
data: unknown;
|
|
20
|
+
} | {
|
|
21
|
+
ok: false;
|
|
22
|
+
error: string;
|
|
23
|
+
threw?: true;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A check that one call stays within one rule. It runs in the host app, in code, so the model cannot talk its way past
|
|
27
|
+
* it. Return why the call breaks the rule, or null when it does not. `rule` is the id of the rule in the context file.
|
|
28
|
+
* (The tool-layer pull request is meant to generate these for rules that restrict something.)
|
|
29
|
+
*/
|
|
30
|
+
export interface Guard<C, I = any> {
|
|
31
|
+
rule: string;
|
|
32
|
+
check: (ctx: C, input: I) => Promise<string | null> | string | null;
|
|
33
|
+
}
|
|
34
|
+
export interface ToolDef<C, S extends z.ZodType = z.ZodType<any>> {
|
|
35
|
+
name: string;
|
|
36
|
+
/** Short label for people, e.g. "Check out a rental". */
|
|
37
|
+
title: string;
|
|
38
|
+
/** What the tool does and when to use it, written for the model. */
|
|
39
|
+
description: string;
|
|
40
|
+
risk: Risk;
|
|
41
|
+
/** Rules this tool is checked against before every call. See `guardedPolicy`. */
|
|
42
|
+
guards?: Guard<C, z.infer<S>>[];
|
|
43
|
+
input: S;
|
|
44
|
+
/** One plain sentence describing exactly what will happen, shown before a person approves a write. */
|
|
45
|
+
preview?: (ctx: C, input: z.infer<S>) => Promise<string> | string;
|
|
46
|
+
run: (ctx: C, input: z.infer<S>) => Promise<ToolOutcome>;
|
|
47
|
+
/**
|
|
48
|
+
* The app's records in a successful result (`data`), for links under the activity line: `{ kind, id, label }`. Runs in
|
|
49
|
+
* the app's code, never the model's; its output goes to no model, audit row or cloud event. A throw shows no links.
|
|
50
|
+
*/
|
|
51
|
+
refs?: (data: any) => {
|
|
52
|
+
kind: string;
|
|
53
|
+
id: string | number;
|
|
54
|
+
label: string;
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
export declare function defineTool<C, S extends z.ZodType>(def: ToolDef<C, S>): ToolDef<C, S>;
|
|
58
|
+
export declare function toApiTool<C>(def: ToolDef<C>): Anthropic.Beta.BetaTool;
|
|
59
|
+
/**
|
|
60
|
+
* What one of the app's own functions handed back, as a tool outcome. A refusal stays a refusal: `{ ok: false }`, or an
|
|
61
|
+
* `error` text without `ok: true`, is reported as not done, so the assistant never tells a person that something worked
|
|
62
|
+
* when the function said no. Anything else is the result. (Generated tool files use this.)
|
|
63
|
+
*/
|
|
64
|
+
export declare function toOutcome(out: unknown): ToolOutcome;
|
|
65
|
+
/** One plain sentence for the person who approves: what is asked for, with the exact values, and nothing else. */
|
|
66
|
+
export declare function previewOf(what: string, input: Record<string, unknown>): string;
|
package/dist/tool.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const needsPerson = (risk) => risk !== "read";
|
|
3
|
+
export const mayAutoRun = (risk) => risk === "read" || risk === "draft" || risk === "write";
|
|
4
|
+
export function defineTool(def) {
|
|
5
|
+
if (!/^[a-z][a-z0-9_]{0,63}$/.test(def.name))
|
|
6
|
+
throw new Error(`Tool name "${def.name}" must be lower_snake_case.`);
|
|
7
|
+
return def;
|
|
8
|
+
}
|
|
9
|
+
const RISK_NOTE = {
|
|
10
|
+
read: "Read-only.",
|
|
11
|
+
draft: "Meant to save a draft that only the person can see, sending nothing. The person may be asked to approve it first.",
|
|
12
|
+
write: "Changes records; the person is asked to approve before it runs.",
|
|
13
|
+
irreversible: "Cannot be undone (sends, charges or deletes); the person is asked to approve before it runs.",
|
|
14
|
+
};
|
|
15
|
+
export function toApiTool(def) {
|
|
16
|
+
const schema = z.toJSONSchema(def.input);
|
|
17
|
+
delete schema.$schema;
|
|
18
|
+
return {
|
|
19
|
+
name: def.name,
|
|
20
|
+
description: `${def.description} ${RISK_NOTE[def.risk]}`,
|
|
21
|
+
input_schema: schema,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export function toOutcome(out) {
|
|
25
|
+
if (out && typeof out === "object" && !Array.isArray(out)) {
|
|
26
|
+
const o = out;
|
|
27
|
+
const said = typeof o.error === "string" && o.error.trim() ? o.error : null;
|
|
28
|
+
if (o.ok === false || (said && o.ok !== true))
|
|
29
|
+
return { ok: false, error: said ?? "It was refused." };
|
|
30
|
+
}
|
|
31
|
+
return { ok: true, data: out ?? null };
|
|
32
|
+
}
|
|
33
|
+
export function previewOf(what, input) {
|
|
34
|
+
const parts = Object.entries(input).filter(([, v]) => v !== undefined).map(([k, v]) => `${k} ${JSON.stringify(v)}`);
|
|
35
|
+
return `${what}: ${parts.join(", ") || "no details"}`;
|
|
36
|
+
}
|
package/dist/trust.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Policy } from "./agent.js";
|
|
2
|
+
import { type ToolDef } from "./tool.js";
|
|
3
|
+
export declare const TRUST_LEVELS: readonly ["off", "watching", "suggest", "automatic"];
|
|
4
|
+
export type TrustLevel = (typeof TRUST_LEVELS)[number];
|
|
5
|
+
/**
|
|
6
|
+
* `levelOf` gives the level for a tool (the host maps tools to skills). No level means "suggest", which is what the default
|
|
7
|
+
* policy does. A value that is not a level (a damaged bundle) is refused, not guessed. Put it under the rule guards:
|
|
8
|
+
* `guardedPolicy({ isOn, base: trustPolicy({ levelOf }) })`, so a broken rule still blocks a call at any level.
|
|
9
|
+
*/
|
|
10
|
+
export declare function trustPolicy<C>(opts: {
|
|
11
|
+
levelOf: (tool: ToolDef<C>) => TrustLevel | undefined; /** The owner's confirmation that this tool only saves a private draft. Missing means none is confirmed. */
|
|
12
|
+
isDraft?: (tool: ToolDef<C>) => boolean;
|
|
13
|
+
}): Policy<C>;
|
package/dist/trust.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { mayAutoRun } from "./tool.js";
|
|
2
|
+
export const TRUST_LEVELS = ["off", "watching", "suggest", "automatic"];
|
|
3
|
+
export function trustPolicy(opts) {
|
|
4
|
+
return (tool) => {
|
|
5
|
+
const level = opts.levelOf(tool) ?? "suggest";
|
|
6
|
+
const read = tool.risk === "read";
|
|
7
|
+
const draft = tool.risk === "draft" && opts.isDraft?.(tool) === true;
|
|
8
|
+
if (level === "off")
|
|
9
|
+
return { deny: "this skill is switched off", own: true };
|
|
10
|
+
if (level === "watching")
|
|
11
|
+
return read ? "auto" : "note";
|
|
12
|
+
if (level === "suggest")
|
|
13
|
+
return read || draft ? "auto" : "confirm";
|
|
14
|
+
if (level === "automatic")
|
|
15
|
+
return mayAutoRun(tool.risk) ? "auto" : "confirm";
|
|
16
|
+
return { deny: "this skill has an unknown trust level", own: true };
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/** The runtime's version, reported to the cloud on every heartbeat. A test keeps it equal to package.json. */
|
|
2
|
+
export declare const RUNTIME_VERSION = "0.4.2";
|
|
3
|
+
/**
|
|
4
|
+
* The deployed git commit: the app's own setting, then `COGNOLO_COMMIT`, then a host's own variable (only a plain git hash
|
|
5
|
+
* counts from those). Null when nothing says, as when running on a developer's machine.
|
|
6
|
+
*/
|
|
7
|
+
export declare function deployedCommit(own?: string, env?: Record<string, string | undefined>): string | null;
|
|
8
|
+
/** The package as an install command names one version of it, from npm: `npm install @cognolo/runtime@0.1.0`. */
|
|
9
|
+
export declare const installSpec: (version: string) => string;
|
|
10
|
+
/**
|
|
11
|
+
* One release, newest first. `steps` are what an app must do beyond the usual update (change the version, run
|
|
12
|
+
* `npx cognolo init` again, build, test in the first environment, then put it live): say so here whenever a release
|
|
13
|
+
* needs a database command, a new setting or a code change, so whoever updates (the owner, a developer or an AI helper)
|
|
14
|
+
* is told. A test keeps the first one equal to RUNTIME_VERSION.
|
|
15
|
+
*/
|
|
16
|
+
export type Release = {
|
|
17
|
+
version: string;
|
|
18
|
+
date: string;
|
|
19
|
+
summary: string;
|
|
20
|
+
steps: string[];
|
|
21
|
+
};
|
|
22
|
+
export declare const RELEASES: Release[];
|
|
23
|
+
export declare const isVersion: (v: string) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* -1, 0 or 1, comparing two versions. A pre-release comes before the same numbers without one (0.2.0-beta < 0.2.0);
|
|
26
|
+
* two pre-releases compare by their tags. Anything that isn't a version counts as older than any version.
|
|
27
|
+
*/
|
|
28
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
29
|
+
/**
|
|
30
|
+
* How to update an app from `from` (the version it runs, or null when unknown, or something that isn't a version) to
|
|
31
|
+
* the newest release: whether it is behind (null when unknown), the releases it would gain (newest first) and every
|
|
32
|
+
* step, the usual ones plus each release's own.
|
|
33
|
+
*/
|
|
34
|
+
export declare function updatePlan(from: string | null, releases?: Release[]): {
|
|
35
|
+
running: string | null;
|
|
36
|
+
latest: string;
|
|
37
|
+
behind: boolean | null;
|
|
38
|
+
gained: Release[];
|
|
39
|
+
steps: string[];
|
|
40
|
+
};
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export const RUNTIME_VERSION = "0.4.2";
|
|
2
|
+
const HOST_COMMIT_VARS = ["VERCEL_GIT_COMMIT_SHA", "RENDER_GIT_COMMIT", "RAILWAY_GIT_COMMIT_SHA", "COMMIT_REF", "CF_PAGES_COMMIT_SHA", "HEROKU_SLUG_COMMIT", "SOURCE_VERSION", "GITHUB_SHA"];
|
|
3
|
+
export function deployedCommit(own, env = typeof process === "undefined" ? {} : process.env) {
|
|
4
|
+
if (own)
|
|
5
|
+
return own;
|
|
6
|
+
if (env.COGNOLO_COMMIT)
|
|
7
|
+
return env.COGNOLO_COMMIT;
|
|
8
|
+
for (const v of HOST_COMMIT_VARS) {
|
|
9
|
+
const c = env[v]?.trim();
|
|
10
|
+
if (c && /^[0-9a-f]{7,40}$/i.test(c))
|
|
11
|
+
return c.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
export const installSpec = (version) => `@cognolo/runtime@${version}`;
|
|
16
|
+
export const RELEASES = [
|
|
17
|
+
{
|
|
18
|
+
version: "0.4.2",
|
|
19
|
+
date: "2026-12-01",
|
|
20
|
+
summary: "The assistant needs its Cognolo settings (COGNOLO_KEY, COGNOLO_URL and COGNOLO_ENV) in every mode: development, a production build on your own computer and a live server. Without them it says it isn't set up. A site that can't reach Cognolo keeps going as before.",
|
|
21
|
+
steps: [
|
|
22
|
+
"Every environment that runs the assistant, your own computer included, needs COGNOLO_KEY, COGNOLO_URL and COGNOLO_ENV. Get a test key from your Cognolo account (the Free plan has one) for development, previews and other test deploys.",
|
|
23
|
+
"Your own tests: run them with NODE_ENV=test (Jest and Vitest set it; Node's own test runner doesn't), or the assistant says it isn't set up. Tests against a running app (`next dev` or `next start` in CI) need a test key set as a CI secret.",
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
version: "0.4.1",
|
|
28
|
+
date: "2026-11-30",
|
|
29
|
+
summary: "A new install now asks for a fresh sign-in before anyone sets up a passkey, for apps that sign in with Clerk (7 or later) or Auth.js, so a script in a person's own browser can't set up their first passkey. `recentSignIn` helps an app write that check itself.",
|
|
30
|
+
steps: [
|
|
31
|
+
"Nothing to do if you already pass `passkey: { freshSignIn }` to `cognoloRoute`.",
|
|
32
|
+
"With Clerk 7 or later, add to lib/cognolo/assistant.ts: `async function signedInJustNow() { const { has } = await auth(); return has({ reverification: \"strict\" }); }`, and `passkey: { freshSignIn: signedInJustNow }` in `cognoloRoute`.",
|
|
33
|
+
"With Auth.js, first record when people sign in, in auth.ts: in the jwt callback `if (user) token.signedInAt = Date.now()` (never copied from an `update()`), in the session callback `session.signedInAt = token.signedInAt`, and `declare module \"next-auth\" { interface Session { signedInAt?: number } }`; with database sessions, a `createdAt` column on Session instead, never anything worked out from `expires`. Then pass a `freshSignIn` that reads `signedInAt` from `auth()` and returns `recentSignIn(signedInAt)` (from `@cognolo/runtime`).",
|
|
34
|
+
],
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
version: "0.4.0",
|
|
38
|
+
date: "2026-11-30",
|
|
39
|
+
summary: "Approvals that need the person: a change that can't be undone (and any the owner ticks) is approved with the person's passkey (fingerprint, face or device PIN), tied to exactly what they approved, once the app has the passkey table and its addresses; a click alone is then not enough. One gate for every way in: the assistant and any outside AI go through the same checks on each call. People's own AI (an agent in the person's browser, through WebMCP) can use the reads the owner ticks, as that person, within limits per person and a pause for the whole environment, and, where the owner allows it, ask for a change that waits in the app's panel until the person approves it with their passkey. All of this is off until the owner switches it on in Cognolo. (0.3.0 was never published: its approvals ship here.)",
|
|
40
|
+
steps: [
|
|
41
|
+
"Add the passkey table: Prisma, add the `CognoloPasskey` model from the storage guide (docs/store.md) and run `npx prisma migrate dev --name cognolo-passkeys`; plain SQL, run `migrations/cognolo-passkeys.sql`; Drizzle, add `schema-passkeys.ts` and include it in drizzle.config. Then pass it to your storage helper: `passkeys: db.cognoloPasskey` (Prisma), `passkeys: \"cognolo_passkeys\"` (SQL) or `passkeys: cognoloPasskeys` (Drizzle). Until then, approving stays a click, and the owner's Safety check says so.",
|
|
42
|
+
"Set `COGNOLO_ORIGINS` to the addresses people open the app at, comma-separated. The first one's site is the passkey site: passkeys work there and on its subdomains only, and any other address is left out for passkeys (the log says so). Left empty, approving stays a click.",
|
|
43
|
+
"Strongly recommended: pass `passkey: { freshSignIn }` to `cognoloRoute`, returning true when the person signed in again just now (Clerk's re-verification, say). It is asked before every passkey is set up. Without it, a script in a person's own browser could set up their first passkey for them outside Production, as a person's first passkey is trusted on first use there; on Production no passkey can be set up, so changes that can't be undone wait until you add it.",
|
|
44
|
+
"Staff who approve changes that can't be undone need a device that can use a passkey; where that isn't possible, the owner can allow click-only for that environment, or for one tool, in Cognolo.",
|
|
45
|
+
"If you draw your own decision buttons without `useCognoloChat`, send the decisions as text with a passkey answer (`approvalChallengeIn` and `passkeyAnswer` from `@cognolo/runtime/react`), or those approvals are refused.",
|
|
46
|
+
"Approving opens the system's passkey prompt, which doesn't work inside another site's frame: open the app in its own tab, not in Replit's preview pane.",
|
|
47
|
+
"Nothing to add for people's own AI until the owner switches it on in Cognolo (Tools). Before they do: return `person` from `open()` (its limits are per person; without it they follow a hash of the scope); a read is offered only when its tool says which records it returns (`refs`), and a change only when its tool has a `preview` that says what will change. Optional: a table for its calls (`CognoloOutsideAction`). With more than one server, on serverless, or before Production, add the two tables for its limits (`CognoloOutsideCount`, `CognoloOutsideSeen`; Prisma only for now): without them each server counts on its own, and a restart clears a pause the limits set. See the storage guide (docs/store.md).",
|
|
48
|
+
"Changes people's own AI asks for need the passkey table, `COGNOLO_ORIGINS` and `freshSignIn`, and are approved only with a passkey set up after a fresh sign-in: one trusted on first use doesn't count for them.",
|
|
49
|
+
"Changes that can't be undone that were already waiting when you update have no passkey link: once passkeys are on, they are refused, and the person asks again.",
|
|
50
|
+
"The owner columns of your conversation and action tables can no longer be named `kind`, `info`, `alg`, `credentialId`, `publicKey`, `credential_id` or `public_key` (the passkey table uses them).",
|
|
51
|
+
"Express apps set up by `npx cognolo init` before 0.4.0: in the assistant's server file, also pass the `origin`, `sec-fetch-site`, `user-agent` and `cookie` headers into the web Request (new set-ups do). Without them, people's own AI is refused.",
|
|
52
|
+
"To remove someone's passkey (a lost device, or one they didn't make), delete its row from the passkey table. They set up a new one next time.",
|
|
53
|
+
"If you call `runTurn` yourself with a conversation the route saved, pass its `passkey` option, or a change that needs one is refused. `gate` and `passkeySetup` are now taken as names in the assistant's POST body.",
|
|
54
|
+
],
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
version: "0.2.2",
|
|
58
|
+
date: "2026-11-24",
|
|
59
|
+
summary: "Page awareness: when the owner switches it on, people can ask about the page they're on and the assistant sees what's on their screen, with secret fields hidden and ID numbers shortened, as in a look-up (free text is checked less strictly than labelled fields). Web research: when the owner switches it on, the assistant can look something up on the public web in a separate search that can't see the conversation or the app, and shows the sites it used under \"From the web\". Cognolo checks every question, and one that holds details from the app's records is shown to the person to approve before it leaves, web pages are information only, and once it has searched, changes wait for a person until they reply; the web text itself isn't sent again in later messages (the assistant's own answer stays). On Anthropic's own API, with your own AI key. Also: a suggestion line no longer goes missing after the owner's rule refused a change (Cognolo's own refusal words aren't treated as records), and when a line can't be offered the person is told so.",
|
|
60
|
+
steps: [
|
|
61
|
+
"Nothing to add for reading the page: the owner turns it on in Cognolo (Setup, What the assistant can take in). Add `data-cognolo-hide` to any part of a page the assistant should never see; to keep it off for some sessions, return false from `pageView` in `cognoloRoute`'s options.",
|
|
62
|
+
"Nothing to add for web research: the owner turns it on in Cognolo (Setup, Searching the web). To keep it off for some sessions, such as an admin viewing as someone else, return false from `research` in `cognoloRoute`'s options. Web search must also be allowed for your organisation in Anthropic's Console.",
|
|
63
|
+
"With one request waiting, its card's own Approve and Decline now send the answer, and `waitingOne` shows on the card itself (with several, the bar under the conversation stays). If you set `waitingOne` in `labels`, check it still reads well on a card.",
|
|
64
|
+
],
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
version: "0.2.1",
|
|
68
|
+
date: "2026-11-24",
|
|
69
|
+
summary: "The assistant knows when each message was sent and the business's own date. Secret fields are hidden from the AI and identifiers (licence, passport, card, bank and tax numbers) shortened to their last 4, and the owner can add fields or let one through. Your plan's limits now hold: questions and changes counted, places per person, Free's 3 saved workflows. A long conversation is shortened for the assistant by code from about 200,000 tokens and stops at 600,000; one tool result is cut to 32,000 characters. Every message checks for new rules; the prompt cache lasts an hour by default (cacheTtl: \"5m\" restores five minutes); a refused AI key is said plainly; the owner can choose the model per environment, unless the app fixes one. When the app turns them on: people can search their own earlier conversations, use the app's site map and help articles, and send pictures. The panel shows when each message was sent, a copy button and a usage ring. Setup: `npx cognolo init` also handles an Express server with a React front end, `npx cognolo key` puts an environment's key into the app's settings from a one-time code, and `npx cognolo propose` opens Cognolo's pull requests from the repository's own workflow. Rules from Cognolo are now made for one app's key, and another key's are refused. The panel mirrors on a right-to-left page, an app can draw its own approve and decline bar (`render.decisionBar`), the badge's \"rules v{n}\" is a label, and a picture over 20 MB is refused. `claudeModel({ host, client })` reaches Claude through the business's own cloud (Claude Platform on AWS, Claude on Google Cloud, Bedrock or Vertex). Drafting a workflow uses Sonnet 5.5, unless the app fixes its model. The owner can pause the assistant in one environment, and people see a short reply instead. A workflow can have look-up steps: one read tool with a fixed input, run without the AI.",
|
|
70
|
+
steps: [
|
|
71
|
+
"On the Free or Starter plan, return `person` from `open()` in your assistant file: the signed-in person's own user id, the same one as the scope. Without it, nobody can use the assistant in a live environment: each person is told to ask the owner for access.",
|
|
72
|
+
"Return `timeZone` from `open()`: the business's time zone, such as Europe/London, so \"today\" means the business's day. Without it the assistant uses UTC.",
|
|
73
|
+
"Check what your tools return: secret fields are now hidden from the AI and identifiers shortened to their last 4, and a change whose input holds a shortened value is refused. To let the assistant read a field in full, the owner adds it in Cognolo (Setup, fields to protect); without Cognolo's cloud, pass `reveal` to `cognoloRoute`.",
|
|
74
|
+
"On the Free plan, if your app saves workflows, call `mayAddWorkflow` in its save code, so the plan's limit of saved workflows holds.",
|
|
75
|
+
"If your app calls `shareWorkflows` with its whole list after each save, pass `replace: true` (or name removed ids in `remove`): it now adds to what's shared instead of replacing it.",
|
|
76
|
+
"On MySQL, change the conversations' `state` and `transcript` columns to LONGTEXT before turning pictures on.",
|
|
77
|
+
"Search, the site map, help articles and pictures don't appear by themselves: add `searchEarlier`, `pages` or `pictures` to `cognoloRoute`, and `audience` to what `open()` returns for help articles. Search and pictures also need the owner's switch in Cognolo.",
|
|
78
|
+
"An Express app you added Cognolo to by hand before 0.2.1, that uses `npx cognolo key`: add `try { process.loadEnvFile(\".env.cognolo\"); } catch {}` near the top of your assistant file, so the app reads the settings the command writes.",
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
version: "0.2.0",
|
|
83
|
+
date: "2026-11-21",
|
|
84
|
+
summary: "Ready for Cognolo's new cloud: checks rules signed the new way (over a hash of the rules, so large rule sets can be signed), and carries Cognolo's two public keys, so COGNOLO_PUBLIC_KEY can be left empty in new setups. Rules signed the old way still work.",
|
|
85
|
+
steps: [
|
|
86
|
+
"If the app sets COGNOLO_PUBLIC_KEY (apps set up before 0.2.0 do), change it when the environment moves to Cognolo's new cloud: either take the `!publicKey` check out of the cloud() function in lib/cognolo/assistant.ts and leave the setting empty, so the runtime's built-in Cognolo keys are used, or set it to those two keys (COGNOLO_PUBLIC_KEYS in @cognolo/runtime). With the old key every rules update is refused, and the assistant can only look things up.",
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
version: "0.1.1",
|
|
91
|
+
date: "2026-11-21",
|
|
92
|
+
summary: "The same as 0.1.0, published again with Cognolo's business contact details. Nothing changes in how it works.",
|
|
93
|
+
steps: [],
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
version: "0.1.0",
|
|
97
|
+
date: "2026-11-20",
|
|
98
|
+
summary: "The first numbered version. Checks for new rules when the assistant is used, follows the page's dark mode, adds the assistant button to the signed-in layout, and reports the deployed commit from common hosts.",
|
|
99
|
+
steps: [],
|
|
100
|
+
},
|
|
101
|
+
];
|
|
102
|
+
const parse = (v) => {
|
|
103
|
+
const m = /^v?(\d+)\.(\d+)(?:\.(\d+))?(?:-([0-9A-Za-z.-]+))?$/.exec(v.trim());
|
|
104
|
+
return m ? { n: [Number(m[1]), Number(m[2]), Number(m[3] ?? 0)], pre: m[4] ?? null } : null;
|
|
105
|
+
};
|
|
106
|
+
export const isVersion = (v) => parse(v) !== null;
|
|
107
|
+
export function compareVersions(a, b) {
|
|
108
|
+
const [x, y] = [parse(a), parse(b)];
|
|
109
|
+
if (!x || !y)
|
|
110
|
+
return x ? 1 : y ? -1 : 0;
|
|
111
|
+
for (let i = 0; i < 3; i++)
|
|
112
|
+
if (x.n[i] !== y.n[i])
|
|
113
|
+
return x.n[i] < y.n[i] ? -1 : 1;
|
|
114
|
+
if (x.pre === y.pre)
|
|
115
|
+
return 0;
|
|
116
|
+
if (x.pre === null || y.pre === null)
|
|
117
|
+
return x.pre === null ? 1 : -1;
|
|
118
|
+
return x.pre < y.pre ? -1 : 1;
|
|
119
|
+
}
|
|
120
|
+
export function updatePlan(from, releases = RELEASES) {
|
|
121
|
+
const latest = releases[0].version;
|
|
122
|
+
const known = from !== null && isVersion(from) ? from : null;
|
|
123
|
+
const gained = releases.filter((r) => known === null || compareVersions(r.version, known) > 0);
|
|
124
|
+
const behind = known === null ? null : gained.length > 0;
|
|
125
|
+
const steps = behind === false ? [] : [
|
|
126
|
+
`Run npm install ${installSpec(latest)} (pnpm add or yarn add if the app uses them). It changes the version in package.json; an app that pinned a git link for @cognolo/runtime gets the npm version instead.`,
|
|
127
|
+
"Run npx cognolo init again. It adds any new file a version needs and never writes over the app's own files. Ignore the commands it lists under 'Then run': those are for a first install (an update never runs the database command again unless a step below says so).",
|
|
128
|
+
...gained.slice().reverse().flatMap((r) => r.steps.map((s) => `${r.version}: ${s}`)),
|
|
129
|
+
"Type-check, build and run the app's tests, then check the assistant opens for a signed-in person in the first environment (usually Dev).",
|
|
130
|
+
"Put it live the usual way, environment by environment. The new version shows on the app's Setup page once it is used.",
|
|
131
|
+
];
|
|
132
|
+
return { running: from, latest, behind, gained, steps };
|
|
133
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One tool offered to people's own AI, as the route lists it: names and words from the app's code, never from the page.
|
|
3
|
+
* `change`: it asks for a change, which waits for the person; otherwise it only looks things up.
|
|
4
|
+
*/
|
|
5
|
+
export interface OwnAiTool {
|
|
6
|
+
name: string;
|
|
7
|
+
title: string;
|
|
8
|
+
description: string;
|
|
9
|
+
inputSchema: Record<string, unknown>;
|
|
10
|
+
change?: true;
|
|
11
|
+
}
|
|
12
|
+
/** Sent on `window` when a change people's own AI asked for is waiting, so the panel opens on it. `detail.id` is its conversation. */
|
|
13
|
+
export declare const OUTSIDE_WAITING_EVENT = "cognolo:outside-waiting";
|
|
14
|
+
/** Calls the app's gate as the signed-in person. The gate's own words come back on a refusal; nothing is thrown. */
|
|
15
|
+
export declare function callGate(endpoint: string, tool: string, input: unknown, signal?: AbortSignal): Promise<unknown>;
|
|
16
|
+
/**
|
|
17
|
+
* Offers `tools` to the person's own AI and returns a function that takes them back. Each look-up is marked read-only, and
|
|
18
|
+
* every tool as returning content from records (which may hold text written by others). Does nothing without WebMCP.
|
|
19
|
+
*/
|
|
20
|
+
export declare function offerToOwnAi(endpoint: string, tools: OwnAiTool[]): () => void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const OUTSIDE_WAITING_EVENT = "cognolo:outside-waiting";
|
|
2
|
+
const NAME = /^[A-Za-z0-9_.-]{1,128}$/;
|
|
3
|
+
function modelContext() {
|
|
4
|
+
const d = typeof document !== "undefined" ? document.modelContext : undefined;
|
|
5
|
+
const n = typeof navigator !== "undefined" ? navigator.modelContext : undefined;
|
|
6
|
+
const mc = d ?? n;
|
|
7
|
+
return mc && typeof mc.registerTool === "function" ? mc : null;
|
|
8
|
+
}
|
|
9
|
+
export async function callGate(endpoint, tool, input, signal) {
|
|
10
|
+
try {
|
|
11
|
+
const r = await fetch(endpoint, { method: "POST", credentials: "same-origin", ...(signal ? { signal } : {}), headers: { "Content-Type": "application/json" }, body: JSON.stringify({ gate: { tool, input } }) });
|
|
12
|
+
const body = (await r.json().catch(() => null));
|
|
13
|
+
if (r.ok && body && typeof body.waiting === "string") {
|
|
14
|
+
try {
|
|
15
|
+
window.dispatchEvent(new CustomEvent(OUTSIDE_WAITING_EVENT, { detail: { id: body.waiting } }));
|
|
16
|
+
}
|
|
17
|
+
catch { }
|
|
18
|
+
return { waiting: body.waiting, note: body.note };
|
|
19
|
+
}
|
|
20
|
+
if (r.ok && body && typeof body.status === "string")
|
|
21
|
+
return body;
|
|
22
|
+
if (r.ok && body && "result" in body)
|
|
23
|
+
return body.result;
|
|
24
|
+
return { error: typeof body?.error === "string" ? body.error : "That didn't work." };
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return { error: "That look-up didn't work." };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function offerToOwnAi(endpoint, tools) {
|
|
31
|
+
const mc = modelContext();
|
|
32
|
+
if (!mc || !tools.length)
|
|
33
|
+
return () => { };
|
|
34
|
+
const stop = new AbortController();
|
|
35
|
+
const names = [];
|
|
36
|
+
for (const t of tools) {
|
|
37
|
+
if (!NAME.test(t.name) || names.includes(t.name))
|
|
38
|
+
continue;
|
|
39
|
+
names.push(t.name);
|
|
40
|
+
const tool = {
|
|
41
|
+
name: t.name,
|
|
42
|
+
title: t.title,
|
|
43
|
+
description: t.description,
|
|
44
|
+
inputSchema: t.inputSchema,
|
|
45
|
+
annotations: { readOnlyHint: !t.change, untrustedContentHint: true },
|
|
46
|
+
execute: async (input, opts) => ({ content: [{ type: "text", text: JSON.stringify(await callGate(endpoint, t.name, input ?? {}, opts?.signal)) }] }),
|
|
47
|
+
};
|
|
48
|
+
try {
|
|
49
|
+
void Promise.resolve(mc.registerTool(tool, { signal: stop.signal })).catch(() => { });
|
|
50
|
+
}
|
|
51
|
+
catch { }
|
|
52
|
+
}
|
|
53
|
+
return () => {
|
|
54
|
+
stop.abort();
|
|
55
|
+
for (const n of names)
|
|
56
|
+
try {
|
|
57
|
+
mc.unregisterTool?.(n);
|
|
58
|
+
}
|
|
59
|
+
catch { }
|
|
60
|
+
};
|
|
61
|
+
}
|