@feltdb/feltkit 0.1.1 → 0.3.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 (99) hide show
  1. package/dist/app.d.ts +106 -10
  2. package/dist/app.js +51 -0
  3. package/dist/app.js.map +1 -1
  4. package/dist/cli/deploy.js +9 -0
  5. package/dist/cli/deploy.js.map +1 -1
  6. package/dist/cli/main.js +339 -2
  7. package/dist/cli/main.js.map +1 -1
  8. package/dist/cli/skills.d.ts +39 -0
  9. package/dist/cli/skills.js +125 -0
  10. package/dist/cli/skills.js.map +1 -0
  11. package/dist/dashboard/assets/{index-BLnBFDJs.css → index--1Tqbv_A.css} +1 -1
  12. package/dist/dashboard/assets/index-D9529PVz.js +15 -0
  13. package/dist/dashboard/index.html +2 -2
  14. package/dist/errors.d.ts +5 -1
  15. package/dist/errors.js +3 -0
  16. package/dist/errors.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/runtime/activity.d.ts +21 -8
  19. package/dist/runtime/activity.js +17 -3
  20. package/dist/runtime/activity.js.map +1 -1
  21. package/dist/runtime/agent.d.ts +353 -0
  22. package/dist/runtime/agent.js +1345 -0
  23. package/dist/runtime/agent.js.map +1 -0
  24. package/dist/runtime/authority.d.ts +24 -3
  25. package/dist/runtime/authority.js +72 -5
  26. package/dist/runtime/authority.js.map +1 -1
  27. package/dist/runtime/changes.d.ts +16 -8
  28. package/dist/runtime/changes.js.map +1 -1
  29. package/dist/runtime/content.d.ts +33 -0
  30. package/dist/runtime/content.js +46 -0
  31. package/dist/runtime/content.js.map +1 -0
  32. package/dist/runtime/context.d.ts +26 -1
  33. package/dist/runtime/credentials.d.ts +174 -0
  34. package/dist/runtime/credentials.js +407 -0
  35. package/dist/runtime/credentials.js.map +1 -0
  36. package/dist/runtime/data.d.ts +8 -2
  37. package/dist/runtime/data.js +74 -9
  38. package/dist/runtime/data.js.map +1 -1
  39. package/dist/runtime/decisions.d.ts +141 -0
  40. package/dist/runtime/decisions.js +330 -0
  41. package/dist/runtime/decisions.js.map +1 -0
  42. package/dist/runtime/environment.js +11 -0
  43. package/dist/runtime/environment.js.map +1 -1
  44. package/dist/runtime/idempotency.d.ts +37 -0
  45. package/dist/runtime/idempotency.js +88 -0
  46. package/dist/runtime/idempotency.js.map +1 -0
  47. package/dist/runtime/instance.d.ts +8 -3
  48. package/dist/runtime/instance.js +27 -4
  49. package/dist/runtime/instance.js.map +1 -1
  50. package/dist/runtime/integrations.d.ts +125 -0
  51. package/dist/runtime/integrations.js +429 -0
  52. package/dist/runtime/integrations.js.map +1 -0
  53. package/dist/runtime/loader.d.ts +5 -1
  54. package/dist/runtime/loader.js +35 -13
  55. package/dist/runtime/loader.js.map +1 -1
  56. package/dist/runtime/projects.d.ts +1 -0
  57. package/dist/runtime/projects.js +6 -4
  58. package/dist/runtime/projects.js.map +1 -1
  59. package/dist/runtime/readiness.d.ts +29 -0
  60. package/dist/runtime/readiness.js +154 -0
  61. package/dist/runtime/readiness.js.map +1 -0
  62. package/dist/runtime/runtime.d.ts +53 -1
  63. package/dist/runtime/runtime.js +252 -9
  64. package/dist/runtime/runtime.js.map +1 -1
  65. package/dist/runtime/services.d.ts +205 -36
  66. package/dist/runtime/services.js +479 -152
  67. package/dist/runtime/services.js.map +1 -1
  68. package/dist/runtime/sessions.d.ts +7 -18
  69. package/dist/runtime/sessions.js +7 -5
  70. package/dist/runtime/sessions.js.map +1 -1
  71. package/dist/server/admin.d.ts +80 -0
  72. package/dist/server/admin.js +677 -8
  73. package/dist/server/admin.js.map +1 -1
  74. package/dist/server/index.d.ts +2 -0
  75. package/dist/server/index.js +13 -4
  76. package/dist/server/index.js.map +1 -1
  77. package/dist/server/management.d.ts +12 -0
  78. package/dist/server/management.js +177 -0
  79. package/dist/server/management.js.map +1 -0
  80. package/dist/server/mcp.d.ts +202 -0
  81. package/dist/server/mcp.js +62 -4
  82. package/dist/server/mcp.js.map +1 -1
  83. package/dist/server/operators.d.ts +77 -0
  84. package/dist/server/operators.js +162 -0
  85. package/dist/server/operators.js.map +1 -0
  86. package/dist/server/project.js +17 -4
  87. package/dist/server/project.js.map +1 -1
  88. package/dist/testing/index.js +3 -2
  89. package/dist/testing/index.js.map +1 -1
  90. package/package.json +18 -11
  91. package/skills/.claude-plugin/marketplace.json +16 -0
  92. package/skills/.claude-plugin/plugin.json +24 -0
  93. package/skills/README.md +44 -0
  94. package/skills/feltkit-agent/SKILL.md +84 -0
  95. package/skills/feltkit-build/SKILL.md +153 -0
  96. package/skills/feltkit-data/SKILL.md +79 -0
  97. package/skills/feltkit-operations/SKILL.md +72 -0
  98. package/skills/feltkit-services/SKILL.md +124 -0
  99. package/dist/dashboard/assets/index-CxJGCspE.js +0 -15
@@ -7,8 +7,8 @@
7
7
  <meta name="referrer" content="no-referrer" />
8
8
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='8' fill='%23111827'/%3E%3Cpath d='M11 7c-4 5-4 13 0 18M21 7c4 5 4 13 0 18' stroke='%2334d399' stroke-width='3' fill='none' stroke-linecap='round'/%3E%3C/svg%3E" />
9
9
  <title>FeltKit</title>
10
- <script type="module" crossorigin src="/_feltkit/assets/index-CxJGCspE.js"></script>
11
- <link rel="stylesheet" crossorigin href="/_feltkit/assets/index-BLnBFDJs.css">
10
+ <script type="module" crossorigin src="/_feltkit/assets/index-D9529PVz.js"></script>
11
+ <link rel="stylesheet" crossorigin href="/_feltkit/assets/index--1Tqbv_A.css">
12
12
  </head>
13
13
  <body>
14
14
  <div id="root"></div>
package/dist/errors.d.ts CHANGED
@@ -3,7 +3,11 @@
3
3
  * CLI, dashboard) is a FeltKitError with a stable code, so callers can branch on
4
4
  * `code` instead of parsing messages.
5
5
  */
6
- export type FeltKitErrorCode = "INVALID_ARGUMENT" | "VALIDATION_FAILED" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "FUNCTION_NOT_FOUND" | "CONFLICT" | "PAYLOAD_TOO_LARGE" | "CONFIGURATION" | "DUPLICATE_INSTANCE" | "UNAVAILABLE" | "INTERNAL";
6
+ export type FeltKitErrorCode = "INVALID_ARGUMENT" | "VALIDATION_FAILED" | "UNAUTHORIZED" | "FORBIDDEN" | "NOT_FOUND" | "FUNCTION_NOT_FOUND" | "CONFLICT" | "PAYLOAD_TOO_LARGE" | "CONFIGURATION" | "DUPLICATE_INSTANCE" | "UNAVAILABLE"
7
+ /** An external effect may or may not have happened. Never retried blindly; verify it. */
8
+ | "OUTCOME_UNKNOWN"
9
+ /** This environment's credential custody cannot store values (they come from the host). */
10
+ | "CUSTODY_READ_ONLY" | "INTERNAL";
7
11
  export interface FeltKitErrorJSON {
8
12
  code: FeltKitErrorCode;
9
13
  message: string;
package/dist/errors.js CHANGED
@@ -42,9 +42,12 @@ export function statusFor(code) {
42
42
  return 404;
43
43
  case "CONFLICT":
44
44
  case "DUPLICATE_INSTANCE":
45
+ case "CUSTODY_READ_ONLY":
45
46
  return 409;
46
47
  case "PAYLOAD_TOO_LARGE":
47
48
  return 413;
49
+ case "OUTCOME_UNKNOWN":
50
+ return 502;
48
51
  case "UNAVAILABLE":
49
52
  return 503;
50
53
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AA0BA,MAAM,KAAK,GAAG,MAAM,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;AAE1C,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,IAAI,CAAmB;IACvB,OAAO,CAAW;IAClB,IAAI,CAAU;IACd,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAExB,YAAY,IAAsB,EAAE,OAAe,EAAE,UAAiE,EAAE;QACtH,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KA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AAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;SACxD,CAAC;IACJ,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAK,KAAiC,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC;AAC3G,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,IAAI,CAAC,IAAsB,EAAE,OAAe,EAAE,OAAiB;IAC7E,MAAM,IAAI,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;AAClF,CAAC;AAED,qCAAqC;AACrC,MAAM,UAAU,SAAS,CAAC,IAAsB;IAC9C,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,kBAAkB,CAAC;QACxB,KAAK,mBAAmB;YACtB,OAAO,GAAG,CAAC;QACb,KAAK,cAAc;YACjB,OAAO,GAAG,CAAC;QACb,KAAK,WAAW;YACd,OAAO,GAAG,CAAC;QACb,KAAK,WAAW,CAAC;QACjB,KAAK,oBAAoB;YACvB,OAAO,GAAG,CAAC;QACb,KAAK,UAAU,CAAC;QAChB,KAAK,oBAAoB,CAAC;QAC1B,KAAK,mBAAmB;YACtB,OAAO,GAAG,CAAC;QACb,KAAK,mBAAmB;YACtB,OAAO,GAAG,CAAC;QACb,KAAK,iBAAiB;YACpB,OAAO,GAAG,CAAC;QACb,KAAK,aAAa;YAChB,OAAO,GAAG,CAAC;QACb;YACE,OAAO,GAAG,CAAC;IACf,CAAC;AACH,CAAC"}
package/dist/index.d.ts CHANGED
@@ -15,4 +15,4 @@ export type { FeltKitErrorCode, FeltKitErrorJSON } from "./errors.js";
15
15
  export type { QueryCtx, MutationCtx, Logger, EnvironmentInfo } from "./runtime/context.js";
16
16
  export type { DatabaseReader, DatabaseWriter, FindOptions, QueryRequest, QueryPage, WhereClause, OrderBy } from "./runtime/data.js";
17
17
  export type { AuthContext, Principal, PrincipalType } from "./runtime/authority.js";
18
- export type { FileInfo, FilesReader, FilesWriter, UploadInput, NotificationInfo, NotificationsReader, NotificationsWriter, SendNotificationInput, ConfigurationReader, ConfigurationWriter } from "./runtime/services.js";
18
+ export type { FileInfo, FilesReader, FilesWriter, UploadInput, NotificationInfo, NotificationsReader, NotificationsWriter, SendNotificationInput, JobsWriter, WebhooksWriter, ConfigurationReader, ConfigurationWriter } from "./runtime/services.js";
@@ -4,19 +4,20 @@
4
4
  * Entries are written to the application's FeltDB instance after an operation
5
5
  * completes. A mutation's `writes`, `transactionId`, and `commitRevision` come from
6
6
  * FeltDB's commit result — not from what the handler said it did. Service effects are
7
- * linked through AppPort Services' own evidence records (`service_effect_evidence`,
8
- * joined on `runId` = the FeltKit request id).
7
+ * linked through AppPort Services' own evidence, looked up with
8
+ * `services.evidence.findByRunId(runId)` where `runId` is the FeltKit request id (FeltKit
9
+ * passes it as the run id of every service effect inside the request).
9
10
  *
10
11
  * Payloads are never recorded (they can contain personal data or secrets); only the
11
12
  * argument names are.
12
13
  */
13
14
  import type { StateFirstDB } from "@feltdb/core";
15
+ import type { EffectEvidenceLookup, EffectEvidenceRecord } from "@appport/services";
14
16
  import type { CommittedWrite } from "./data.js";
15
17
  import type { Principal } from "./authority.js";
16
18
  export declare const ACTIVITY_COLLECTION = "_feltkit_activity";
17
- export declare const SERVICE_EVIDENCE_COLLECTION = "service_effect_evidence";
18
- export type ActivityKind = "query" | "mutation" | "capability" | "auth" | "admin" | "system";
19
- export type ActivityVia = "http" | "appport" | "mcp" | "dashboard" | "test" | "cli" | "runtime";
19
+ export type ActivityKind = "query" | "mutation" | "capability" | "auth" | "admin" | "system" | "service" | "agent" | "integration";
20
+ export type ActivityVia = "http" | "appport" | "mcp" | "dashboard" | "test" | "cli" | "runtime" | "job" | "agent" | "services" | "integration";
20
21
  export interface ActivityEntry {
21
22
  id: string;
22
23
  at: string;
@@ -51,7 +52,7 @@ export interface ActivityEntry {
51
52
  durationMs: number;
52
53
  argKeys?: string[];
53
54
  reads?: string[];
54
- /** AppPort Services this invocation used (details in service_effect_evidence). */
55
+ /** AppPort Services this invocation used (details in their effect evidence for `requestId`). */
55
56
  services?: string[];
56
57
  writes?: CommittedWrite[];
57
58
  transactionId?: string;
@@ -64,6 +65,8 @@ export interface ActivityFilter {
64
65
  kind?: ActivityKind;
65
66
  outcome?: ActivityEntry["outcome"];
66
67
  name?: string;
68
+ /** Entries for one request (exact). */
69
+ requestId?: string;
67
70
  limit?: number;
68
71
  }
69
72
  export type ActivityListener = (entry: ActivityEntry) => void;
@@ -76,6 +79,7 @@ export declare class ActivityLog {
76
79
  constructor(db: StateFirstDB, options: {
77
80
  mode: "all" | "writes" | "errors";
78
81
  retain?: number;
82
+ evidence: (runId: string) => Promise<EffectEvidenceLookup>;
79
83
  });
80
84
  get mode(): "writes" | "all" | "errors";
81
85
  subscribe(listener: ActivityListener): () => void;
@@ -88,8 +92,17 @@ export declare class ActivityLog {
88
92
  flush(): Promise<void>;
89
93
  list(filter?: ActivityFilter): Promise<ActivityEntry[]>;
90
94
  get(id: string): Promise<ActivityEntry | null>;
91
- /** AppPort Services evidence for one FeltKit request. */
92
- serviceEvidence(requestId: string): Promise<Record<string, unknown>[]>;
95
+ /**
96
+ * AppPort Services' evidence for one FeltKit request: its aggregate state (`none`,
97
+ * `started` = outcome unknown, `completed`, `failed`), the records, and whether the
98
+ * lookup was truncated.
99
+ */
100
+ serviceEvidenceLookup(requestId: string): Promise<EffectEvidenceLookup>;
101
+ /**
102
+ * The evidence records for one request, for reconciliation. A truncated lookup returns
103
+ * none: an incomplete set cannot prove an outcome, so the caller treats it as unknown.
104
+ */
105
+ serviceEvidence(requestId: string): Promise<EffectEvidenceRecord[]>;
93
106
  }
94
107
  export declare function errorSummary(error: unknown): {
95
108
  code: string;
@@ -1,17 +1,18 @@
1
1
  import { isFeltKitError } from "../errors.js";
2
2
  import { newId } from "./data.js";
3
3
  export const ACTIVITY_COLLECTION = "_feltkit_activity";
4
- export const SERVICE_EVIDENCE_COLLECTION = "service_effect_evidence";
5
4
  export class ActivityLog {
6
5
  #db;
7
6
  #mode;
8
7
  #retain;
9
8
  #listeners = new Set();
9
+ #evidence;
10
10
  #sincePrune = 0;
11
11
  #queue = Promise.resolve();
12
12
  lastError = null;
13
13
  constructor(db, options) {
14
14
  this.#db = db;
15
+ this.#evidence = options.evidence;
15
16
  this.#mode = options.mode;
16
17
  this.#retain = Math.max(100, options.retain ?? 2000);
17
18
  }
@@ -69,6 +70,7 @@ export class ActivityLog {
69
70
  ...(filter.kind ? [{ field: "kind", eq: filter.kind }] : []),
70
71
  ...(filter.outcome ? [{ field: "outcome", eq: filter.outcome }] : []),
71
72
  ...(filter.name ? [{ field: "name", eq: filter.name }] : []),
73
+ ...(filter.requestId ? [{ field: "requestId", eq: filter.requestId }] : []),
72
74
  ];
73
75
  const page = await this.#db.query({ collection: ACTIVITY_COLLECTION, ...(where.length ? { where } : {}), orderBy: [{ field: "id", direction: "desc" }], limit });
74
76
  return page.records;
@@ -77,9 +79,21 @@ export class ActivityLog {
77
79
  await this.flush();
78
80
  return (await this.#db.collection(ACTIVITY_COLLECTION).get(id)) ?? null;
79
81
  }
80
- /** AppPort Services evidence for one FeltKit request. */
82
+ /**
83
+ * AppPort Services' evidence for one FeltKit request: its aggregate state (`none`,
84
+ * `started` = outcome unknown, `completed`, `failed`), the records, and whether the
85
+ * lookup was truncated.
86
+ */
87
+ serviceEvidenceLookup(requestId) {
88
+ return this.#evidence(requestId);
89
+ }
90
+ /**
91
+ * The evidence records for one request, for reconciliation. A truncated lookup returns
92
+ * none: an incomplete set cannot prove an outcome, so the caller treats it as unknown.
93
+ */
81
94
  async serviceEvidence(requestId) {
82
- return (await this.#db.collection(SERVICE_EVIDENCE_COLLECTION).find({ runId: requestId })) ?? [];
95
+ const lookup = await this.#evidence(requestId);
96
+ return lookup.truncated ? [] : [...lookup.records];
83
97
  }
84
98
  async #prune() {
85
99
  const all = await this.#db.collection(ACTIVITY_COLLECTION).find({});
@@ -1 +1 @@
1
- {"version":3,"file":"activity.js","sourceRoot":"","sources":["../../src/runtime/activity.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGlC,MAAM,CAAC,MAAM,mBAAmB,GAAG,mBAAmB,CAAC;AACvD,MAAM,CAAC,MAAM,2BAA2B,GAAG,yBAAyB,CAAC;AAkDrE,MAAM,OAAO,WAAW;IACb,GAAG,CAAe;IAClB,KAAK,CAA8B;IACnC,OAAO,CAAS;IAChB,UAAU,GAAG,IAAI,GAAG,EAAoB,CAAC;IAClD,WAAW,GAAG,CAAC,CAAC;IAChB,MAAM,GAAkB,OAAO,CAAC,OAAO,EAAE,CAAC;IAC1C,SAAS,GAA2C,IAAI,CAAC;IAEzD,YAAY,EAAgB,EAAE,OAA+D;QAC3F,IAAI,CAAC,GAAG,GAAG,EAAE,CAAC;QACd,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,SAAS,CAAC,QAA0B;QAClC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAC9B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAChD,CAAC;IAED,KAAK,CAAC,IAAkB,EAAE,OAAiC;QACzD,IAAI,IAAI,CAAC,KAAK,KAAK,KAA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,CAAC,GAAG,CAAC,UAAU,CAAgB,mBAAmB,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnF,IAAI,GAAG,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO;QACvC,MAAM,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAChG,KAAK,MAAM,KAAK,IAAI,MAAM;YAAE,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC9F,CAAC;CACF;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,IAAI,cAAc,CAAC,KAAK,CAAC;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC;IAC/E,MAAM,CAAC,GAAG,KAA8C,CAAC;IACzD,OAAO,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;AAC1I,CAAC"}
@@ -0,0 +1,353 @@
1
+ /**
2
+ * The FeltKit agent: FeltDB's agent runtime and agent state, operating this
3
+ * application through AppPort.
4
+ *
5
+ * What is FeltDB's, reused as is (all on the environment's single instance):
6
+ *
7
+ * db.defineAgent(...) the agent's identity, capabilities, approval policy
8
+ * db.createAgentExecution({ taskId }) / start / transition / resume / complete / fail / cancel
9
+ * the durable lifecycle record of each task; every change
10
+ * is committed by FeltDB, invalid transitions refuse, and
11
+ * db.findAgentExecution({ taskId }) finds it (indexed)
12
+ * openAgentState(db) tasks, checkpoints whose `record` evidence is verified
13
+ * inside the commit, task memory (pending proposals),
14
+ * leased handoffs to another participant, bounded
15
+ * context bundles (feltdb.agent-context@1), and bounded,
16
+ * cursor-paged listTasks / listHandoffs
17
+ *
18
+ * What FeltKit adds is the product layer FeltDB does not have:
19
+ *
20
+ * - Actions go only through AppPort: application capabilities via the application's
21
+ * own dispatch pipeline (validate → authorize → execute), service operations via
22
+ * AppPort Services' invoke() and gateway. The agent has no other access to state.
23
+ * - Every action runs as the task's owner. An "observation" runs at once; a
24
+ * "consequential" action (AppPort's and AppPort Services' own effect classes) waits
25
+ * for a human who is also authorized to perform it. Approval is recorded; it never
26
+ * widens the owner's authority.
27
+ * - Decisions: FeltDB has no planner, and FeltKit adds none. Built-in playbooks choose
28
+ * capabilities by code (as FeltDB's own worker does); open-ended work is handed off,
29
+ * through FeltDB's handoff, to an external coding agent that proposes actions over MCP.
30
+ *
31
+ * Every result is redacted before it is recorded: secrets returned by an operation
32
+ * (an API key's plaintext, a session token) never reach a checkpoint, memory, or reply.
33
+ */
34
+ import { type AgentCheckpoint, type AgentTask, type StateFirstDB } from "@feltdb/core";
35
+ import { type Principal } from "./authority.js";
36
+ import type { FeltKitRuntime } from "./runtime.js";
37
+ export declare const AGENT_NAME = "feltkit";
38
+ export declare const AGENT_VERSION = 1;
39
+ /** Permissions for using the agent itself. Actions still need their own permissions. */
40
+ export declare const AGENT_PERMISSIONS: {
41
+ readonly read: "feltkit.agent.read";
42
+ readonly write: "feltkit.agent.write";
43
+ };
44
+ export type ActionEffect = "observation" | "consequential";
45
+ export interface AgentTool {
46
+ /** AppPort capability name ("reports.list") or AppPort Services capability ("jobs.retry"). */
47
+ name: string;
48
+ source: "application" | "services";
49
+ effect: ActionEffect;
50
+ description?: string;
51
+ /** Whether the principal asking may perform it (a decision only; nothing runs). */
52
+ allowed: boolean;
53
+ }
54
+ export interface ProposedAction {
55
+ actionId: string;
56
+ capability: string;
57
+ source: "application" | "services";
58
+ effect: ActionEffect;
59
+ input: Record<string, unknown>;
60
+ reason: string;
61
+ proposedBy: string;
62
+ proposedAt: string;
63
+ /** When a model's decision chose this action: which decision record, runtime, and model. */
64
+ decision?: {
65
+ memoryId: string;
66
+ runtime: string;
67
+ provider: string;
68
+ model?: string;
69
+ };
70
+ }
71
+ /**
72
+ * A decision for the agent to put to the environment's model: application code supplies
73
+ * the candidate next steps; the model only chooses among those the task owner may take.
74
+ */
75
+ export interface DecisionSpec {
76
+ question: string;
77
+ options: DecisionOption[];
78
+ /** Facts the model may use. Redacted before it is sent or recorded. */
79
+ context?: Record<string, unknown>;
80
+ }
81
+ export interface DecisionOption {
82
+ /** A short label the model answers with: lowercase letters, digits, dashes. */
83
+ id: string;
84
+ label?: string;
85
+ /** The capability this option proposes. Omit for a step only a person can take. */
86
+ capability?: string;
87
+ input?: Record<string, unknown>;
88
+ reason?: string;
89
+ }
90
+ /** Always offered: hand the task to a person instead of acting. */
91
+ export declare const ESCALATE = "escalate";
92
+ export interface ActionOutcome {
93
+ actionId: string;
94
+ capability: string;
95
+ ok: boolean;
96
+ /** Redacted. */
97
+ output?: unknown;
98
+ error?: {
99
+ code: string;
100
+ message: string;
101
+ };
102
+ /** The activity entry that records it: checkpoint evidence, verified on commit. */
103
+ activityId?: string;
104
+ durationMs: number;
105
+ /** Set when the call was abandoned before it answered; its effect may still happen. */
106
+ aborted?: "timeout" | "cancelled";
107
+ }
108
+ export type ActionState = "proposed" | "rejected" | "approved" | "executing" | "succeeded" | "failed" | "cancelled" | "interrupted";
109
+ /** States that still need something: approval, completion, or a person to settle them. */
110
+ export declare const OPEN_STATES: readonly ActionState[];
111
+ /** A consequential action as recorded in FeltDB agent memory. Never holds a secret. */
112
+ export interface ActionRecord extends ProposedAction {
113
+ state: ActionState;
114
+ /** Position in the record chain (`<actionId>.<seq>`). */
115
+ seq: number;
116
+ /** A retry after a failure is a new attempt, with a new idempotency key. */
117
+ attempt: number;
118
+ /** Who approved, rejected, or cancelled it (`type:id`). */
119
+ decidedBy?: string;
120
+ decidedAt?: string;
121
+ decisionNote?: string;
122
+ /** Whose authority it runs with: the task owner. */
123
+ executedAs?: string;
124
+ /** The AppPort request id, persisted before the call: how recovery finds its evidence. */
125
+ requestId?: string;
126
+ idempotencyKey?: string;
127
+ startedAt?: string;
128
+ finishedAt?: string;
129
+ outcome?: {
130
+ ok: boolean;
131
+ output?: unknown;
132
+ error?: {
133
+ code: string;
134
+ message: string;
135
+ };
136
+ activityId?: string;
137
+ determinedBy: "dispatch" | "appport-idempotency-record" | "function-activity" | "service-evidence" | "integration-call" | "integration-verification" | "person";
138
+ resolvedBy?: string;
139
+ };
140
+ /** Why the outcome is unknown. */
141
+ interruption?: string;
142
+ history: Array<{
143
+ state: ActionState;
144
+ at: string;
145
+ by: string;
146
+ note?: string;
147
+ }>;
148
+ }
149
+ /**
150
+ * Tests only: fault injection at the points where a real process could stop. A hook
151
+ * that throws behaves like a crash: nothing after it in the action's lifecycle runs.
152
+ */
153
+ export interface AgentHooks {
154
+ afterApproved?: (at: {
155
+ taskId: string;
156
+ actionId: string;
157
+ }) => void | Promise<void>;
158
+ beforeInvoke?: (at: {
159
+ taskId: string;
160
+ actionId: string;
161
+ }) => void | Promise<void>;
162
+ afterInvoke?: (at: {
163
+ taskId: string;
164
+ actionId: string;
165
+ }) => void | Promise<void>;
166
+ }
167
+ export interface TaskView {
168
+ task: AgentTask;
169
+ checkpoints: AgentCheckpoint[];
170
+ execution: Record<string, unknown> | null;
171
+ /** Actions waiting for approval. */
172
+ pending: ActionRecord[];
173
+ /** Every consequential action on the task, in any state. */
174
+ actions: ActionRecord[];
175
+ playbook?: string;
176
+ }
177
+ export declare const PLAYBOOKS: readonly ["diagnose-job", "diagnose-delivery", "inspect-app", "invoke", "decide", "handoff"];
178
+ export type Playbook = (typeof PLAYBOOKS)[number];
179
+ /** Remove credential material from anything recorded or returned. */
180
+ export declare function redact(value: unknown, depth?: number): unknown;
181
+ export declare class AgentHost {
182
+ #private;
183
+ constructor(runtime: FeltKitRuntime, db: StateFirstDB, options?: {
184
+ actionTimeoutMs?: number;
185
+ hooks?: AgentHooks;
186
+ separateApprover?: boolean;
187
+ });
188
+ /** Open agent state and define the agent. The runtime reconciles open actions once it is ready (outcome hooks are function calls). */
189
+ open(): Promise<void>;
190
+ /** (Re)define the agent with the application's current capabilities. Called on reload. */
191
+ define(): void;
192
+ /** What `principal` could ask the agent to do, with an authorization decision for each. */
193
+ tools(principal: Principal): Promise<AgentTool[]>;
194
+ /**
195
+ * The agent's own boundary: using the agent needs feltkit.agent.* (or a grant covering
196
+ * it). "admin" is the dashboard's admin token, which may read (never act).
197
+ */
198
+ authorizeRead(principal: Principal | null | "admin"): void;
199
+ createTask(input: {
200
+ objective: string;
201
+ principal: Principal | null;
202
+ playbook?: Playbook;
203
+ target?: string;
204
+ capability?: string;
205
+ args?: Record<string, unknown>;
206
+ decision?: DecisionSpec;
207
+ taskId?: string;
208
+ subject?: {
209
+ collection: string;
210
+ id: string;
211
+ };
212
+ }): Promise<TaskView>;
213
+ list(principal: Principal | null | "admin", limit?: number): Promise<Array<{
214
+ task: AgentTask;
215
+ execution: Record<string, unknown> | null;
216
+ pending: number;
217
+ }>>;
218
+ get(taskId: string, principal: Principal | null | "admin"): Promise<TaskView>;
219
+ /** The FeltDB context bundle for a task, plus this application's context. Redacted. */
220
+ context(taskId: string, principal: Principal | null): Promise<unknown>;
221
+ /**
222
+ * What an agent needs to know about this application, as `principal` sees it: the
223
+ * data model, capabilities it may use, services and their states, and recent failures.
224
+ */
225
+ applicationContext(principal: Principal): Promise<{
226
+ application: string;
227
+ environment: import("./environment.js").EnvironmentName;
228
+ collections: {
229
+ fields: string[];
230
+ description?: string | undefined;
231
+ name: string;
232
+ }[];
233
+ tools: AgentTool[];
234
+ services: {
235
+ summary?: Record<string, number> | undefined;
236
+ id: string;
237
+ state: import("./services.js").ServiceState;
238
+ detail: string;
239
+ }[];
240
+ recentErrors: {
241
+ at: string;
242
+ name: string;
243
+ via: import("./activity.js").ActivityVia;
244
+ code: string | undefined;
245
+ message: string | undefined;
246
+ }[];
247
+ recentDenials: {
248
+ at: string;
249
+ name: string;
250
+ via: import("./activity.js").ActivityVia;
251
+ principal: string | undefined;
252
+ }[];
253
+ }>;
254
+ /**
255
+ * Propose an action. An observation runs now as the task owner; a consequential
256
+ * action waits for approval. Either way it goes only through AppPort.
257
+ */
258
+ propose(taskId: string, proposal: {
259
+ capability: string;
260
+ input?: Record<string, unknown>;
261
+ reason: string;
262
+ decision?: ProposedAction["decision"];
263
+ }, principal: Principal | null): Promise<TaskView>;
264
+ /**
265
+ * Approve a proposed action, then run it as the task owner. Everything that can refuse
266
+ * is checked before the proposal is consumed: the approver is a person with
267
+ * feltkit.agent.write who may perform the action; the owner can still be resolved and
268
+ * may perform it. A refusal is recorded on the action, which stays proposed. A
269
+ * duplicate or concurrent approval of the same action never runs it twice.
270
+ */
271
+ approve(taskId: string, actionId: string, approver: Principal | null): Promise<TaskView>;
272
+ /** Reject a proposed action. */
273
+ reject(taskId: string, actionId: string, principal: Principal | null, reason?: string): Promise<TaskView>;
274
+ /**
275
+ * Retry an action that failed with a known outcome: a new attempt, with a new
276
+ * idempotency key, that needs approval again. The owner or a person may ask.
277
+ */
278
+ retry(taskId: string, actionId: string, principal: Principal | null): Promise<TaskView>;
279
+ /**
280
+ * Settle an interrupted action whose outcome FeltKit could not determine. Only a person
281
+ * who may perform the action can say what happened; FeltKit never guesses.
282
+ */
283
+ resolve(taskId: string, actionId: string, input: {
284
+ outcome: "succeeded" | "failed";
285
+ note?: string;
286
+ }, principal: Principal | null): Promise<TaskView>;
287
+ /**
288
+ * Bring every open action to a state that matches what is known, after a restart or on
289
+ * demand. Every open task (FeltDB's listTasks, paged), deterministic; it never runs an
290
+ * action:
291
+ *
292
+ * approved → proposed execution had not started; approval must be repeated
293
+ * executing → succeeded / failed from evidence (AppPort's idempotency record or the
294
+ * function's activity entry; AppPort Services' effect evidence), else
295
+ * → interrupted (outcome unknown)
296
+ * interrupted → succeeded / failed when such evidence has appeared since
297
+ */
298
+ reconcile(): Promise<{
299
+ examined: number;
300
+ changes: Array<{
301
+ taskId: string;
302
+ actionId: string;
303
+ from: ActionState;
304
+ to: ActionState;
305
+ determinedBy: string;
306
+ }>;
307
+ }>;
308
+ /** Finish a task. The summary is the owner's; evidence is what the checkpoints cite. */
309
+ complete(taskId: string, summary: string, principal: Principal | null): Promise<TaskView>;
310
+ /**
311
+ * Cancel a task. Actions not yet running are cancelled. A running action is aborted;
312
+ * since its effect may still complete, it becomes interrupted, and the task is not
313
+ * cancelled until every such action is settled (FeltDB takes no checkpoint after a
314
+ * terminal one, so settling must come first).
315
+ */
316
+ cancel(taskId: string, principal: Principal | null, reason?: string): Promise<TaskView>;
317
+ openHandoffs(principal: Principal | null | "admin"): Promise<{
318
+ handoffId: string;
319
+ taskId: string;
320
+ objective: string;
321
+ from: string;
322
+ note: string | null;
323
+ createdAt: string;
324
+ }[]>;
325
+ /** Claim and accept a handoff: the claimant becomes the task's owner and gets its context. */
326
+ claim(handoffId: string, principal: Principal | null): Promise<{
327
+ taskId: string;
328
+ context: unknown;
329
+ }>;
330
+ /** A note from the owner: decisions and progress, recorded as a checkpoint. */
331
+ note(taskId: string, input: {
332
+ summary: string;
333
+ decisions?: string[];
334
+ pendingWork?: string[];
335
+ }, principal: Principal | null): Promise<TaskView>;
336
+ /**
337
+ * Put the task's decision to the model again, e.g. after its configuration was fixed.
338
+ * The owner or a person may ask; the answer is a new proposal, never an execution.
339
+ */
340
+ decide(taskId: string, principal: Principal | null): Promise<TaskView>;
341
+ /** Start a decision task after the caller's transaction commits (ctx.agent.start). Tracked by idle(). */
342
+ startAfterCommit(input: {
343
+ taskId: string;
344
+ objective: string;
345
+ decision: DecisionSpec;
346
+ subject?: {
347
+ collection: string;
348
+ id: string;
349
+ };
350
+ }, principal: Principal): void;
351
+ /** Resolves when tasks started after commits have made their first decision. */
352
+ idle(): Promise<void>;
353
+ }