akanjs 3.2.0-rc.20 → 3.2.0-rc.21

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/common/index.ts +2 -0
  3. package/common/mcpExposure.ts +12 -2
  4. package/fetch/client/fetchClient.ts +2 -2
  5. package/package.json +1 -1
  6. package/server/mcp/AgentTools.ts +1 -0
  7. package/service/agentLoop/agentLoop.ts +49 -6
  8. package/service/agentLoop/agentLoopTypes.ts +25 -3
  9. package/service/agentLoop/loopCompaction.ts +8 -2
  10. package/service/agentLoop/loopRequest.ts +34 -1
  11. package/service/agentLoop/loopToolkits.ts +107 -0
  12. package/service/predefinedAdaptor/agentTools.adaptor.ts +3 -2
  13. package/service/predefinedAdaptor/llm.adaptor.ts +2 -0
  14. package/signal/index.ts +1 -0
  15. package/signal/mcp/McpDocument.ts +8 -1
  16. package/signal/serializer/fetch.serializer.ts +12 -5
  17. package/signal/slice.ts +22 -19
  18. package/signal/types.ts +17 -5
  19. package/types/common/index.d.ts +1 -1
  20. package/types/common/mcpExposure.d.ts +7 -2
  21. package/types/dictionary/base.dictionary.d.ts +1 -1
  22. package/types/dictionary/dictionary.d.ts +8 -8
  23. package/types/server/logging/rotatingLogWriter.d.ts +1 -1
  24. package/types/service/agentLoop/agentLoopTypes.d.ts +24 -2
  25. package/types/service/agentLoop/loopCompaction.d.ts +1 -1
  26. package/types/service/agentLoop/loopRequest.d.ts +1 -1
  27. package/types/service/agentLoop/loopToolkits.d.ts +14 -0
  28. package/types/service/predefinedAdaptor/agentTools.adaptor.d.ts +3 -2
  29. package/types/service/predefinedAdaptor/llm.adaptor.d.ts +2 -0
  30. package/types/signal/index.d.ts +1 -1
  31. package/types/signal/mcp/McpDocument.d.ts +2 -0
  32. package/types/signal/slice.d.ts +15 -13
  33. package/types/signal/types.d.ts +16 -5
  34. package/types/ui/index.d.ts +1 -1
  35. package/types/vendor/use-agentic/AgentClientTools.d.ts +19 -0
  36. package/types/vendor/use-agentic/index.d.ts +1 -0
  37. package/ui/index.ts +4 -0
  38. package/vendor/use-agentic/AgentClientTools.ts +33 -0
  39. package/vendor/use-agentic/CHANGELOG.md +16 -1
  40. package/vendor/use-agentic/index.ts +1 -0
@@ -1,4 +1,5 @@
1
1
  import type { DefaultPrimitiveName, UnCls } from "akanjs/base";
2
+ import type { McpShelf } from "akanjs/common";
2
3
  import type { AkanJob, ServiceModel } from "akanjs/service";
3
4
  import type { RateLimitBudget } from "./endpointRateLimit.d.ts";
4
5
  import type { GuardCls } from "./guard.d.ts";
@@ -106,8 +107,11 @@ export interface SignalOption<Response = any, Nullable extends boolean = false,
106
107
  /** HTTP verb of a `mutation`, `POST` unless named; every other endpoint type ignores it. */
107
108
  method?: HttpMutationMethod;
108
109
  fileUpload?: boolean;
109
- /** `false` keeps it out of the MCP catalogue (default `true`); curation, not authorization — HTTP still serves it. */
110
- mcp?: boolean;
110
+ /**
111
+ * `false` keeps it out of the MCP catalogue (default `true`), and `"agent"` keeps it off `/mcp` while the in-process
112
+ * agent (`AgentToolsRole`, `agentService.loop`) still lists it; curation, not authorization — HTTP still serves it.
113
+ */
114
+ mcp?: McpShelf;
111
115
  /**
112
116
  * Overrides what the key implies for a `mutation`'s MCP `destructiveHint`: `true` for one no verb gives away, such as
113
117
  * `archiveOrder`, `false` for a `drop…` that loses nothing. `agentService.loop` refuses a destructive tool unless
@@ -140,8 +144,8 @@ interface SerializedSignalOption {
140
144
  guards?: string[];
141
145
  method?: HttpMutationMethod;
142
146
  fileUpload?: boolean;
143
- /** Only ever `false`, when declared. Resolved here because the API explorer holds guard names, not classes. */
144
- mcp?: false;
147
+ /** Only ever `false` or `"agent"`, when declared. Resolved here because the API explorer holds guard names, not classes. */
148
+ mcp?: false | "agent";
145
149
  /** Only ever `false`, when a guard declares `static agents = false` (a person-only act). */
146
150
  agents?: false;
147
151
  }
@@ -207,7 +211,7 @@ export interface SerializedSignal {
207
211
  updateGuards?: string[];
208
212
  removeGuards?: string[];
209
213
  /** Generated CRUD verbs kept off the agent shelf, carried here because `FetchClient.getBaseEndpoint` synthesizes them. */
210
- mcp?: SerializedSignalMcp;
214
+ mcp?: SerializedSignalShelf;
211
215
  /** Generated CRUD verbs the server does not mount at all, so no client synthesizes them. */
212
216
  crud?: SerializedSignalMcp;
213
217
  /** Which generated CRUD verbs a person-only guard protects, by the same verb map; only the `false` keys travel. */
@@ -215,6 +219,13 @@ export interface SerializedSignal {
215
219
  /** The app or lib that registered the signal, first registrant first: an app extending a lib module reads `["shared", "sceny"]`. */
216
220
  origin?: string[];
217
221
  }
222
+ /** The generated CRUD verbs not on `/mcp`, by the same verb map; `"agent"` ones are still listed to the in-process agent. */
223
+ export interface SerializedSignalShelf {
224
+ get?: false | "agent";
225
+ create?: false | "agent";
226
+ update?: false | "agent";
227
+ remove?: false | "agent";
228
+ }
218
229
  /** Keyed by generated verb, mirroring the `guards` map `slice()` takes. The root slice's own flag rides on `slice[""]`. */
219
230
  export interface SerializedSignalMcp {
220
231
  get?: false;
@@ -1,5 +1,5 @@
1
1
  export { type AgentReferenceInput, useAgentReference } from "akanjs/store";
2
- export { AgentProvider, type AgentProviderProps, type AgentRunner, AgentSession, type AgentSessionOptions, type ChatMessage, type CompactOptions, type ContextBlock, httpRunner, type MessageAttachment, type MessageReference, type PublishedTool, Reference, type RunnerEvent, type RunnerRequest, SessionContext, type SessionHistory, type SurfaceView, useAgent, } from "../vendor/use-agentic.d.ts";
2
+ export { type AgentClientToolDefinition, AgentClientTools, AgentProvider, type AgentProviderProps, type AgentRunner, AgentSession, type AgentSessionOptions, type ChatMessage, type CompactOptions, type ContextBlock, httpRunner, type MessageAttachment, type MessageReference, type PublishedTool, Reference, type RunnerEvent, type RunnerRequest, SessionContext, type SessionHistory, type SurfaceView, type ToolApprovalRequest, type ToolRunnerHost, useAgent, } from "../vendor/use-agentic.d.ts";
3
3
  export { Agent } from "./Agent.d.ts";
4
4
  export { type ApprovalProps, DefaultApproval } from "./Agent/Approval.d.ts";
5
5
  export { Chips as AgentAttachments, type ChipsProps as AgentAttachmentsProps } from "./Agent/Attach.d.ts";
@@ -0,0 +1,19 @@
1
+ import { type ToolRunnerHost } from "./ToolRunner.d.ts";
2
+ import type { PublishedTool, SurfaceView, ToolCallRequest, ToolCallResult } from "./types.d.ts";
3
+ /** `readOnly` is always `false`: a screen tool declares no such flag, so a server loop counts every one as a write. */
4
+ export interface AgentClientToolDefinition extends PublishedTool {
5
+ readOnly: false;
6
+ }
7
+ /**
8
+ * A screen's tools lent to an agent loop that runs on the server: `list()` is what that loop takes as its client
9
+ * tools, and `run(call)` answers a call it parked. A call goes through the same `ToolRunner` as the in-page chat, so a
10
+ * `confirm` still asks through `host.approve` (refused without one), a card needs `host.card`, and the answer is
11
+ * clipped and fenced as the chat's would be.
12
+ */
13
+ export declare class AgentClientTools {
14
+ #private;
15
+ constructor(surface?: SurfaceView, host?: ToolRunnerHost);
16
+ list(): AgentClientToolDefinition[];
17
+ /** Never throws: a tool no longer on the screen, a refusal and a failure all come back as the result's `error`. */
18
+ run(call: ToolCallRequest, signal?: AbortSignal): Promise<ToolCallResult>;
19
+ }
@@ -1,5 +1,6 @@
1
1
  export * from "./AgentAbort.d.ts";
2
2
  export * from "./AgentActivity.d.ts";
3
+ export * from "./AgentClientTools.d.ts";
3
4
  export * from "./AgentGate.d.ts";
4
5
  export * from "./Agentic.d.ts";
5
6
  export * from "./AgenticSurface.d.ts";
package/ui/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  export { type AgentReferenceInput, useAgentReference } from "akanjs/store";
3
3
  export {
4
+ type AgentClientToolDefinition,
5
+ AgentClientTools,
4
6
  AgentProvider,
5
7
  type AgentProviderProps,
6
8
  type AgentRunner,
@@ -19,6 +21,8 @@ export {
19
21
  SessionContext,
20
22
  type SessionHistory,
21
23
  type SurfaceView,
24
+ type ToolApprovalRequest,
25
+ type ToolRunnerHost,
22
26
  useAgent,
23
27
  } from "../vendor/use-agentic";
24
28
  export { Agent } from "./Agent";
@@ -0,0 +1,33 @@
1
+ import { AgenticSurface } from "./AgenticSurface";
2
+ import { ToolRunner, type ToolRunnerHost } from "./ToolRunner";
3
+ import type { PublishedTool, SurfaceView, ToolCallRequest, ToolCallResult } from "./types";
4
+
5
+ /** `readOnly` is always `false`: a screen tool declares no such flag, so a server loop counts every one as a write. */
6
+ export interface AgentClientToolDefinition extends PublishedTool {
7
+ readOnly: false;
8
+ }
9
+
10
+ /**
11
+ * A screen's tools lent to an agent loop that runs on the server: `list()` is what that loop takes as its client
12
+ * tools, and `run(call)` answers a call it parked. A call goes through the same `ToolRunner` as the in-page chat, so a
13
+ * `confirm` still asks through `host.approve` (refused without one), a card needs `host.card`, and the answer is
14
+ * clipped and fenced as the chat's would be.
15
+ */
16
+ export class AgentClientTools {
17
+ readonly #surface: SurfaceView;
18
+ readonly #runner: ToolRunner;
19
+
20
+ constructor(surface: SurfaceView = AgenticSurface.shared, host: ToolRunnerHost = {}) {
21
+ this.#surface = surface;
22
+ this.#runner = new ToolRunner(surface, host);
23
+ }
24
+
25
+ list(): AgentClientToolDefinition[] {
26
+ return this.#surface.snapshot().tools.map((tool) => ({ ...tool, readOnly: false }));
27
+ }
28
+
29
+ /** Never throws: a tool no longer on the screen, a refusal and a failure all come back as the result's `error`. */
30
+ async run(call: ToolCallRequest, signal: AbortSignal = new AbortController().signal): Promise<ToolCallResult> {
31
+ return await this.#runner.run(call, signal);
32
+ }
33
+ }
@@ -1,6 +1,21 @@
1
1
  # use-agentic
2
2
 
3
- ## 0.3.1
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - dcddea0: `agentService.loop` can now call the tools of a screen the member has open, without running them on the server. The run parks each such call, the way an approval parks one, until the page answers it.
8
+
9
+ - **Server.** `clientTools` takes the definitions the open page sent over the app's own transport. They are listed beside the endpoint tools.
10
+ - They are client input. Each definition is rebuilt from `name`, `description`, `parameters`, `readOnly` and `needsConfirm`. A name an endpoint tool holds is dropped, in a closed toolkit too, and so is `openToolkit`.
11
+ - `approve` is still asked about each call. With no approver, a definition that is not `readOnly` counts as a write, and a `needsConfirm` one is refused.
12
+ - An allowed call ends the run as `awaiting`, with `client: true` on the event. Calls written before it in the same batch have already run; calls written after it wait for the resume.
13
+ - The run never waits on a socket. The app delivers the call to the page, appends the page's result to the stored messages (or its own error when no page answers), and resumes. A resume without that result parks the call again. A resume without `clientTools` answers it as an unknown tool.
14
+ - **Browser.** `AgentClientTools` is new in `use-agentic` and re-exported from `akanjs/ui`, along with the `ToolRunnerHost` and `ToolApprovalRequest` types.
15
+ - `new AgentClientTools(surface?, host?).list()` gives the open screen's tools in the shape `clientTools` takes, each with `readOnly: false`.
16
+ - `run(call)` answers a parked call through the same `ToolRunner` as the in-page chat. A `confirm` still asks through `host.approve` and is refused without one, a card tool needs `host.card`, and the answer is clipped and fenced as the chat's would be.
17
+
18
+ Both are new and optional, so no upgrade step is needed.
4
19
 
5
20
  ### Patch Changes
6
21
 
@@ -1,5 +1,6 @@
1
1
  export * from "./AgentAbort";
2
2
  export * from "./AgentActivity";
3
+ export * from "./AgentClientTools";
3
4
  export * from "./AgentGate";
4
5
  export * from "./Agentic";
5
6
  export * from "./AgenticSurface";