@feltdb/feltkit 0.4.0 → 0.5.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.
Files changed (126) hide show
  1. package/dist/agent-engine.d.ts +93 -0
  2. package/dist/agent-engine.js +40 -0
  3. package/dist/agent-engine.js.map +1 -0
  4. package/dist/app.d.ts +153 -4
  5. package/dist/app.js +134 -25
  6. package/dist/app.js.map +1 -1
  7. package/dist/appboundry/build.d.ts +7 -0
  8. package/dist/appboundry/build.js +4 -1
  9. package/dist/appboundry/build.js.map +1 -1
  10. package/dist/appboundry/guest.js +4 -0
  11. package/dist/appboundry/guest.js.map +1 -1
  12. package/dist/appboundry/host.d.ts +21 -0
  13. package/dist/appboundry/host.js +25 -0
  14. package/dist/appboundry/host.js.map +1 -1
  15. package/dist/appboundry/runtime.js +1 -0
  16. package/dist/appboundry/runtime.js.map +1 -1
  17. package/dist/boards/index.d.ts +1258 -0
  18. package/dist/boards/index.js +1410 -0
  19. package/dist/boards/index.js.map +1 -0
  20. package/dist/boards/model.d.ts +177 -0
  21. package/dist/boards/model.js +177 -0
  22. package/dist/boards/model.js.map +1 -0
  23. package/dist/boards/react.d.ts +18 -0
  24. package/dist/boards/react.js +339 -0
  25. package/dist/boards/react.js.map +1 -0
  26. package/dist/cli/deploy-appboundry-self-hosted.js +2 -2
  27. package/dist/cli/deploy.js +19 -6
  28. package/dist/cli/deploy.js.map +1 -1
  29. package/dist/cli/main.js +70 -5
  30. package/dist/cli/main.js.map +1 -1
  31. package/dist/client/index.d.ts +265 -4
  32. package/dist/client/index.js +170 -3
  33. package/dist/client/index.js.map +1 -1
  34. package/dist/cron.d.ts +18 -0
  35. package/dist/cron.js +67 -0
  36. package/dist/cron.js.map +1 -0
  37. package/dist/dashboard/assets/index-iIj7SL77.js +15 -0
  38. package/dist/dashboard/index.html +1 -1
  39. package/dist/docs.d.ts +1 -1
  40. package/dist/docs.js +3 -0
  41. package/dist/docs.js.map +1 -1
  42. package/dist/eve/index.d.ts +77 -0
  43. package/dist/eve/index.js +128 -0
  44. package/dist/eve/index.js.map +1 -0
  45. package/dist/index.d.ts +7 -2
  46. package/dist/index.js +2 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/native/build.d.ts +112 -0
  49. package/dist/native/build.js +472 -0
  50. package/dist/native/build.js.map +1 -0
  51. package/dist/native/index.d.ts +67 -0
  52. package/dist/native/index.js +113 -0
  53. package/dist/native/index.js.map +1 -0
  54. package/dist/native/instance.d.ts +3 -0
  55. package/dist/native/instance.js +18 -0
  56. package/dist/native/instance.js.map +1 -0
  57. package/dist/react/agent-control.d.ts +2 -0
  58. package/dist/react/agent-control.js +1 -1
  59. package/dist/react/agent-control.js.map +1 -1
  60. package/dist/react/auth.d.ts +15 -1
  61. package/dist/react/auth.js +28 -5
  62. package/dist/react/auth.js.map +1 -1
  63. package/dist/react/hooks.d.ts +88 -0
  64. package/dist/react/hooks.js +188 -0
  65. package/dist/react/hooks.js.map +1 -0
  66. package/dist/react/index.d.ts +5 -88
  67. package/dist/react/index.js +3 -185
  68. package/dist/react/index.js.map +1 -1
  69. package/dist/runtime/agent-control.d.ts +10 -0
  70. package/dist/runtime/agent-control.js +9 -1
  71. package/dist/runtime/agent-control.js.map +1 -1
  72. package/dist/runtime/agent-run.d.ts +166 -0
  73. package/dist/runtime/agent-run.js +431 -0
  74. package/dist/runtime/agent-run.js.map +1 -0
  75. package/dist/runtime/agent.d.ts +158 -1
  76. package/dist/runtime/agent.js +329 -8
  77. package/dist/runtime/agent.js.map +1 -1
  78. package/dist/runtime/assemble.js +14 -1
  79. package/dist/runtime/assemble.js.map +1 -1
  80. package/dist/runtime/authority.d.ts +9 -0
  81. package/dist/runtime/authority.js.map +1 -1
  82. package/dist/runtime/context.d.ts +9 -0
  83. package/dist/runtime/required-capabilities.d.ts +73 -0
  84. package/dist/runtime/required-capabilities.js +69 -0
  85. package/dist/runtime/required-capabilities.js.map +1 -0
  86. package/dist/runtime/runtime.d.ts +70 -1
  87. package/dist/runtime/runtime.js +261 -9
  88. package/dist/runtime/runtime.js.map +1 -1
  89. package/dist/runtime/sessions.d.ts +1 -0
  90. package/dist/runtime/sessions.js +1 -1
  91. package/dist/runtime/sessions.js.map +1 -1
  92. package/dist/runtime/tenancy.d.ts +9 -1
  93. package/dist/runtime/tenancy.js +22 -0
  94. package/dist/runtime/tenancy.js.map +1 -1
  95. package/dist/runtime/transactions.d.ts +3 -1
  96. package/dist/runtime/transactions.js.map +1 -1
  97. package/dist/server/eve.d.ts +287 -0
  98. package/dist/server/eve.js +1071 -0
  99. package/dist/server/eve.js.map +1 -0
  100. package/dist/server/index.d.ts +2 -0
  101. package/dist/server/index.js +58 -1
  102. package/dist/server/index.js.map +1 -1
  103. package/dist/server/mcp.d.ts +7 -7
  104. package/dist/server/project.js +20 -3
  105. package/dist/server/project.js.map +1 -1
  106. package/dist/server/tenancy.d.ts +2 -0
  107. package/dist/server/tenancy.js +31 -1
  108. package/dist/server/tenancy.js.map +1 -1
  109. package/dist/testing/index.d.ts +1 -4
  110. package/dist/testing/index.js.map +1 -1
  111. package/docs/AGENT-CONTROL.md +36 -0
  112. package/docs/APPBOUNDRY.md +36 -0
  113. package/docs/AUTH.md +2 -0
  114. package/docs/EVE-COMPOSITION.md +75 -0
  115. package/docs/NATIVE-AGENTS.md +353 -0
  116. package/docs/NATIVE.md +137 -0
  117. package/docs/README.md +5 -2
  118. package/package.json +33 -7
  119. package/skills/.claude-plugin/marketplace.json +1 -1
  120. package/skills/.claude-plugin/plugin.json +1 -1
  121. package/skills/feltkit-agent/SKILL.md +1 -1
  122. package/skills/feltkit-build/SKILL.md +1 -1
  123. package/skills/feltkit-data/SKILL.md +1 -1
  124. package/skills/feltkit-operations/SKILL.md +1 -1
  125. package/skills/feltkit-services/SKILL.md +1 -1
  126. package/dist/dashboard/assets/index-BhxrvY37.js +0 -15
@@ -0,0 +1,93 @@
1
+ /**
2
+ * The execution-engine boundary for reasoning agents (`app.agent` with `instructions`).
3
+ *
4
+ * FeltKit owns everything durable about a run: its task, its transcript (one FeltDB memory per message,
5
+ * written once), its authority, every tool call (an AppPort proposal: authorized, approval-gated,
6
+ * idempotent per call), and its evidence. An engine owns one decision: given the instructions, the
7
+ * transcript so far and the tools the agent may use now, what is the agent's next turn (text, and the
8
+ * tool calls it asks for)? It never reads or writes state, never holds a credential, and never runs a
9
+ * tool. So a run resumes after a restart from FeltDB alone, whatever engine produced its earlier turns,
10
+ * and engines (a model, a local model, rules, a future external engine) replace each other without
11
+ * changing the agent's definition.
12
+ */
13
+ import type { GenerationMessage, GenerationResult, ToolCall, ToolDefinition } from "./runtime/generation.js";
14
+ export type { GenerationMessage as AgentMessage, ToolCall as AgentToolCall } from "./runtime/generation.js";
15
+ /** A tool the agent may use in this turn: an AppPort capability it declared, that its roles allow now. */
16
+ export interface AgentToolSpec extends ToolDefinition {
17
+ /** "observation" runs at once; "consequential" waits for a person's approval unless the agent declares it autonomous. */
18
+ effect: "observation" | "consequential";
19
+ /** True when the agent's definition lets it run this consequential tool without a person's approval. */
20
+ autonomous?: boolean;
21
+ }
22
+ /** What the engine is asked for: the next turn. */
23
+ export interface AgentTurnRequest {
24
+ readonly agent: {
25
+ readonly name: string;
26
+ readonly version: string;
27
+ };
28
+ readonly instructions: string;
29
+ /** Every message so far, from durable state: the input, earlier turns, tool results, people's updates. */
30
+ readonly transcript: readonly GenerationMessage[];
31
+ readonly tools: readonly AgentToolSpec[];
32
+ /** The output contract (JSON Schema), when the agent declares one: the final answer must be JSON matching it. */
33
+ readonly output?: Record<string, unknown>;
34
+ /** Aborted when this attempt must stop (it lost the run to another attempt): stop the model call. */
35
+ readonly signal: AbortSignal;
36
+ /**
37
+ * The environment's model, through FeltKit: resolved from the environment's configuration (never from
38
+ * the agent's definition), credentials kept server-side, every generation recorded as evidence on the
39
+ * run's task. Throws a CONFIGURATION error that says what to set when no model is configured.
40
+ */
41
+ readonly model: {
42
+ generate(request: {
43
+ messages: GenerationMessage[];
44
+ tools?: ToolDefinition[];
45
+ maxTokens?: number;
46
+ temperature?: number;
47
+ }): Promise<GenerationResult & {
48
+ generationId: string;
49
+ memoryId: string;
50
+ receipt: {
51
+ provider: string;
52
+ model: string;
53
+ };
54
+ }>;
55
+ };
56
+ }
57
+ /** The engine's answer: the agent's next turn. No tool calls ends the run with `text` as its output. */
58
+ export interface AgentTurn {
59
+ text: string;
60
+ toolCalls: ToolCall[];
61
+ /** The recorded generation this turn came from, when a model produced it (its id and FeltDB memory id). */
62
+ generation?: {
63
+ generationId: string;
64
+ memoryId: string;
65
+ };
66
+ /** The model that decided, when one did: recorded on each proposal as `model:<provider>/<model>`. */
67
+ decidedBy?: {
68
+ provider: string;
69
+ model: string;
70
+ };
71
+ }
72
+ /** An execution engine: decides an agent's next turn. Stateless between calls. */
73
+ export interface AgentEngine {
74
+ /** Recorded on the run and its evidence ("feltkit.model", "rules:triage", …). */
75
+ readonly id: string;
76
+ /** Whether the engine needs the environment's model; a run without one fails clearly before it starts. */
77
+ readonly usesModel: boolean;
78
+ next(request: AgentTurnRequest): Promise<AgentTurn>;
79
+ }
80
+ /**
81
+ * The default engine: one generation with the environment's model per turn, the instructions as the
82
+ * system message, the agent's tools offered as the model's tools.
83
+ */
84
+ export declare function modelEngine(options?: {
85
+ maxTokens?: number;
86
+ temperature?: number;
87
+ }): AgentEngine;
88
+ /**
89
+ * A deterministic engine: `decide` maps the transcript to the next turn with ordinary code, no model.
90
+ * Same lifecycle, authority, approvals and evidence as a model-driven agent; useful for rule-based
91
+ * agents and for testing an agent's tools and approvals without a provider.
92
+ */
93
+ export declare function rulesEngine(id: string, decide: (request: Omit<AgentTurnRequest, "model">) => AgentTurn | Promise<AgentTurn>): AgentEngine;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * The default engine: one generation with the environment's model per turn, the instructions as the
3
+ * system message, the agent's tools offered as the model's tools.
4
+ */
5
+ export function modelEngine(options = {}) {
6
+ return Object.freeze({
7
+ id: "feltkit.model",
8
+ usesModel: true,
9
+ async next(request) {
10
+ const g = await request.model.generate({
11
+ messages: [{ role: "system", content: request.output ? `${request.instructions}\n\nWhen you are done, answer with only a JSON value matching this JSON Schema (no other text):\n${JSON.stringify(request.output)}` : request.instructions }, ...request.transcript],
12
+ ...(request.tools.length ? { tools: request.tools.map((t) => ({ name: t.name, ...(t.description ? { description: t.description } : {}), inputSchema: t.inputSchema })) } : {}),
13
+ ...(options.maxTokens !== undefined ? { maxTokens: options.maxTokens } : {}),
14
+ ...(options.temperature !== undefined ? { temperature: options.temperature } : {}),
15
+ });
16
+ return { text: g.text, toolCalls: g.toolCalls, generation: { generationId: g.generationId, memoryId: g.memoryId }, decidedBy: { provider: g.receipt.provider, model: g.receipt.model } };
17
+ },
18
+ });
19
+ }
20
+ /**
21
+ * A deterministic engine: `decide` maps the transcript to the next turn with ordinary code, no model.
22
+ * Same lifecycle, authority, approvals and evidence as a model-driven agent; useful for rule-based
23
+ * agents and for testing an agent's tools and approvals without a provider.
24
+ */
25
+ export function rulesEngine(id, decide) {
26
+ if (typeof id !== "string" || !/^[a-z][a-z0-9._:-]{0,62}$/.test(id))
27
+ throw new TypeError(`rulesEngine("${id}"): the id is a lowercase letter, then letters, digits, ".", "_", ":" or "-".`);
28
+ if (typeof decide !== "function")
29
+ throw new TypeError(`rulesEngine("${id}") needs a decide function.`);
30
+ return Object.freeze({
31
+ id: `rules:${id}`,
32
+ usesModel: false,
33
+ async next(request) {
34
+ const { model: _model, ...rest } = request;
35
+ const turn = await decide(rest);
36
+ return { text: String(turn?.text ?? ""), toolCalls: Array.isArray(turn?.toolCalls) ? turn.toolCalls : [] };
37
+ },
38
+ });
39
+ }
40
+ //# sourceMappingURL=agent-engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-engine.js","sourceRoot":"","sources":["../src/agent-engine.ts"],"names":[],"mappings":"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"}
package/dist/app.d.ts CHANGED
@@ -166,6 +166,44 @@ export interface OidcProvider extends ProviderClient {
166
166
  /** Default ["openid", "email", "profile"]. */
167
167
  scopes?: string[];
168
168
  }
169
+ /**
170
+ * An agent that runs on the agent runtime from its own project (`agent/`), built and supervised by FeltKit:
171
+ * `app.agent(name, { project: ".", roles, tenantRole, capabilities })`. (`feltkit({ eve })` is the same declaration.)
172
+ */
173
+ export interface ProjectAgentConfig {
174
+ /** The agent's project directory (it holds `agent/` and installs the agent runtime), relative to the application. */
175
+ project: string;
176
+ /** Application roles the agent's worker holds in a workspace. No more than the person who activates it holds. */
177
+ roles: readonly string[];
178
+ /** The workspace role the agent joins a workspace with (`auth.tenant.roles`). Required when the app has workspaces. */
179
+ tenantRole?: string;
180
+ /** The capabilities the agent may be granted: exact names or `namespace.*`. A person grants only those they may call. */
181
+ capabilities: readonly string[];
182
+ /** Shown as the agent's name. */
183
+ displayName?: string;
184
+ /** How long a person's work grant to the agent lasts. Default 24 h. */
185
+ grantTtlMs?: number;
186
+ }
187
+ /** A project agent, as `app.agent` returns it. */
188
+ export interface ProjectAgentDefinition {
189
+ readonly name: string;
190
+ readonly project: string;
191
+ }
192
+ /** One agent of the application that runs on the agent runtime (`app.agent(name, { project })` or `feltkit({ eve })`). */
193
+ export interface EveAgentDeclaration {
194
+ /** The eve project directory (it holds `agent/` and installs `eve`), relative to the application. Default ".". */
195
+ root?: string;
196
+ /** Application roles the agent's worker holds in a workspace. No more than the person who activates it holds. */
197
+ roles: readonly string[];
198
+ /** The workspace role the agent joins a workspace with (`auth.tenant.roles`). Required when the app has workspaces. */
199
+ tenantRole?: string;
200
+ /** The capabilities the agent may be granted: exact names or `namespace.*`. A person grants only those they may call. */
201
+ capabilities: readonly string[];
202
+ /** Shown as the agent's name. */
203
+ displayName?: string;
204
+ /** How long a person's work grant to the agent lasts. Default 24 h. */
205
+ grantTtlMs?: number;
206
+ }
169
207
  /**
170
208
  * Sign in with Google or GitHub through FeltKit's broker instead of your own provider client: nothing to register and no
171
209
  * client secret to keep. The broker signs the person in and hands this app a signed statement of who they are (the
@@ -389,6 +427,15 @@ export interface FeltKitOptions {
389
427
  * docs/COMPONENTS.md.
390
428
  */
391
429
  components?: Record<string, import("./component.js").ComponentDeclaration>;
430
+ /**
431
+ * eve agents this application runs (`@appport/eve`), each from its own eve project directory. FeltKit builds
432
+ * and supervises each as a child process on a loopback port, with its sessions in FeltDB (the FeltDB World,
433
+ * `@appport/eve-world-feltdb`, under this environment's state), and forwards `/eve/<name>/…` to it only for
434
+ * signed-in people, with a short-lived signed identity (person, workspace, roles, work grant). The agent acts
435
+ * on the application only through its published capabilities, as a worker under the person's work grant;
436
+ * approvals are AppPort approvals of one exact call. See docs/EVE-COMPOSITION.md.
437
+ */
438
+ eve?: Record<string, EveAgentDeclaration>;
392
439
  /**
393
440
  * AppPort providers this application uses: `{ <name>: { provider, config?, credentials? } }`, where `provider` is
394
441
  * the `defineProvider(...)` a package exports. Their capabilities join the application's own, authorized by its
@@ -396,6 +443,12 @@ export interface FeltKitOptions {
396
443
  * runtime/providers.ts and docs/PROVIDERS.md.
397
444
  */
398
445
  providers?: Record<string, import("./providers.js").ProviderDeclaration>;
446
+ /**
447
+ * Capabilities of other applications this one needs, by AppPort name and integer version range. A declaration
448
+ * names no provider, endpoint or credential: an AppBoundry host binds each to a provider and grant, and the code
449
+ * reaches it through `ctx.capabilities`. Emitted as the artifact manifest's `requires` (host interface capabilities@1).
450
+ */
451
+ requires?: readonly import("./runtime/required-capabilities.js").CapabilityRequirement[];
399
452
  /**
400
453
  * Quotas for every function of the application (K3), on top of each function's own `quota`: at most
401
454
  * `limit` calls in any `windowMs`, counted per principal across all functions ("principal") or for
@@ -873,9 +926,78 @@ export interface AgentConfig<Input extends Record<string, unknown> = Record<stri
873
926
  maxAttempts?: number;
874
927
  backoffMs?: number;
875
928
  };
876
- /** How long a run holds its claim before the services worker treats it as abandoned and runs it again (default 300 000 ms). */
929
+ /**
930
+ * How long a run holds its claim before the services worker treats it as abandoned and runs it again (default
931
+ * 300 000 ms; 120 000 ms for a reasoning agent, whose run lease is half of it, renewed while an attempt works:
932
+ * a process that stops is taken over within about this long).
933
+ */
877
934
  leaseMs?: number;
878
- handler: (ctx: AgentCtx, input: Input) => unknown;
935
+ /** A deterministic agent: code that runs as a mutation, in one transaction. Exactly one of `handler` and `instructions`. */
936
+ handler?: (ctx: AgentCtx, input: Input) => unknown;
937
+ /**
938
+ * A reasoning agent: FeltKit runs it turn by turn. Each turn the engine (default: the environment's model)
939
+ * reads the durable transcript and answers with text and tool calls; FeltKit runs each tool call as an
940
+ * AppPort proposal by the agent (observations at once, consequential calls after a person approves them,
941
+ * unless listed in `autonomous`), records the result, and continues until a turn asks for no tool. The
942
+ * run's task, transcript, generations and actions are FeltDB state: a run resumes after a restart, and a
943
+ * run waiting for an approval resumes when a person decides. Its roles must grant `feltkit.agent.write`
944
+ * (checked when the runtime starts).
945
+ */
946
+ instructions?: string;
947
+ /** The capabilities a reasoning agent may use, by definition (published functions of this app). Its roles must also allow each one. */
948
+ tools?: readonly FunctionDefinition<any, any, any>[];
949
+ /**
950
+ * Consequential tools (a subset of `tools`) the agent runs without a person's approval: the application's
951
+ * explicit policy, recorded on each action as `policy:agent/<name>`. Never applies to a function declared
952
+ * `approval: "required"`, which still waits for a person.
953
+ */
954
+ autonomous?: readonly FunctionDefinition<any, any, any>[];
955
+ /** Input contract of a reasoning agent's runs (validated before a run starts). Default: any object. */
956
+ input?: ShapeInput;
957
+ /**
958
+ * Budgets of one reasoning run, enforced by FeltKit from durable records across every attempt (a restart does
959
+ * not reset them). Exhausting one stops the run (its task is cancelled with the budget as the reason).
960
+ * maxTurns the agent's turns (default 8, at most 100)
961
+ * maxToolCalls tool results (default 20, at most 500)
962
+ * maxGenerations model generations, failed ones included (default 2 × maxTurns)
963
+ * maxActiveMs execution time, summed over attempts; waiting for a person does not count (default 10 min)
964
+ * maxTokens input + output tokens the provider reported; generations that report none are not counted
965
+ * (and the stop says so). Optional: not every provider reports usage.
966
+ * concurrency runs of this agent executing at once in one process (default 4); more wait their turn
967
+ */
968
+ limits?: {
969
+ maxTurns?: number;
970
+ maxToolCalls?: number;
971
+ maxGenerations?: number;
972
+ maxActiveMs?: number;
973
+ maxTokens?: number;
974
+ concurrency?: number;
975
+ };
976
+ /**
977
+ * The output contract: the final answer must be JSON matching it (a schema from `s`, or a shape like `args`).
978
+ * An answer that does not match is never the run's result: the agent is told why and answers again, within
979
+ * maxTurns. The validated value is the run's output (`result.run.output`, `<task>.output`).
980
+ */
981
+ output?: ShapeInput | import("@appport/sdk").Schema;
982
+ /** Who decides each turn (default `modelEngine()`: the environment's model). See `@feltdb/feltkit` AgentEngine. */
983
+ engine?: import("./agent-engine.js").AgentEngine;
984
+ }
985
+ /** A reasoning agent's definition, as FeltKit runs it. */
986
+ export interface ReasoningDefinition {
987
+ readonly instructions: string;
988
+ /** Capability names. */
989
+ readonly tools: readonly string[];
990
+ readonly autonomous: readonly string[];
991
+ readonly limits: {
992
+ readonly maxTurns: number;
993
+ readonly maxToolCalls: number;
994
+ readonly maxGenerations: number;
995
+ readonly maxActiveMs: number;
996
+ readonly maxTokens?: number;
997
+ readonly concurrency: number;
998
+ };
999
+ readonly output?: import("@appport/sdk").Schema;
1000
+ readonly engine: import("./agent-engine.js").AgentEngine;
879
1001
  }
880
1002
  export interface AgentDefinition {
881
1003
  readonly name: string;
@@ -892,9 +1014,17 @@ export interface AgentDefinition {
892
1014
  readonly backoffMs: number;
893
1015
  };
894
1016
  readonly leaseMs: number;
895
- /** The handler as a mutation (internal: run only by the runtime, under the name `agent/<name>`). */
896
- readonly function: FunctionDefinition<"mutation">;
1017
+ /** The handler as a mutation, or a reasoning agent's run as an action (internal: run only by the runtime, under the name `agent/<name>`). */
1018
+ readonly function: FunctionDefinition<"mutation"> | FunctionDefinition<"action">;
1019
+ /** Present for a reasoning agent (`instructions`). */
1020
+ readonly reasoning?: ReasoningDefinition;
897
1021
  }
1022
+ /** The outbox claim of one reasoning attempt. Short: the run's own lease (renewed while it works) keeps a live attempt's run from being taken over. */
1023
+ export declare const AGENT_REASONING_LEASE_MS = 120000;
1024
+ export declare const AGENT_MAX_TURNS = 100;
1025
+ export declare const AGENT_MAX_TOOL_CALLS = 500;
1026
+ /** The internal hook a reasoning agent's action calls: the runtime puts its run driver here on the action's ctx. */
1027
+ export declare const AGENT_RUN: unique symbol;
898
1028
  export declare const AGENT_DEFAULT_ATTEMPTS = 5;
899
1029
  export declare const AGENT_DEFAULT_BACKOFF_MS = 1000;
900
1030
  export declare const AGENT_MAX_BACKOFF_MS = 600000;
@@ -943,6 +1073,8 @@ export declare class FeltKitApp<O extends FeltKitOptions = FeltKitOptions> {
943
1073
  readonly migrations: MigrationDefinition[];
944
1074
  /** Application agents (see `agent`), by name. */
945
1075
  readonly agents: Map<string, AgentDefinition>;
1076
+ /** Agents that run on the agent runtime from their own project (`app.agent(name, { project })`), by name. */
1077
+ readonly projectAgents: Map<string, EveAgentDeclaration>;
946
1078
  /** Declared policies (`app.policy`), in declaration order. Resolved to function names at assembly. */
947
1079
  readonly policies: PolicyRule[];
948
1080
  constructor(options: O);
@@ -1019,7 +1151,11 @@ export declare class FeltKitApp<O extends FeltKitOptions = FeltKitOptions> {
1019
1151
  *
1020
1152
  * See docs/TRANSACTIONS.md ("Application agents"). Not available in an AppBoundry artifact.
1021
1153
  */
1154
+ agent(name: string, config: ProjectAgentConfig): ProjectAgentDefinition;
1022
1155
  agent<Input extends Record<string, unknown> = Record<string, unknown>>(name: string, config: AgentConfig<Input>): AgentDefinition;
1156
+ private projectAgent;
1157
+ private inProcessAgent;
1158
+ private checkReasoning;
1023
1159
  /**
1024
1160
  * Declare a policy: who may call which functions, on which resource, under which conditions
1025
1161
  * (see PolicyRule and src/policy.ts for the semantics). Deterministic, enforced at the execution
@@ -1157,6 +1293,17 @@ export type FunctionVisibility = "public" | "worker" | "service" | "internal";
1157
1293
  export declare function feltkit<const O extends FeltKitOptions>(options: O): FeltKitApp<O>;
1158
1294
  export declare function isFeltKitApp(value: unknown): value is FeltKitApp;
1159
1295
  export declare function isFunctionDefinition(value: unknown): value is FunctionDefinition;
1296
+ /**
1297
+ * A function group: one export whose function members are named `<module>:<member>`, as if each
1298
+ * were exported on its own (a capability built from the public API, such as Boards, ships its
1299
+ * functions this way). Members that are not functions (collections, helpers) are ignored.
1300
+ */
1301
+ export declare const FUNCTION_GROUP: unique symbol;
1302
+ export type FunctionGroup<T extends object> = T & {
1303
+ readonly $functionGroup: true;
1304
+ };
1305
+ export declare function functionGroup<T extends object>(members: T): FunctionGroup<T>;
1306
+ export declare function isFunctionGroup(value: unknown): value is Record<string, unknown>;
1160
1307
  export declare function isEventDefinition(value: unknown): value is EventDefinition;
1161
1308
  /** Marks a collection declared with app.auditTrail (its record() allocates a sequence: transactions@1 in an artifact). */
1162
1309
  export declare const AUDIT_TRAIL: unique symbol;
@@ -1168,4 +1315,6 @@ export declare function isCollectionDefinition(value: unknown): value is Collect
1168
1315
  * letter (more dotted segments are allowed). No hyphens, underscores, or capitals.
1169
1316
  */
1170
1317
  export declare function capabilityNameSuggestion(name: string): string;
1318
+ /** Every agent of the application that runs on the agent runtime: `app.agent(name, { project })` and `feltkit({ eve })`. */
1319
+ export declare function projectAgentsOf(app: FeltKitApp): Record<string, EveAgentDeclaration>;
1171
1320
  export {};
package/dist/app.js CHANGED
@@ -2,6 +2,7 @@ import { checkPolicyRule, viaCollections } from "./policy.js";
2
2
  import { servicesDependencyProblem } from "./runtime/services-rules.js";
3
3
  import { validateName } from "@appport/protocol";
4
4
  import { FeltKitError } from "./errors.js";
5
+ import { modelEngine } from "./agent-engine.js";
5
6
  import { validateProviders } from "./providers.js";
6
7
  import { validateComponents } from "./component.js";
7
8
  import { defineSurface } from "./surfaces.js";
@@ -92,6 +93,12 @@ export function checkAccess(access, what) {
92
93
  throw new TypeError(`${what}: access "${access}" is not a permission (segments of letters, digits, "_" or "-" joined by ".", like "notes.read"), "authenticated" or "public".`);
93
94
  return access;
94
95
  }
96
+ /** The outbox claim of one reasoning attempt. Short: the run's own lease (renewed while it works) keeps a live attempt's run from being taken over. */
97
+ export const AGENT_REASONING_LEASE_MS = 120_000;
98
+ export const AGENT_MAX_TURNS = 100;
99
+ export const AGENT_MAX_TOOL_CALLS = 500;
100
+ /** The internal hook a reasoning agent's action calls: the runtime puts its run driver here on the action's ctx. */
101
+ export const AGENT_RUN = Symbol.for("feltkit.agentRun");
95
102
  export const AGENT_DEFAULT_ATTEMPTS = 5;
96
103
  export const AGENT_DEFAULT_BACKOFF_MS = 1_000;
97
104
  export const AGENT_MAX_BACKOFF_MS = 600_000;
@@ -109,6 +116,8 @@ export class FeltKitApp {
109
116
  migrations = [];
110
117
  /** Application agents (see `agent`), by name. */
111
118
  agents = new Map();
119
+ /** Agents that run on the agent runtime from their own project (`app.agent(name, { project })`), by name. */
120
+ projectAgents = new Map();
112
121
  /** Declared policies (`app.policy`), in declaration order. Resolved to function names at assembly. */
113
122
  policies = [];
114
123
  constructor(options) {
@@ -184,6 +193,7 @@ export class FeltKitApp {
184
193
  throw new TypeError("auth.guests.ttlMs is from one minute to 30 days.");
185
194
  }
186
195
  validateComponents(options.components, options.roles);
196
+ validateEve(options.eve, options.roles, options.auth?.tenant?.roles);
187
197
  validateProviders(options.providers);
188
198
  const tenant = options.auth?.tenant;
189
199
  if (tenant !== undefined) {
@@ -337,32 +347,29 @@ export class FeltKitApp {
337
347
  this.events.set(name, frozen);
338
348
  return frozen;
339
349
  }
340
- /**
341
- * An application agent: a handler that runs after a mutation commits, **as the agent** (principal
342
- * type "agent", `roles`, never the triggering caller's authority), through the same authority as
343
- * any call (roles → `access` → `feltkit({ authorize })`). A mutation triggers it with
344
- * `ctx.afterCommit.agent(name, input)`, or by publishing an event named in `on`. The run is
345
- * recorded in the mutation's transaction (the after-commit outbox), so it happens for every
346
- * committed mutation and never for one that did not commit; it runs at least once, with a lease,
347
- * retries with backoff, and its writes commit at most once per trigger (`ctx.trigger.idempotencyKey`).
348
- *
349
- * export const assistant = app.agent("assistant", {
350
- * principal: { id: "assistant", displayName: "Assistant" },
351
- * roles: ["assistant"],
352
- * access: "messages.write",
353
- * handler: async (ctx, { roomId }) => { ... ctx.db.insert(messages, { roomId, text }) ... },
354
- * });
355
- * // in messages:send — if (text.includes("@assistant")) ctx.afterCommit.agent("assistant", { roomId });
356
- *
357
- * See docs/TRANSACTIONS.md ("Application agents"). Not available in an AppBoundry artifact.
358
- */
359
350
  agent(name, config) {
351
+ if (config && typeof config.project === "string")
352
+ return this.projectAgent(name, config);
353
+ return this.inProcessAgent(name, config);
354
+ }
355
+ projectAgent(name, config) {
356
+ if (this.agents.has(name) || this.projectAgents.has(name) || Object.hasOwn(this.options.eve ?? {}, name))
357
+ throw new TypeError(`app.agent("${name}") is declared twice.`);
358
+ if (config.handler !== undefined || config.instructions !== undefined)
359
+ throw new TypeError(`app.agent("${name}") needs exactly one of handler (a deterministic agent), instructions (in-process reasoning) and project (an agent project on the agent runtime).`);
360
+ const { project, displayName, roles, tenantRole, capabilities, grantTtlMs } = config;
361
+ const declaration = { root: project, roles, capabilities, ...(tenantRole ? { tenantRole } : {}), ...(displayName ? { displayName } : {}), ...(grantTtlMs !== undefined ? { grantTtlMs } : {}) };
362
+ validateEve({ [name]: declaration }, this.options.roles, this.options.auth?.tenant?.roles, `app.agent("${name}")`);
363
+ this.projectAgents.set(name, Object.freeze(declaration));
364
+ return Object.freeze({ name, project });
365
+ }
366
+ inProcessAgent(name, config) {
360
367
  if (typeof name !== "string" || !/^[a-z][a-zA-Z0-9_-]{0,62}$/.test(name))
361
368
  throw new TypeError(`app.agent("${name}"): the name is a lowercase letter, then letters, digits, "_" or "-" (at most 63).`);
362
- if (this.agents.has(name))
369
+ if (this.agents.has(name) || this.projectAgents.has(name))
363
370
  throw new TypeError(`app.agent("${name}") is declared twice.`);
364
- if (!config || typeof config.handler !== "function")
365
- throw new TypeError(`app.agent("${name}") needs a handler function.`);
371
+ if (!config || (typeof config.handler !== "function") === (config.instructions === undefined))
372
+ throw new TypeError(`app.agent("${name}") needs exactly one of handler (a deterministic agent) and instructions (a reasoning agent).`);
366
373
  const id = config.principal?.id;
367
374
  if (typeof id !== "string" || !/^[A-Za-z0-9][A-Za-z0-9._:@-]{0,127}$/.test(id))
368
375
  throw new TypeError(`app.agent("${name}"): principal.id must be 1-128 letters, digits, ".", "_", ":", "@" or "-".`);
@@ -380,7 +387,8 @@ export class FeltKitApp {
380
387
  }
381
388
  const maxAttempts = config.retry?.maxAttempts ?? AGENT_DEFAULT_ATTEMPTS;
382
389
  const backoffMs = config.retry?.backoffMs ?? AGENT_DEFAULT_BACKOFF_MS;
383
- const leaseMs = config.leaseMs ?? AGENT_DEFAULT_LEASE_MS;
390
+ const reasoning = config.instructions !== undefined ? this.checkReasoning(name, config) : undefined;
391
+ const leaseMs = config.leaseMs ?? (reasoning ? AGENT_REASONING_LEASE_MS : AGENT_DEFAULT_LEASE_MS);
384
392
  if (!Number.isInteger(maxAttempts) || maxAttempts < 1 || maxAttempts > 100)
385
393
  throw new TypeError(`app.agent("${name}"): retry.maxAttempts must be an integer from 1 to 100.`);
386
394
  if (!Number.isFinite(backoffMs) || backoffMs < 0 || backoffMs > AGENT_MAX_BACKOFF_MS)
@@ -388,7 +396,9 @@ export class FeltKitApp {
388
396
  if (!Number.isFinite(leaseMs) || leaseMs < 1_000)
389
397
  throw new TypeError(`app.agent("${name}"): leaseMs must be at least 1000.`);
390
398
  const handler = config.handler;
391
- const fn = this.define("mutation", { access: checkAccess(config.access, `app.agent("${name}")`), ...(config.description ? { description: config.description } : {}), handler: (ctx, input) => handler(ctx, input) });
399
+ const fn = reasoning
400
+ ? this.define("action", { access: checkAccess(config.access, `app.agent("${name}")`), ...(config.description ? { description: config.description } : {}), handler: (ctx, input) => ctx[AGENT_RUN](input) })
401
+ : this.define("mutation", { access: checkAccess(config.access, `app.agent("${name}")`), ...(config.description ? { description: config.description } : {}), handler: (ctx, input) => handler(ctx, input) });
392
402
  // Any input object: the trigger's input is the app's own (validated where it is staged, if at all).
393
403
  const definition = Object.freeze({
394
404
  name,
@@ -397,11 +407,57 @@ export class FeltKitApp {
397
407
  on: Object.freeze(events.map((e) => e.name)),
398
408
  retry: Object.freeze({ maxAttempts, backoffMs }),
399
409
  leaseMs,
400
- function: Object.freeze({ ...fn, argsSchema: shapeToObjectSchema({}, { additionalProperties: true }) }),
410
+ function: Object.freeze({ ...fn, argsSchema: config.input ? shapeToObjectSchema(config.input) : shapeToObjectSchema({}, { additionalProperties: true }) }),
411
+ ...(reasoning ? { reasoning } : {}),
401
412
  });
402
413
  this.agents.set(name, definition);
403
414
  return definition;
404
415
  }
416
+ checkReasoning(name, config) {
417
+ const where = `app.agent("${name}")`;
418
+ if (typeof config.instructions !== "string" || !config.instructions.trim() || config.instructions.length > 100_000)
419
+ throw new TypeError(`${where}: instructions is a non-empty string (at most 100 000 characters).`);
420
+ const capabilityOf = (fn, list) => {
421
+ if (!isFunctionDefinition(fn) || fn.app !== this)
422
+ throw new TypeError(`${where}: ${list} takes this application's query, mutation or action definitions (import them).`);
423
+ if (!fn.capability)
424
+ throw new TypeError(`${where}: ${list} names a function that is not published as a capability; add capability: "<name>" to it, so the agent uses it through AppPort like any caller.`);
425
+ return fn.capability.name;
426
+ };
427
+ if (!Array.isArray(config.tools) || config.tools.length === 0)
428
+ throw new TypeError(`${where}: a reasoning agent declares the tools it may use (tools: [...]).`);
429
+ const tools = [...new Set(config.tools.map((fn) => capabilityOf(fn, "tools")))];
430
+ const autonomous = [...new Set((config.autonomous ?? []).map((fn) => capabilityOf(fn, "autonomous")))];
431
+ for (const a of autonomous)
432
+ if (!tools.includes(a))
433
+ throw new TypeError(`${where}: autonomous names ${a}, which is not in tools.`);
434
+ const maxTurns = config.limits?.maxTurns ?? 8;
435
+ const maxToolCalls = config.limits?.maxToolCalls ?? 20;
436
+ if (!Number.isInteger(maxTurns) || maxTurns < 1 || maxTurns > AGENT_MAX_TURNS)
437
+ throw new TypeError(`${where}: limits.maxTurns is an integer from 1 to ${AGENT_MAX_TURNS}.`);
438
+ if (!Number.isInteger(maxToolCalls) || maxToolCalls < 1 || maxToolCalls > AGENT_MAX_TOOL_CALLS)
439
+ throw new TypeError(`${where}: limits.maxToolCalls is an integer from 1 to ${AGENT_MAX_TOOL_CALLS}.`);
440
+ const engine = config.engine ?? modelEngine();
441
+ if (!engine || typeof engine.id !== "string" || typeof engine.next !== "function")
442
+ throw new TypeError(`${where}: engine is an AgentEngine ({ id, usesModel, next }), e.g. modelEngine() or rulesEngine(id, decide).`);
443
+ const int = (key, fallback, min, max) => {
444
+ const value = config.limits?.[key] ?? fallback;
445
+ if (value !== undefined && (!Number.isInteger(value) || value < min || value > max))
446
+ throw new TypeError(`${where}: limits.${key} is an integer from ${min} to ${max}.`);
447
+ return value;
448
+ };
449
+ const maxGenerations = int("maxGenerations", maxTurns * 2, 1, 1_000);
450
+ const maxActiveMs = int("maxActiveMs", 600_000, 1_000, 86_400_000);
451
+ const maxTokens = int("maxTokens", undefined, 1, 100_000_000);
452
+ const concurrency = int("concurrency", 4, 1, 1_000);
453
+ const limits = Object.freeze({ maxTurns, maxToolCalls, maxGenerations, maxActiveMs, concurrency, ...(maxTokens !== undefined ? { maxTokens } : {}) });
454
+ let output;
455
+ if (config.output !== undefined) {
456
+ const candidate = config.output;
457
+ output = typeof candidate?.toJSONSchema === "function" ? config.output : shapeToObjectSchema(config.output);
458
+ }
459
+ return Object.freeze({ instructions: config.instructions, tools: Object.freeze(tools), autonomous: Object.freeze(autonomous), limits, engine, ...(output ? { output } : {}) });
460
+ }
405
461
  /**
406
462
  * Declare a policy: who may call which functions, on which resource, under which conditions
407
463
  * (see PolicyRule and src/policy.ts for the semantics). Deterministic, enforced at the execution
@@ -936,6 +992,18 @@ export function isFeltKitApp(value) {
936
992
  export function isFunctionDefinition(value) {
937
993
  return typeof value === "object" && value !== null && value[FUNCTION] === true;
938
994
  }
995
+ /**
996
+ * A function group: one export whose function members are named `<module>:<member>`, as if each
997
+ * were exported on its own (a capability built from the public API, such as Boards, ships its
998
+ * functions this way). Members that are not functions (collections, helpers) are ignored.
999
+ */
1000
+ export const FUNCTION_GROUP = Symbol.for("feltkit.functionGroup");
1001
+ export function functionGroup(members) {
1002
+ return Object.freeze(Object.assign(Object.create(null), members, { $functionGroup: true, [FUNCTION_GROUP]: true }));
1003
+ }
1004
+ export function isFunctionGroup(value) {
1005
+ return typeof value === "object" && value !== null && value[FUNCTION_GROUP] === true;
1006
+ }
939
1007
  export function isEventDefinition(value) {
940
1008
  return typeof value === "object" && value !== null && value[EVENT] === true;
941
1009
  }
@@ -967,4 +1035,45 @@ export function capabilityNameSuggestion(name) {
967
1035
  const example = options.length ? `Use ${options.join(" or ")}.` : 'For example "tasks.complete".';
968
1036
  return `Names are lowercase <namespace>.<operation>, ASCII letters and digits only (no hyphens, underscores, or capitals). ${example}`;
969
1037
  }
1038
+ function validateEve(eve, roles, tenantRoles, label) {
1039
+ if (eve === undefined)
1040
+ return;
1041
+ if (!eve || typeof eve !== "object" || Array.isArray(eve))
1042
+ throw new TypeError("feltkit({ eve }) is { <name>: { roles, capabilities, tenantRole?, root? } }.");
1043
+ for (const [name, agent] of Object.entries(eve)) {
1044
+ if (!/^[a-z][a-z0-9-]{0,31}$/.test(name))
1045
+ throw new TypeError(`${label ?? `agent "${name}"`}: a name is 1–32 lowercase letters, digits or '-', starting with a letter.`);
1046
+ if (!agent || typeof agent !== "object")
1047
+ throw new TypeError(`${label ?? `agent "${name}"`} is { roles, capabilities, tenantRole?, root? }.`);
1048
+ if (!Array.isArray(agent.roles) || agent.roles.length === 0)
1049
+ throw new TypeError(`${label ?? `agent "${name}"`} needs the roles its worker holds: roles: ["agent"].`);
1050
+ for (const role of agent.roles)
1051
+ if (!roles?.[role])
1052
+ throw new TypeError(`${label ?? `agent "${name}"`} names role "${role}", which is not declared in roles.`);
1053
+ const grants = agent.roles.flatMap((role) => roles?.[role] ?? []);
1054
+ if (!grants.some((g) => g === "*" || g === "feltkit.*" || g === "feltkit.agent.*" || g === "feltkit.agent.write"))
1055
+ throw new TypeError(`${label ?? `agent "${name}"`}: its roles must grant "feltkit.agent.write": each session is an agent task the agent reports on (checkpoints, acknowledged updates). Add it to the "${agent.roles[0]}" role.`);
1056
+ if (!Array.isArray(agent.capabilities) || agent.capabilities.length === 0)
1057
+ throw new TypeError(`${label ?? `agent "${name}"`} needs the capabilities it may be granted: capabilities: ["tasks.*"].`);
1058
+ for (const c of agent.capabilities)
1059
+ if (typeof c !== "string" || !/^[a-z][a-z0-9]*(\.[a-z][a-z0-9]*)*(\.\*)?$/.test(c))
1060
+ throw new TypeError(`${label ?? `agent "${name}"`}: ${JSON.stringify(c)} is not a capability name or "namespace.*".`);
1061
+ if (tenantRoles) {
1062
+ if (!agent.tenantRole)
1063
+ throw new TypeError(`${label ?? `agent "${name}"`}: this application has workspaces, so name the workspace role the agent joins with (tenantRole).`);
1064
+ if (!tenantRoles.includes(agent.tenantRole))
1065
+ throw new TypeError(`${label ?? `agent "${name}"`}: tenantRole "${agent.tenantRole}" is not one of auth.tenant.roles.`);
1066
+ }
1067
+ else if (agent.tenantRole !== undefined)
1068
+ throw new TypeError(`${label ?? `agent "${name}"`}: tenantRole needs auth.tenant.`);
1069
+ if (agent.root !== undefined && (typeof agent.root !== "string" || agent.root.startsWith("/") || agent.root.split(/[\\/]/).includes("..")))
1070
+ throw new TypeError(`${label ?? `agent "${name}"`}: root is a directory inside the application.`);
1071
+ if (agent.grantTtlMs !== undefined && (!Number.isInteger(agent.grantTtlMs) || agent.grantTtlMs < 3_600_000 || agent.grantTtlMs > 30 * 24 * 3_600_000))
1072
+ throw new TypeError(`${label ?? `agent "${name}"`}: grantTtlMs is from one hour to 30 days.`);
1073
+ }
1074
+ }
1075
+ /** Every agent of the application that runs on the agent runtime: `app.agent(name, { project })` and `feltkit({ eve })`. */
1076
+ export function projectAgentsOf(app) {
1077
+ return { ...(app.options.eve ?? {}), ...Object.fromEntries(app.projectAgents) };
1078
+ }
970
1079
  //# sourceMappingURL=app.js.map