akanjs 3.3.0-rc.36 → 3.3.0-rc.38
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/CHANGELOG.md +36 -0
- package/common/websocketContract.ts +2 -1
- package/constant/inputParser.ts +7 -0
- package/package.json +1 -1
- package/server/mcp/McpRouter.ts +2 -0
- package/server/routing/apiRouter.ts +4 -1
- package/signal/roomKey.ts +3 -6
- package/store/agent/AgentContext.ts +36 -11
- package/store/agent/StoreSurfaceSource.ts +1 -1
- package/types/store/agent/AgentContext.d.ts +1 -0
- package/types/ui/recipe/badgeRecipe.d.ts +2 -2
- package/types/ui/recipe/buttonRecipe.d.ts +2 -2
- package/types/ui/recipe/inputRecipe.d.ts +2 -2
- package/types/vendor/use-agentic/types.d.ts +2 -0
- package/types/webkit/scrollerTakesDrag.d.ts +3 -0
- package/types/webkit/useCsrRefs.d.ts +1 -1
- package/ui/Agent/agentSessionOf.ts +2 -1
- package/vendor/use-agentic/CHANGELOG.md +20 -0
- package/vendor/use-agentic/types.ts +2 -0
- package/webkit/McpAppAgent.ts +1 -1
- package/webkit/scrollerTakesDrag.ts +31 -0
- package/webkit/useCsrTransitions.ts +20 -9
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
7
|
+
- 800f3ef: fix(agent): a write's change report carries a changed value the way the screen block does
|
|
8
|
+
|
|
9
|
+
After a tool call that changed something, its result lists the resources that changed. Each entry held the whole
|
|
10
|
+
new value, so free text published with `st.expose`, `st.useState` or `useAgentResource`, which the screen block
|
|
11
|
+
leaves out and `readState` answers as page content, reached the model as the app's own data on the first write. An
|
|
12
|
+
entry now keeps what the screen block keeps (a token, a number, a boolean, an ISO timestamp, a short list or object
|
|
13
|
+
of those, and a list scope's ids and token labels) and is marked `withheld: true` when anything was left out;
|
|
14
|
+
`readState(name)` answers the rest. The in-page agent and an MCP App view both report this way.
|
|
15
|
+
|
|
16
|
+
- `AgentContext.reported(view)` returns a surface view whose change report follows the rule.
|
|
17
|
+
- `ResourceDiff` gains the optional `withheld` field.
|
|
18
|
+
|
|
19
|
+
**Upgrading.** No code change is needed: both additions are optional. A model that read a sentence from a tool
|
|
20
|
+
result's `changes` now finds the entry marked `withheld` and reads it with `readState`, which makes the next change
|
|
21
|
+
ask for approval. Where an agent should act on a changed value without that ask, publish an id, a count or an enum
|
|
22
|
+
member, or return the value from the tool itself. A host that builds its own `ToolRunner` over the store surface
|
|
23
|
+
wraps the surface with `AgentContext.reported` to report the same way.
|
|
24
|
+
|
|
7
25
|
- 4a568b2: What an agent turn carries beside the conversation reaches the model as marked data in a user turn, outside the system prompt.
|
|
8
26
|
|
|
9
27
|
- **A turn's `context` is no longer written into the system prompt.** `OpenaiDialect` and `AnthropicLlm` send it as a `<turn-context …>` block that ends the turn's last user-role content, after that turn's tool results: a text block on the Messages API, and on the chat-completions wire the end of the user message the turn closes on, or a user message of its own after tool messages. The block closes on a delimiter chosen so that its content cannot contain it, in any case or width or with characters that do not show between its letters. The delimiter is keyed with a secret of the process: the same text gets the same one in every request a process sends, and another process gives it another. The system prompt is the instructions alone, so it is the same text on every turn of a conversation and a provider's prefix cache keeps it.
|
|
@@ -526,6 +544,14 @@
|
|
|
526
544
|
Such a server handed its own start code on to the worker's command, so the child ran the server's code again with the worker file as an argument, exited with 1 and was started again every second: the worker never ran, and the log showed `[Worker:<name>] WARN exited 1; restarting in 1000ms` over and over. A server started from its file (`bun main.js` with no backends of its own) was not affected. The same command builds the `ops snapshot` and `ops migrate` children, which now leave the start code out as well.
|
|
527
545
|
|
|
528
546
|
- f678e80: The `akanjs` package no longer ships `ARCHITECTURE.md`. The map of the framework's processes and messages is for contributors and stays in the repository (`pkgs/akanjs/ARCHITECTURE.md`); a coding agent building an app read its 11.9 KB from the unpacked package before scaffolding. Verifying a built `akanjs` dist now fails if the file is back in it.
|
|
547
|
+
- cda53a8: fix(signal): a bare value for an array argument is refused over HTTP and WebSocket
|
|
548
|
+
|
|
549
|
+
An endpoint declaring `tags: [String]` and sent `"a"` handed its handler the string `"a"` where it expects a list: the
|
|
550
|
+
primitive parser read the lone value as one item and returned it unwrapped. It now answers 400 `invalidArgument`,
|
|
551
|
+
as a model argument and a filter already did. A repeated query string (`?tags=a`) is always read as a list, so
|
|
552
|
+
`fetch` and the generated client are unaffected; a hand-written body must send `["a"]`. MCP still lifts a lone value
|
|
553
|
+
into a one-item list, since models send a bare value for an array.
|
|
554
|
+
|
|
529
555
|
- af09c4f: `router.backOrFallback()` and `Link.Back` with a `fallback` close a browser tab the app itself opened instead of replacing to the fallback, when there is nothing to go back to. The tab counts as opened by the app when it holds one history entry and has an opener or a same-origin referrer, so a `window.open(href, "_blank", "noopener")` or `target="_blank"` link qualifies. A tab the person opened (a bookmark, a typed URL), one another site opened, and an iOS, Android or desktop shell keep going to the fallback, as does a tab the browser refuses to close.
|
|
530
556
|
- 24315d1: A page asks for its stylesheet before its client chunks. The preload tags for the chunks a page's first screen imports are written at the end of `<head>` instead of at its top, so the stylesheet link comes first; the bootstrap module, the dictionary and the import map stay at the top. On a throttled mobile connection (Lighthouse's slow 4G applied in the browser, over HTTP/2) a 56-chunk page first paints about 160 ms sooner (1.83 s to 1.67 s), and a page whose largest element is a small image shows it about 140 ms sooner; a large image still shares the connection with the chunks and arrives when it did. Every chunk still starts loading with the document, so the page hydrates when it did.
|
|
531
557
|
- 7c4143e: `akanjs/client` exports `nativeKeyboardEasing()`, the curve the keyboard of the shell a page runs in moves on: Android's (`ANDROID_KEYBOARD_ANIMATION_EASING`) in an Android app, iOS's (`IOS_KEYBOARD_ANIMATION_EASING`) anywhere else. `KeyboardRide` already used it; with the name on the barrel, a page's browser code holds the device and keyboard files once, where a build would otherwise have shipped them in two bundles.
|
|
@@ -597,6 +623,11 @@
|
|
|
597
623
|
|
|
598
624
|
The server still fails a render whose stream it has 256 messages of undrained, and since a message now holds up to 32 KB that is about 8 MB of a streamed page where it was about 1 MB; a cached page arrives as one message, so it is never counted.
|
|
599
625
|
|
|
626
|
+
- 040c561: Two cases where a room id did not match the arguments it was built from are fixed.
|
|
627
|
+
|
|
628
|
+
- A publish to a pubsub room whose required `String` argument is `""` now reaches its subscribers. The publisher's side spelled that argument as "no value" while the subscriber had joined with the empty string, so the message went to a room nobody was in. The publisher now reads each argument with the argument's own nullability, the way the client serializes it and the server parses it.
|
|
629
|
+
- An own `__proto__` key in an `Any` room argument or in a live query is part of the room id. It used to be dropped, so two subscriptions whose arguments differed only by that key shared a room.
|
|
630
|
+
|
|
600
631
|
- 5c6d039: A precompressed `.br` or `.gz` asset is now streamed from disk instead of being read whole and copied on every request, which cuts the server CPU per asset request to about a quarter. In production the answer of whether a sidecar exists is remembered per path.
|
|
601
632
|
An existing zero-byte `.br` or `.gz` sibling is skipped, because an empty body is not valid brotli or gzip.
|
|
602
633
|
- b30db27: A signal test's fetch opens its socket at the first subscribe or message, so a pubsub test needs no clone.
|
|
@@ -616,6 +647,11 @@
|
|
|
616
647
|
In development (`NODE_ENV=development`, as under `akan start`), `st.use`, `st.do` and `st.slice` throw on a key no loaded store declares, naming it (`st.do.initMemo is not registered: …`), where they answered `undefined` and the call failed later with `… is not a function`. `in`, `Object.keys` and a symbol key still answer as before, and a production build and a test run are unchanged.
|
|
617
648
|
|
|
618
649
|
- 8f9d432: A page no longer shows a broken character where React's output buffer ends. React writes a page's HTML in 4 KB pieces cut by bytes; when the piece that carried the document's head ended inside a character of more than one byte (Korean, Japanese, an accented letter, an emoji), that character arrived as replacement marks and a stray one closed the document. It depended on where the text fell, so the same page could be right on one request and wrong on the next.
|
|
650
|
+
- fb46b5d: Three malformed requests now get the refusal a well-formed mistake gets, instead of a 500 or a stray answer.
|
|
651
|
+
|
|
652
|
+
- A WebSocket frame whose `key` names a member of `Object.prototype` (`constructor`, `toString`, `valueOf`, `hasOwnProperty`, `__proto__`) answers 404 `routeNotFound`, like any other unregistered key. It used to find that member in the route table and answer 500 with an error log line, `{}` or `"[object Undefined]"`.
|
|
653
|
+
- A WebSocket frame whose `data` is not an array answers 400 `invalidMessage`. A missing or `null` `data` used to answer 500 with an error log line, and a string had its characters read as the arguments.
|
|
654
|
+
- An MCP `POST` whose JSON body is `null` answers 400 with a JSON-RPC `invalidRequest` error instead of throwing.
|
|
619
655
|
|
|
620
656
|
## 3.2.0
|
|
621
657
|
|
|
@@ -68,7 +68,8 @@ const canonicalOf = (value: unknown, holding: Set<object>): unknown => {
|
|
|
68
68
|
if (value instanceof Set) return { "%set": [...value].map((item) => canonicalOf(item, holding)) };
|
|
69
69
|
if (value instanceof RegExp) return { "%regexp": [value.source, value.flags] };
|
|
70
70
|
if (Array.isArray(value)) return value.map((item) => canonicalOf(item, holding) ?? null);
|
|
71
|
-
|
|
71
|
+
|
|
72
|
+
const record: Record<string, unknown> = Object.create(null);
|
|
72
73
|
for (const key of Object.keys(value).sort()) {
|
|
73
74
|
const item = canonicalOf((value as Record<string, unknown>)[key], holding);
|
|
74
75
|
if (item !== undefined) record[key] = item;
|
package/constant/inputParser.ts
CHANGED
|
@@ -52,6 +52,7 @@ export class InputParser {
|
|
|
52
52
|
throw new InvalidInputError(key, null);
|
|
53
53
|
}
|
|
54
54
|
if (PrimitiveRegistry.has(argRef)) {
|
|
55
|
+
InputParser.#requireArrays(value, arrDepth, key);
|
|
55
56
|
const parsed = deserialize(argRef, arrDepth, value, option);
|
|
56
57
|
RequestValue.admit(parsed, key);
|
|
57
58
|
return parsed;
|
|
@@ -59,6 +60,12 @@ export class InputParser {
|
|
|
59
60
|
return InputParser.#walk(value, arrDepth, key, (item, path) => InputParser.#value(argRef, item, path));
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
static #requireArrays(value: unknown, arrDepth: number, path: string) {
|
|
64
|
+
if (!arrDepth) return;
|
|
65
|
+
if (!Array.isArray(value)) throw new InvalidInputError(path, "array");
|
|
66
|
+
for (const [idx, item] of value.entries()) InputParser.#requireArrays(item, arrDepth - 1, `${path}.${idx}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
62
69
|
static #walk(value: unknown, arrDepth: number, path: string, parse: Parse): unknown {
|
|
63
70
|
if (!arrDepth) return parse(value, path);
|
|
64
71
|
if (!Array.isArray(value)) throw new InvalidInputError(path, "array");
|
package/package.json
CHANGED
package/server/mcp/McpRouter.ts
CHANGED
|
@@ -257,6 +257,8 @@ export class McpRouter {
|
|
|
257
257
|
} catch {
|
|
258
258
|
return McpRouter.#error(null, McpErrorCode.parse, "Invalid JSON body.", { status: 400 });
|
|
259
259
|
}
|
|
260
|
+
if (body === null)
|
|
261
|
+
return McpRouter.#error(null, McpErrorCode.invalidRequest, "A JSON-RPC request is an object.", { status: 400 });
|
|
260
262
|
const id = body.id ?? null;
|
|
261
263
|
const method = body.method;
|
|
262
264
|
if (typeof method !== "string")
|
|
@@ -213,7 +213,8 @@ export class ApiRouter {
|
|
|
213
213
|
ws.send(JSON.stringify(websocketHeartbeatContract.makeAck()));
|
|
214
214
|
return;
|
|
215
215
|
}
|
|
216
|
-
|
|
216
|
+
|
|
217
|
+
const wsRoute = Object.hasOwn(wsRoutes, msg.key) ? wsRoutes[msg.key] : undefined;
|
|
217
218
|
if (!wsRoute) {
|
|
218
219
|
|
|
219
220
|
logger.warn(`WebSocket route "${msg.key}" is not registered`);
|
|
@@ -221,6 +222,8 @@ export class ApiRouter {
|
|
|
221
222
|
statusCode: 404,
|
|
222
223
|
});
|
|
223
224
|
}
|
|
225
|
+
if (!Array.isArray(msg.data))
|
|
226
|
+
throw new AkanError("invalidMessage", "Message data is not an array", { statusCode: 400 });
|
|
224
227
|
const eventType =
|
|
225
228
|
typeof msg.subscribe === "boolean" ? (msg.subscribe ? "subscribe" : "unsubscribe") : "message";
|
|
226
229
|
const call = () => wsRoute(ws, msg.data, eventType, { since: msg.since });
|
package/signal/roomKey.ts
CHANGED
|
@@ -25,15 +25,12 @@ export class RoomKey {
|
|
|
25
25
|
|
|
26
26
|
static #asReceived(arg: ArgInfo, value: unknown): unknown {
|
|
27
27
|
try {
|
|
28
|
+
const nullable = arg.option?.nullable;
|
|
28
29
|
const sent = serialize(arg.argRef as ConstantModelRef | PrimitiveScalar, arg.arrDepth, value, "input", {
|
|
29
|
-
nullable
|
|
30
|
+
nullable,
|
|
30
31
|
});
|
|
31
32
|
const wire: unknown = JSON.parse(JSON.stringify(sent) ?? "null");
|
|
32
|
-
return InputParser.parse(arg.argRef as Cls, arg.arrDepth, wire, {
|
|
33
|
-
key: arg.name,
|
|
34
|
-
nullable: true,
|
|
35
|
-
enum: arg.enum,
|
|
36
|
-
});
|
|
33
|
+
return InputParser.parse(arg.argRef as Cls, arg.arrDepth, wire, { key: arg.name, nullable, enum: arg.enum });
|
|
37
34
|
} catch {
|
|
38
35
|
return value;
|
|
39
36
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { STATE_DERIVED_META } from "akanjs/base";
|
|
2
|
-
import type { ContextBlock, PublishedResource, PublishedScope, SurfaceView } from "../../vendor/use-agentic";
|
|
2
|
+
import type { ContextBlock, PublishedResource, PublishedScope, ResourceDiff, SurfaceView } from "../../vendor/use-agentic";
|
|
3
3
|
import { InlineToken } from "../../common/inlineToken";
|
|
4
4
|
import type { StoreInstance } from "../storeInstance";
|
|
5
5
|
import { StoreRegistry } from "../storeRegistry";
|
|
@@ -24,6 +24,17 @@ export class AgentContext {
|
|
|
24
24
|
return AgentInline.path(pathname);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
static reported(view: SurfaceView): SurfaceView {
|
|
28
|
+
return {
|
|
29
|
+
snapshot: () => view.snapshot(),
|
|
30
|
+
tool: (name) => view.tool(name),
|
|
31
|
+
call: (name, args) => view.call(name, args),
|
|
32
|
+
read: (name) => view.read(name),
|
|
33
|
+
diffSince: (before) => AgentContext.#changes(view.diffSince(before), view.snapshot().scopes),
|
|
34
|
+
subscribe: (listener) => view.subscribe(listener),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
readonly #instance: StoreInstance;
|
|
28
39
|
readonly #bridge: AgentBridge;
|
|
29
40
|
|
|
@@ -83,21 +94,35 @@ export class AgentContext {
|
|
|
83
94
|
if (!rows.whole) labelled = false;
|
|
84
95
|
return { ...resource, value: rows.value };
|
|
85
96
|
}
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if (!inline.whole || failed) valued = false;
|
|
90
|
-
return {
|
|
91
|
-
...named,
|
|
92
|
-
...(inline.value !== undefined ? { value: inline.value } : {}),
|
|
93
|
-
...(error !== undefined && !failed ? { error } : {}),
|
|
94
|
-
...(inline.whole && !failed ? {} : { withheld: true }),
|
|
95
|
-
};
|
|
97
|
+
const inlined = AgentContext.#inlined(resource);
|
|
98
|
+
if (inlined.withheld) valued = false;
|
|
99
|
+
return inlined;
|
|
96
100
|
});
|
|
97
101
|
const notes = [...(labelled ? [] : [AgentContext.screenNote]), ...(valued ? [] : [AgentContext.resourceNote])];
|
|
98
102
|
return [{ kind: "screen", scopes: shown, resources: listed, ...(notes.length ? { note: notes.join(" ") } : {}) }];
|
|
99
103
|
}
|
|
100
104
|
|
|
105
|
+
static #changes(diffs: ResourceDiff[], scopes: PublishedScope[]): ResourceDiff[] {
|
|
106
|
+
const lists = new Set(scopes.map((scope) => `${scope.path}.items`));
|
|
107
|
+
return diffs.map((diff) => {
|
|
108
|
+
const rows = lists.has(diff.name) ? AgentContext.#rowsOf(diff.value) : null;
|
|
109
|
+
if (!rows) return AgentContext.#inlined(diff);
|
|
110
|
+
return { ...diff, value: rows.value, ...(rows.whole ? {} : { withheld: true }) };
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
static #inlined<Named extends { name: string; value?: unknown; error?: string }>(resource: Named) {
|
|
115
|
+
const { value, error, ...named } = resource;
|
|
116
|
+
const inline = AgentInline.value(value);
|
|
117
|
+
const failed = error !== undefined && !InlineToken.is(error);
|
|
118
|
+
return {
|
|
119
|
+
...named,
|
|
120
|
+
...(inline.value !== undefined ? { value: inline.value } : {}),
|
|
121
|
+
...(error !== undefined && !failed ? { error } : {}),
|
|
122
|
+
...(inline.whole && !failed ? {} : { withheld: true }),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
101
126
|
static #rowsOf(value: unknown): { value: unknown; whole: boolean } | null {
|
|
102
127
|
if (!value || typeof value !== "object" || !("items" in value) || !Array.isArray(value.items)) return null;
|
|
103
128
|
const items: unknown[] = value.items;
|
|
@@ -247,7 +247,7 @@ export class StoreSurfaceSource implements SurfaceSource {
|
|
|
247
247
|
return {
|
|
248
248
|
name: "readState",
|
|
249
249
|
description:
|
|
250
|
-
"Read one store state key of this page, or one resource by its name. Keys are listed in the state context block and in `withheld` of the route block; a resource the screen block marks `withheld` is read by its name.",
|
|
250
|
+
"Read one store state key of this page, or one resource by its name. Keys are listed in the state context block and in `withheld` of the route block; a resource the screen block or a tool result's `changes` marks `withheld` is read by its name.",
|
|
251
251
|
parameters: {
|
|
252
252
|
type: "object",
|
|
253
253
|
properties: { key: { type: "string" } },
|
|
@@ -10,6 +10,7 @@ export declare class AgentContext {
|
|
|
10
10
|
static of(): AgentContext;
|
|
11
11
|
/** A pathname as the route block carries it: a segment of free text, or one past twelve words, reads `…`. */
|
|
12
12
|
static routePath(pathname: string): string;
|
|
13
|
+
static reported(view: SurfaceView): SurfaceView;
|
|
13
14
|
constructor(instance: StoreInstance, bridge: AgentBridge);
|
|
14
15
|
blocks(surface: SurfaceView, view?: string[]): ContextBlock[];
|
|
15
16
|
}
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export declare const badgeRecipe: (variants?: Omit<({
|
|
3
3
|
size?: "lg" | "md" | "sm" | "xs" | undefined;
|
|
4
4
|
outline?: boolean | undefined;
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "default" | "error" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
|
|
6
6
|
} & {
|
|
7
7
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
8
8
|
className?: never;
|
|
9
9
|
}) | ({
|
|
10
10
|
size?: "lg" | "md" | "sm" | "xs" | undefined;
|
|
11
11
|
outline?: boolean | undefined;
|
|
12
|
-
variant?: "
|
|
12
|
+
variant?: "default" | "error" | "info" | "warning" | "success" | "primary" | "outline" | "secondary" | "accent" | "neutral" | undefined;
|
|
13
13
|
} & {
|
|
14
14
|
class?: never;
|
|
15
15
|
className?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
export declare const buttonRecipe: (variants?: Omit<({
|
|
3
3
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
|
|
4
4
|
outline?: boolean | undefined;
|
|
5
|
-
variant?: "
|
|
5
|
+
variant?: "default" | "link" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
|
|
6
6
|
shape?: "default" | "circle" | "square" | undefined;
|
|
7
7
|
} & {
|
|
8
8
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -10,7 +10,7 @@ export declare const buttonRecipe: (variants?: Omit<({
|
|
|
10
10
|
}) | ({
|
|
11
11
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | "icon" | undefined;
|
|
12
12
|
outline?: boolean | undefined;
|
|
13
|
-
variant?: "
|
|
13
|
+
variant?: "default" | "link" | "info" | "warning" | "success" | "destructive" | "primary" | "outline" | "secondary" | "accent" | "neutral" | "ghost" | undefined;
|
|
14
14
|
shape?: "default" | "circle" | "square" | undefined;
|
|
15
15
|
} & {
|
|
16
16
|
class?: never;
|
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
export declare const inputRecipe: (variants?: Omit<({
|
|
3
3
|
kind?: "field" | "select" | "area" | undefined;
|
|
4
4
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
|
|
5
|
-
tone?: "
|
|
5
|
+
tone?: "default" | "error" | "primary" | undefined;
|
|
6
6
|
} & {
|
|
7
7
|
class?: import("tailwind-variants/lite").ClassValue;
|
|
8
8
|
className?: never;
|
|
9
9
|
}) | ({
|
|
10
10
|
kind?: "field" | "select" | "area" | undefined;
|
|
11
11
|
size?: "xl" | "lg" | "md" | "sm" | "xs" | undefined;
|
|
12
|
-
tone?: "
|
|
12
|
+
tone?: "default" | "error" | "primary" | undefined;
|
|
13
13
|
} & {
|
|
14
14
|
class?: never;
|
|
15
15
|
className?: import("tailwind-variants/lite").ClassValue;
|
|
@@ -131,6 +131,8 @@ export interface ResourceDiff {
|
|
|
131
131
|
value?: unknown;
|
|
132
132
|
error?: string;
|
|
133
133
|
removed?: boolean;
|
|
134
|
+
/** Set by a host that reports less than the whole value, so the model reads the rest through a tool. */
|
|
135
|
+
withheld?: boolean;
|
|
134
136
|
}
|
|
135
137
|
export type ChatRole = "user" | "assistant" | "tool";
|
|
136
138
|
export interface ToolCallRequest {
|
|
@@ -17,8 +17,8 @@ export declare const useCsrRefs: () => {
|
|
|
17
17
|
pageContentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
18
18
|
prevPageContentRef: import("react").RefObject<HTMLDivElement | null>;
|
|
19
19
|
onBack: import("react").RefObject<{
|
|
20
|
-
stack?: (() => Promise<void>) | undefined;
|
|
21
20
|
none?: (() => Promise<void>) | undefined;
|
|
21
|
+
stack?: (() => Promise<void>) | undefined;
|
|
22
22
|
fade?: (() => Promise<void>) | undefined;
|
|
23
23
|
bottomUp?: (() => Promise<void>) | undefined;
|
|
24
24
|
scaleOut?: (() => Promise<void>) | undefined;
|
|
@@ -66,7 +66,8 @@ export const agentSessionOf = ({
|
|
|
66
66
|
const { surface } = ensureStoreSurface();
|
|
67
67
|
const history = sessionHistoryOf(persist, view.join("."));
|
|
68
68
|
const drawing = AgentVisual.sink(visual);
|
|
69
|
-
const
|
|
69
|
+
const shown = AgentContext.reported(sessionView(surface, view, builtins));
|
|
70
|
+
const session = new AgentSession(shown, runner ?? fetchRunner(), {
|
|
70
71
|
buildContext: (scoped) => AgentContext.of().blocks(scoped, view),
|
|
71
72
|
settle: () => ScreenSettle.wait(),
|
|
72
73
|
continueAsk: () => ({ question: l("base.agentContinue"), keep: l("base.agentKeepGoing") }),
|
|
@@ -14,6 +14,26 @@
|
|
|
14
14
|
|
|
15
15
|
**Upgrading.** A host that stages references (`session.stage`, `session.refer`) must render `pendingApproval`, as a host that publishes a `taint: "source"` tool already must: the first change after a mention now waits on it. To keep such changes running as each tool's own `confirm` decides, pass `askAfterUntrusted: false`. Nothing else changes for a host whose context blocks carry no `untrusted` field. A host that already used a field named `untrusted` on a context block for something else must rename it: any value but `false` or `undefined` now marks the block.
|
|
16
16
|
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 800f3ef: fix(agent): a write's change report carries a changed value the way the screen block does
|
|
20
|
+
|
|
21
|
+
After a tool call that changed something, its result lists the resources that changed. Each entry held the whole
|
|
22
|
+
new value, so free text published with `st.expose`, `st.useState` or `useAgentResource`, which the screen block
|
|
23
|
+
leaves out and `readState` answers as page content, reached the model as the app's own data on the first write. An
|
|
24
|
+
entry now keeps what the screen block keeps (a token, a number, a boolean, an ISO timestamp, a short list or object
|
|
25
|
+
of those, and a list scope's ids and token labels) and is marked `withheld: true` when anything was left out;
|
|
26
|
+
`readState(name)` answers the rest. The in-page agent and an MCP App view both report this way.
|
|
27
|
+
|
|
28
|
+
- `AgentContext.reported(view)` returns a surface view whose change report follows the rule.
|
|
29
|
+
- `ResourceDiff` gains the optional `withheld` field.
|
|
30
|
+
|
|
31
|
+
**Upgrading.** No code change is needed: both additions are optional. A model that read a sentence from a tool
|
|
32
|
+
result's `changes` now finds the entry marked `withheld` and reads it with `readState`, which makes the next change
|
|
33
|
+
ask for approval. Where an agent should act on a changed value without that ask, publish an id, a count or an enum
|
|
34
|
+
member, or return the value from the tool itself. A host that builds its own `ToolRunner` over the store surface
|
|
35
|
+
wraps the surface with `AgentContext.reported` to report the same way.
|
|
36
|
+
|
|
17
37
|
## 0.3.0
|
|
18
38
|
|
|
19
39
|
### Minor Changes
|
|
@@ -151,6 +151,8 @@ export interface ResourceDiff {
|
|
|
151
151
|
value?: unknown;
|
|
152
152
|
error?: string;
|
|
153
153
|
removed?: boolean;
|
|
154
|
+
/** Set by a host that reports less than the whole value, so the model reads the rest through a tool. */
|
|
155
|
+
withheld?: boolean;
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
export type ChatRole = "user" | "assistant" | "tool";
|
package/webkit/McpAppAgent.ts
CHANGED
|
@@ -34,7 +34,7 @@ export class McpAppAgent {
|
|
|
34
34
|
constructor(bridge: McpAppBridge, surface = ensureStoreSurface().surface, approvals = McpAppApprovals.shared) {
|
|
35
35
|
this.#bridge = bridge;
|
|
36
36
|
this.#surface = surface;
|
|
37
|
-
this.#runner = new ToolRunner(surface, {
|
|
37
|
+
this.#runner = new ToolRunner(AgentContext.reported(surface), {
|
|
38
38
|
approve: (request, signal) => McpAppAgent.#ask(approvals, request, signal),
|
|
39
39
|
...(AgentConfirm.policy.afterScreenRead ? {} : { askAfterUntrusted: false }),
|
|
40
40
|
settle: () => ScreenSettle.wait(),
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
type DragAxis = "x" | "y";
|
|
2
|
+
|
|
3
|
+
const isScrollable = (overflow: string) => overflow === "auto" || overflow === "scroll";
|
|
4
|
+
|
|
5
|
+
const isReversed = (style: CSSStyleDeclaration, axis: DragAxis) =>
|
|
6
|
+
axis === "y"
|
|
7
|
+
? style.flexDirection === "column-reverse"
|
|
8
|
+
: (style.flexDirection === "row-reverse") !== (style.direction === "rtl");
|
|
9
|
+
|
|
10
|
+
const takes = (node: Element, style: CSSStyleDeclaration, axis: DragAxis, movement: number) => {
|
|
11
|
+
if (!isScrollable(axis === "x" ? style.overflowX : style.overflowY)) return false;
|
|
12
|
+
const span = axis === "x" ? node.scrollWidth - node.clientWidth : node.scrollHeight - node.clientHeight;
|
|
13
|
+
if (span < 1) return false;
|
|
14
|
+
|
|
15
|
+
const offset = Math.abs(axis === "x" ? node.scrollLeft : node.scrollTop);
|
|
16
|
+
const fromStart = isReversed(style, axis) ? span - offset : offset;
|
|
17
|
+
return movement > 0 ? fromStart >= 1 : span - fromStart >= 1;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const scrollerTakesDrag = (
|
|
21
|
+
target: EventTarget | null,
|
|
22
|
+
frame: Element | null,
|
|
23
|
+
axis: DragAxis,
|
|
24
|
+
movement: number,
|
|
25
|
+
) => {
|
|
26
|
+
for (let node = target instanceof Element ? target : null; node; node = node.parentElement) {
|
|
27
|
+
if (takes(node, getComputedStyle(node), axis, movement)) return true;
|
|
28
|
+
if (node === frame) return false;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
};
|
|
@@ -14,6 +14,7 @@ import { clamp } from "akanjs/common";
|
|
|
14
14
|
import { type RefObject, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
15
15
|
import { CsrSlide, type CsrSlideFrame } from "./csrSlide";
|
|
16
16
|
import { isDragLift } from "./isDragLift";
|
|
17
|
+
import { scrollerTakesDrag } from "./scrollerTakesDrag";
|
|
17
18
|
import { STACK_TRANSITION_DURATION_MS } from "./useFrameRuntime";
|
|
18
19
|
|
|
19
20
|
const linearEasing = (t: number) => t;
|
|
@@ -469,7 +470,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
469
470
|
const dragOriginRef = useRef(0);
|
|
470
471
|
|
|
471
472
|
const pageBind = useDrag(
|
|
472
|
-
({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event }) => {
|
|
473
|
+
({ first, last, movement: [mx, my], velocity: [vx], direction: [dx], initial: [ix], cancel, event, target }) => {
|
|
473
474
|
if (first) {
|
|
474
475
|
gestureIntent.current = "pending";
|
|
475
476
|
stackBackConfigRef.current = null;
|
|
@@ -483,13 +484,15 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
483
484
|
if (gestureIntent.current === "pending") {
|
|
484
485
|
const absX = Math.abs(mx);
|
|
485
486
|
const absY = Math.abs(my);
|
|
486
|
-
|
|
487
|
+
const isVertical = absY >= GESTURE_INTENT_THRESHOLD && absY > absX * GESTURE_AXIS_LOCK_RATIO;
|
|
488
|
+
const isHorizontal = absX >= GESTURE_INTENT_THRESHOLD && absX > absY * GESTURE_AXIS_LOCK_RATIO;
|
|
489
|
+
if (isVertical || (isHorizontal && scrollerTakesDrag(target, pageContentRef.current, "x", mx))) {
|
|
487
490
|
gestureIntent.current = "scroll";
|
|
488
491
|
void transUnit.start(transUnitRange[1], { immediate: true });
|
|
489
492
|
cancel();
|
|
490
493
|
return;
|
|
491
494
|
}
|
|
492
|
-
if (
|
|
495
|
+
if (!isHorizontal) return;
|
|
493
496
|
gestureIntent.current = "gesture";
|
|
494
497
|
dragOriginRef.current = holdSlide();
|
|
495
498
|
lockPageScroll();
|
|
@@ -499,6 +502,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
499
502
|
cancel();
|
|
500
503
|
return;
|
|
501
504
|
}
|
|
505
|
+
if (event.cancelable) event.preventDefault();
|
|
502
506
|
const unit = dragOriginRef.current + mx;
|
|
503
507
|
if (unit < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
504
508
|
else if (unit > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
@@ -521,8 +525,8 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
521
525
|
});
|
|
522
526
|
}
|
|
523
527
|
},
|
|
524
|
-
|
|
525
|
-
{ filterTaps: true, pointer: { capture: false } },
|
|
528
|
+
|
|
529
|
+
{ filterTaps: true, pointer: { touch: true, capture: false }, eventOptions: { passive: false } },
|
|
526
530
|
);
|
|
527
531
|
|
|
528
532
|
return {
|
|
@@ -573,7 +577,7 @@ const useStackTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
573
577
|
};
|
|
574
578
|
|
|
575
579
|
const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
576
|
-
const { clientHeight, location, prevLocation, onBack } = routeState;
|
|
580
|
+
const { clientHeight, location, prevLocation, onBack, pageContentRef } = routeState;
|
|
577
581
|
const spring = useSlideSpring(clientHeight);
|
|
578
582
|
const { transUnit, transUnitRange, transProgress } = spring;
|
|
579
583
|
const initThreshold = useMemo(() => Math.floor(clientHeight / 3), [clientHeight]);
|
|
@@ -588,11 +592,12 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
588
592
|
usePlayOnForward(spring, routeState, { duration: 220, easing: linearEasing });
|
|
589
593
|
|
|
590
594
|
const pageBind = useDrag(
|
|
591
|
-
({ first, last, movement: [, my], initial: [, iy], cancel, event }) => {
|
|
592
|
-
if (iy > initThreshold) {
|
|
595
|
+
({ first, last, movement: [, my], initial: [, iy], cancel, event, target }) => {
|
|
596
|
+
if (iy > initThreshold || (first && scrollerTakesDrag(target, pageContentRef.current, "y", my))) {
|
|
593
597
|
cancel();
|
|
594
598
|
return;
|
|
595
599
|
}
|
|
600
|
+
if (event.cancelable) event.preventDefault();
|
|
596
601
|
if (first) void Device.getDevice().hideKeyboard();
|
|
597
602
|
if (my < transUnitRange[1]) void transUnit.start(transUnitRange[1], { immediate: true });
|
|
598
603
|
else if (my > transUnitRange[0]) void transUnit.start(transUnitRange[0], { immediate: true });
|
|
@@ -605,7 +610,13 @@ const useBottomUpTrans = (routeState: RouteState): UseCsrTransition => {
|
|
|
605
610
|
clientRouter.back();
|
|
606
611
|
void clientRouter.navigation().catch(() => transUnit.start(transUnitRange[1]));
|
|
607
612
|
},
|
|
608
|
-
{
|
|
613
|
+
{
|
|
614
|
+
axis: "y",
|
|
615
|
+
filterTaps: true,
|
|
616
|
+
threshold: 10,
|
|
617
|
+
pointer: { touch: true, capture: false },
|
|
618
|
+
eventOptions: { passive: false },
|
|
619
|
+
},
|
|
609
620
|
);
|
|
610
621
|
|
|
611
622
|
return {
|