@a5c-ai/krate 5.0.1-staging.660d2b90f → 5.0.1-staging.69cb593ea
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/Dockerfile +31 -29
- package/bin/krate-demo.mjs +0 -0
- package/bin/krate-server.mjs +0 -0
- package/dist/krate-controller-ui.json +808 -10
- package/dist/krate-lifecycle.json +1 -1
- package/dist/krate-runtime-snapshot.json +223 -53
- package/dist/krate-summary.json +40 -3
- package/docs/agents/gaps-agent-mux-to-krate-crds.md +298 -0
- package/docs/architecture-v2.md +431 -0
- package/docs/openapi.yaml +1275 -0
- package/docs/requirements-v2.md +238 -0
- package/docs/sdk-api-reference.md +782 -0
- package/docs/system-spec-v2.md +352 -0
- package/docs/todos.md +4 -0
- package/docs/web-console-spec.md +433 -0
- package/package.json +1 -1
- package/scripts/validate-ui.mjs +305 -207
- package/src/agent-adapter-controller.js +169 -0
- package/src/agent-approval-controller.js +47 -0
- package/src/agent-dispatch-controller.js +130 -7
- package/src/agent-gateway-config-controller.js +147 -0
- package/src/agent-memory-controller.js +357 -0
- package/src/agent-memory-import.js +327 -0
- package/src/agent-memory-query.js +292 -0
- package/src/agent-memory-repository-source-controller.js +255 -0
- package/src/agent-mux-client.js +1 -1
- package/src/agent-permission-review.js +102 -14
- package/src/agent-project-controller.js +117 -0
- package/src/agent-provider-config-controller.js +150 -0
- package/src/agent-secret-config-grant-controller.js +282 -0
- package/src/agent-session-transcript-controller.js +189 -0
- package/src/agent-stack-controller.js +52 -1
- package/src/agent-subagent-controller.js +160 -0
- package/src/agent-transport-binding-controller.js +121 -0
- package/src/agent-trigger-controller.js +273 -0
- package/src/agent-workspace-controller.js +702 -0
- package/src/agent-writeback-controller.js +302 -0
- package/src/api-controller.js +338 -3
- package/src/async-controller.js +207 -0
- package/src/audit-controller.js +191 -0
- package/src/auth.js +48 -6
- package/src/controller-client.js +112 -38
- package/src/controller-ui.js +96 -16
- package/src/data-plane.js +3 -2
- package/src/event-bus.js +61 -0
- package/src/external/conflict-controller.js +225 -0
- package/src/external/github/auth.js +96 -0
- package/src/external/github/cicd.js +180 -0
- package/src/external/github/git-forge.js +240 -0
- package/src/external/github/index.js +144 -0
- package/src/external/github/issue-tracking.js +163 -0
- package/src/external/provider-adapter.js +161 -0
- package/src/external/provider-resource-factory.js +161 -0
- package/src/external/sync-controller.js +235 -0
- package/src/external/webhook-controller.js +144 -0
- package/src/external/write-controller.js +283 -0
- package/src/gitea-backend.js +36 -0
- package/src/gitea-service.js +173 -0
- package/src/http-server.js +226 -0
- package/src/index.js +27 -0
- package/src/kubernetes-controller-async.js +531 -0
- package/src/kubernetes-controller.js +156 -84
- package/src/notification-controller.js +178 -0
- package/src/org-scoping.js +5 -0
- package/src/resource-model.js +26 -8
- package/src/runner-controller.js +272 -0
- package/src/snapshot-cache.js +157 -0
- package/tests/agent-adapter-controller.test.js +361 -0
- package/tests/agent-dispatch-controller.test.js +139 -0
- package/tests/agent-gateway-config-controller.test.js +386 -0
- package/tests/agent-memory-controller.test.js +308 -0
- package/tests/agent-memory-import-snapshot.test.js +477 -0
- package/tests/agent-memory-query.test.js +404 -0
- package/tests/agent-memory-repository-source.test.js +514 -0
- package/tests/agent-permission-review-v2.test.js +317 -0
- package/tests/agent-project-controller.test.js +302 -0
- package/tests/agent-provider-config-controller.test.js +376 -0
- package/tests/agent-resources.test.js +35 -19
- package/tests/agent-secret-config-grant.test.js +231 -0
- package/tests/agent-session-transcript-controller.test.js +499 -0
- package/tests/agent-subagent-controller.test.js +201 -0
- package/tests/agent-transport-binding-controller.test.js +294 -0
- package/tests/agent-trigger-routes.test.js +190 -0
- package/tests/agent-trigger-sources.test.js +245 -0
- package/tests/agent-workspace-controller.test.js +181 -0
- package/tests/agent-writeback.test.js +292 -0
- package/tests/approval-persistence.test.js +171 -0
- package/tests/async-controller.test.js +252 -0
- package/tests/audit-controller.test.js +227 -0
- package/tests/codespace-controller.test.js +318 -0
- package/tests/controller-client.test.js +133 -0
- package/tests/deployment.test.js +43 -29
- package/tests/e2e/lifecycle.test.js +5 -2
- package/tests/event-bus-integration.test.js +190 -0
- package/tests/external-github-forge.test.js +560 -0
- package/tests/external-github-issues-cicd.test.js +520 -0
- package/tests/external-integration.test.js +470 -0
- package/tests/external-persistence.test.js +340 -0
- package/tests/external-provider-adapter.test.js +365 -0
- package/tests/external-resource-model.test.js +215 -0
- package/tests/external-webhook-sync.test.js +287 -0
- package/tests/external-write-conflict.test.js +353 -0
- package/tests/gitea-service.test.js +253 -0
- package/tests/health-check-real.test.js +165 -0
- package/tests/integration/full-flow.test.js +266 -0
- package/tests/krate.test.js +58 -6
- package/tests/memory-search-wiring.test.js +270 -0
- package/tests/notification-controller.test.js +196 -0
- package/tests/notification-integration.test.js +179 -0
- package/tests/org-scoping.test.js +687 -0
- package/tests/runner-controller.test.js +327 -0
- package/tests/runner-integration.test.js +231 -0
- package/tests/session-cookie-hmac.test.js +151 -0
- package/tests/snapshot-performance.test.js +315 -0
- package/tests/sse-events.test.js +107 -0
- package/tests/webhook-trigger.test.js +198 -0
- package/tests/workspace-volumes.test.js +312 -0
- package/tests/writeback-persistence.test.js +207 -0
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
# Krate SDK API Reference
|
|
2
|
+
|
|
3
|
+
> Derived from implementation. Source: `packages/krate/sdk/src/index.js`
|
|
4
|
+
|
|
5
|
+
Package: `@a5c-ai/krate-sdk`
|
|
6
|
+
|
|
7
|
+
The SDK re-exports core helpers for web and CLI consumers. All functions are pure ESM exports with zero external dependencies.
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 1. Resource Model
|
|
12
|
+
|
|
13
|
+
Source: `packages/krate/core/src/resource-model.js`
|
|
14
|
+
|
|
15
|
+
### Constants
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { CONFIG_KINDS, AGGREGATED_KINDS, ALL_KINDS, RESOURCE_DEFINITIONS } from '@a5c-ai/krate-sdk';
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Export | Type | Description |
|
|
22
|
+
|--------|------|-------------|
|
|
23
|
+
| `CONFIG_KINDS` | `Set<string>` | Set of 44 kind names stored in etcd |
|
|
24
|
+
| `AGGREGATED_KINDS` | `Set<string>` | Set of 32 kind names stored in postgres |
|
|
25
|
+
| `ALL_KINDS` | `Set<string>` | Union of CONFIG_KINDS and AGGREGATED_KINDS (76 total) |
|
|
26
|
+
| `RESOURCE_DEFINITIONS` | `Object` | Frozen map of kind → `{ storage, context, plural, purpose, requiredSpec }` |
|
|
27
|
+
|
|
28
|
+
### createResource(kind, metadata, spec)
|
|
29
|
+
|
|
30
|
+
Creates a well-formed Krate resource object.
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
import { createResource } from '@a5c-ai/krate-sdk';
|
|
34
|
+
|
|
35
|
+
const repo = createResource('Repository', { name: 'my-repo', namespace: 'krate-org-acme' }, {
|
|
36
|
+
organizationRef: 'acme',
|
|
37
|
+
visibility: 'private'
|
|
38
|
+
});
|
|
39
|
+
// Returns: { apiVersion: 'krate.a5c.ai/v1alpha1', kind: 'Repository', metadata: {...}, spec: {...} }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### clone(obj)
|
|
43
|
+
|
|
44
|
+
Deep clone utility for resource objects.
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
import { clone } from '@a5c-ai/krate-sdk';
|
|
48
|
+
const copy = clone(resource);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### resourceToYaml(resource)
|
|
52
|
+
|
|
53
|
+
Serialize a resource object to YAML string format.
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import { resourceToYaml } from '@a5c-ai/krate-sdk';
|
|
57
|
+
const yaml = resourceToYaml(repo);
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### findResourceDefinition(kind)
|
|
61
|
+
|
|
62
|
+
Look up the resource definition (plural, storage, namespace) for a given kind.
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
import { findResourceDefinition } from '@a5c-ai/krate-sdk';
|
|
66
|
+
const def = findResourceDefinition('Repository');
|
|
67
|
+
// { kind: 'Repository', plural: 'repositories', namespaced: true, storage: 'etcd' }
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## 2. API Controller
|
|
73
|
+
|
|
74
|
+
Source: `packages/krate/core/src/api-controller.js`
|
|
75
|
+
|
|
76
|
+
### createKrateApiController(options?)
|
|
77
|
+
|
|
78
|
+
Creates the main API controller for resource operations.
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
import { createKrateApiController } from '@a5c-ai/krate-sdk';
|
|
82
|
+
|
|
83
|
+
const controller = createKrateApiController({
|
|
84
|
+
namespace: 'krate-org-acme',
|
|
85
|
+
resourceGateway: createKubernetesResourceGateway() // optional
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Options:**
|
|
90
|
+
| Option | Type | Description |
|
|
91
|
+
|--------|------|-------------|
|
|
92
|
+
| `namespace` | `string` | Target K8s namespace |
|
|
93
|
+
| `resourceGateway` | `object` | Custom resource gateway (default: kubectl) |
|
|
94
|
+
|
|
95
|
+
**Methods:**
|
|
96
|
+
|
|
97
|
+
| Method | Signature | Returns |
|
|
98
|
+
|--------|-----------|---------|
|
|
99
|
+
| `snapshot()` | `() => Promise<object>` | Full namespace resource snapshot |
|
|
100
|
+
| `listResource(kind)` | `(kind: string) => Promise<{ items: object[] }>` | List resources by kind |
|
|
101
|
+
| `getResource(kind, name)` | `(kind: string, name: string) => Promise<object>` | Get single resource |
|
|
102
|
+
| `applyResource(resource)` | `(resource: object) => Promise<object>` | Create or update resource |
|
|
103
|
+
| `deleteResource(kind, name)` | `(kind: string, name: string) => Promise<object>` | Delete resource |
|
|
104
|
+
| `createOrganization(spec)` | `(spec: object) => Promise<object>` | Create org with namespace |
|
|
105
|
+
| `createRepository(spec)` | `(spec: object) => Promise<object>` | Create repository |
|
|
106
|
+
| `listResourceForOrg(org, kind)` | `(org: string, kind: string) => Promise<object>` | List resources scoped to org |
|
|
107
|
+
| `applyResourceForOrg(org, resource)` | `(org: string, resource: object) => Promise<object>` | Apply resource scoped to org |
|
|
108
|
+
| `deleteResourceForOrg(org, kind, name)` | `(org: string, kind: string, name: string) => Promise<object>` | Delete scoped resource |
|
|
109
|
+
| `syncExternalBinding(name, data)` | `(name: string, data: object) => Promise<object>` | Trigger external sync |
|
|
110
|
+
| `resolveExternalConflict(options)` | `(options: object) => Promise<object>` | Resolve sync conflict |
|
|
111
|
+
| `approveExternalWriteIntent(options)` | `(options: object) => Promise<object>` | Approve write intent |
|
|
112
|
+
| `cancelExternalWriteIntent(options)` | `(options: object) => Promise<object>` | Cancel write intent |
|
|
113
|
+
| `processWebhookEvent(event)` | `(event: object) => Promise<object>` | Process webhook/trigger event |
|
|
114
|
+
| `queryAgentMemory(options)` | `(options: object) => Promise<object>` | Query agent memory |
|
|
115
|
+
| `approveAgentAction(input)` | `(input: object) => Promise<object>` | Approve agent action |
|
|
116
|
+
| `denyAgentAction(input)` | `(input: object) => Promise<object>` | Deny agent action |
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 3. UI Model
|
|
121
|
+
|
|
122
|
+
Source: `packages/krate/core/src/controller-ui.js`
|
|
123
|
+
|
|
124
|
+
### createControllerUiModel(snapshot, options?)
|
|
125
|
+
|
|
126
|
+
Transforms a raw controller snapshot into a structured UI model.
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
import { createControllerUiModel } from '@a5c-ai/krate-sdk';
|
|
130
|
+
|
|
131
|
+
const uiModel = createControllerUiModel(await controller.snapshot(), {
|
|
132
|
+
organization: 'acme'
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
**Returns:** Object with:
|
|
137
|
+
- `orgs` — Organization list with display names
|
|
138
|
+
- `repositories` — Repository list with metadata
|
|
139
|
+
- `pullRequests` — Open pull requests
|
|
140
|
+
- `pipelines` — Recent pipeline runs
|
|
141
|
+
- `issues` — Issue list
|
|
142
|
+
- `agents` — Agent stacks, runs, sessions
|
|
143
|
+
- `memory` — Memory repositories
|
|
144
|
+
|
|
145
|
+
### issueProjectRefs(issue)
|
|
146
|
+
|
|
147
|
+
Extract project references from an issue resource.
|
|
148
|
+
|
|
149
|
+
### issueRepositoryRefs(issue)
|
|
150
|
+
|
|
151
|
+
Extract repository references from an issue resource.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 4. Authentication
|
|
156
|
+
|
|
157
|
+
Source: `packages/krate/core/src/auth.js`
|
|
158
|
+
|
|
159
|
+
### createAuthProviderConfig(env?)
|
|
160
|
+
|
|
161
|
+
Build auth configuration from environment variables.
|
|
162
|
+
|
|
163
|
+
```javascript
|
|
164
|
+
import { createAuthProviderConfig } from '@a5c-ai/krate-sdk';
|
|
165
|
+
const config = createAuthProviderConfig(process.env);
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Returns:** `{ session, delegatedIdentity, providers: { github, sso } }`
|
|
169
|
+
|
|
170
|
+
### listEnabledAuthProviders(config?)
|
|
171
|
+
|
|
172
|
+
Get array of enabled and configured providers.
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
import { listEnabledAuthProviders } from '@a5c-ai/krate-sdk';
|
|
176
|
+
const providers = listEnabledAuthProviders(config);
|
|
177
|
+
// [{ id: 'github', label: 'GitHub', type: 'github', ... }]
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### buildAuthorizationRedirect({ provider, requestUrl, state? })
|
|
181
|
+
|
|
182
|
+
Build OAuth authorization redirect URL.
|
|
183
|
+
|
|
184
|
+
```javascript
|
|
185
|
+
import { buildAuthorizationRedirect } from '@a5c-ai/krate-sdk';
|
|
186
|
+
const { url, state, redirectUri } = buildAuthorizationRedirect({
|
|
187
|
+
provider: config.providers.github,
|
|
188
|
+
requestUrl: 'https://krate.example.com/login'
|
|
189
|
+
});
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
### exchangeOAuthCodeForProfile({ provider, code, requestUrl, fetchImpl? })
|
|
193
|
+
|
|
194
|
+
Exchange OAuth authorization code for user profile.
|
|
195
|
+
|
|
196
|
+
```javascript
|
|
197
|
+
import { exchangeOAuthCodeForProfile } from '@a5c-ai/krate-sdk';
|
|
198
|
+
const profile = await exchangeOAuthCodeForProfile({
|
|
199
|
+
provider: config.providers.github,
|
|
200
|
+
code: 'abc123',
|
|
201
|
+
requestUrl: 'https://krate.example.com/login'
|
|
202
|
+
});
|
|
203
|
+
// { provider, subject, email, displayName, username, groups, teams, admin }
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### createSessionCookie(config, profile, options?)
|
|
207
|
+
|
|
208
|
+
Create an HMAC-signed session cookie.
|
|
209
|
+
|
|
210
|
+
```javascript
|
|
211
|
+
import { createSessionCookie } from '@a5c-ai/krate-sdk';
|
|
212
|
+
const cookie = createSessionCookie(config, profile, { secret: process.env.KRATE_SESSION_SECRET });
|
|
213
|
+
// "krate_session=base64url.signature; Path=/; HttpOnly; SameSite=Lax"
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### parseSessionCookie(config, cookieValue, options?)
|
|
217
|
+
|
|
218
|
+
Parse and verify a session cookie. Returns `null` if invalid.
|
|
219
|
+
|
|
220
|
+
```javascript
|
|
221
|
+
import { parseSessionCookie } from '@a5c-ai/krate-sdk';
|
|
222
|
+
const session = parseSessionCookie(config, cookieValue, { secret });
|
|
223
|
+
// { provider, subject, user } or null
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### registerLoginProfile({ controller, namespace, profile })
|
|
227
|
+
|
|
228
|
+
Register a login profile as a User and IdentityMapping.
|
|
229
|
+
|
|
230
|
+
### mapLoginProfileToKrateIdentity(profile)
|
|
231
|
+
|
|
232
|
+
Map an OAuth profile to Krate User + IdentityMapping resources.
|
|
233
|
+
|
|
234
|
+
### profileFromDelegatedHeaders(headers, config?, options?)
|
|
235
|
+
|
|
236
|
+
Extract user profile from proxy delegation headers.
|
|
237
|
+
|
|
238
|
+
### createInviteResource(spec)
|
|
239
|
+
|
|
240
|
+
Create an Invite resource for user onboarding.
|
|
241
|
+
|
|
242
|
+
### createTeamResource(spec)
|
|
243
|
+
|
|
244
|
+
Create a Team resource.
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## 5. Agent Controllers
|
|
249
|
+
|
|
250
|
+
### createAgentStackController()
|
|
251
|
+
|
|
252
|
+
Source: `packages/krate/core/src/agent-stack-controller.js`
|
|
253
|
+
|
|
254
|
+
Stack readiness reconciliation with capability resolution and MCP health checks.
|
|
255
|
+
|
|
256
|
+
```javascript
|
|
257
|
+
import { createAgentStackController } from '@a5c-ai/krate-sdk';
|
|
258
|
+
const stackCtrl = createAgentStackController();
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
**Methods:**
|
|
262
|
+
- `reconcileStack(stack, resources)` — Resolve capabilities, compute readiness
|
|
263
|
+
- `performMcpHealthCheck(url)` — HTTP health check (3s timeout)
|
|
264
|
+
|
|
265
|
+
### createAgentDispatchController(options?)
|
|
266
|
+
|
|
267
|
+
Source: `packages/krate/core/src/agent-dispatch-controller.js`
|
|
268
|
+
|
|
269
|
+
Manual dispatch orchestration with permission gating.
|
|
270
|
+
|
|
271
|
+
```javascript
|
|
272
|
+
import { createAgentDispatchController } from '@a5c-ai/krate-sdk';
|
|
273
|
+
const dispatchCtrl = createAgentDispatchController();
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
**Methods:**
|
|
277
|
+
- `createManualDispatch({ repository, ref, agentStack, taskKind, actor, namespace, organizationRef, resources })` — Create dispatch run
|
|
278
|
+
|
|
279
|
+
### createAgentWorkspaceController()
|
|
280
|
+
|
|
281
|
+
Source: `packages/krate/core/src/agent-workspace-controller.js`
|
|
282
|
+
|
|
283
|
+
Volume-backed git workspace provisioning.
|
|
284
|
+
|
|
285
|
+
**Methods:**
|
|
286
|
+
- `createWorkspace({ name, organizationRef, repository, volumeSpec, branch, namespace })` — Create workspace with PVC
|
|
287
|
+
- `generateCloneSpec(workspace)` — Git clone commands
|
|
288
|
+
- `generateCheckoutSpec(workspace, ref)` — Checkout commands
|
|
289
|
+
- `generateMountSpec(workspace)` — Volume mount configuration
|
|
290
|
+
- `findReusableWorkspace(repository, branch, workspaces)` — Find existing workspace
|
|
291
|
+
- `recordRunInHistory(workspace, runId)` — Track run association
|
|
292
|
+
|
|
293
|
+
### createAgentApprovalController()
|
|
294
|
+
|
|
295
|
+
Source: `packages/krate/core/src/agent-approval-controller.js`
|
|
296
|
+
|
|
297
|
+
Approval workflow management.
|
|
298
|
+
|
|
299
|
+
**Methods:**
|
|
300
|
+
- `createApproval(options)` — Create pending approval
|
|
301
|
+
- `approveAction(approval, decidedBy, reason)` — Approve
|
|
302
|
+
- `denyAction(approval, decidedBy, reason)` — Deny
|
|
303
|
+
|
|
304
|
+
### createAgentTriggerController()
|
|
305
|
+
|
|
306
|
+
Source: `packages/krate/core/src/agent-trigger-controller.js`
|
|
307
|
+
|
|
308
|
+
Event-to-stack routing.
|
|
309
|
+
|
|
310
|
+
```javascript
|
|
311
|
+
import { createAgentTriggerController, validateTriggerRule } from '@a5c-ai/krate-sdk';
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**Methods:**
|
|
315
|
+
- `evaluateTrigger(event, rules, resources)` — Match event to rules
|
|
316
|
+
- `createExecutionRecord(rule, event, decision)` — Record evaluation
|
|
317
|
+
|
|
318
|
+
**Exported utilities:**
|
|
319
|
+
- `validateCronExpression(expr)` — Validate cron syntax
|
|
320
|
+
- `calculateNextRun(expr, now)` — Next cron execution time
|
|
321
|
+
- `validateWebhookTrigger(source)` — Validate webhook source config
|
|
322
|
+
- `validateCommentTrigger(source)` — Validate comment trigger
|
|
323
|
+
- `validateLabelTrigger(source)` — Validate label trigger
|
|
324
|
+
- `getTriggerSourceType(source)` — Determine source type
|
|
325
|
+
- `validateTriggerRule(rule)` — Full rule validation
|
|
326
|
+
|
|
327
|
+
### createAgentMemoryController()
|
|
328
|
+
|
|
329
|
+
Source: `packages/krate/core/src/agent-memory-controller.js`
|
|
330
|
+
|
|
331
|
+
Memory CRUD and time travel.
|
|
332
|
+
|
|
333
|
+
**Methods:**
|
|
334
|
+
- `createMemorySnapshot(options)` — Create dispatch-time memory pin
|
|
335
|
+
- `resolveTimeTravel(options)` — Resolve commit reference
|
|
336
|
+
|
|
337
|
+
### createAgentAdapterController()
|
|
338
|
+
|
|
339
|
+
Source: `packages/krate/core/src/agent-adapter-controller.js`
|
|
340
|
+
|
|
341
|
+
```javascript
|
|
342
|
+
import { createAgentAdapterController, validateAgentAdapter } from '@a5c-ai/krate-sdk';
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
### createAgentTransportBindingController()
|
|
346
|
+
|
|
347
|
+
Source: `packages/krate/core/src/agent-transport-binding-controller.js`
|
|
348
|
+
|
|
349
|
+
```javascript
|
|
350
|
+
import { createAgentTransportBindingController, validateAgentTransportBinding } from '@a5c-ai/krate-sdk';
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### createAgentProviderConfigController()
|
|
354
|
+
|
|
355
|
+
Source: `packages/krate/core/src/agent-provider-config-controller.js`
|
|
356
|
+
|
|
357
|
+
```javascript
|
|
358
|
+
import { createAgentProviderConfigController, validateAgentProviderConfig } from '@a5c-ai/krate-sdk';
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
### createAgentProjectController()
|
|
362
|
+
|
|
363
|
+
Source: `packages/krate/core/src/agent-project-controller.js`
|
|
364
|
+
|
|
365
|
+
```javascript
|
|
366
|
+
import { createAgentProjectController, validateAgentProject } from '@a5c-ai/krate-sdk';
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### createAgentGatewayConfigController()
|
|
370
|
+
|
|
371
|
+
Source: `packages/krate/core/src/agent-gateway-config-controller.js`
|
|
372
|
+
|
|
373
|
+
```javascript
|
|
374
|
+
import { createAgentGatewayConfigController, validateAgentGatewayConfig } from '@a5c-ai/krate-sdk';
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
### createAgentSessionTranscriptController()
|
|
378
|
+
|
|
379
|
+
Source: `packages/krate/core/src/agent-session-transcript-controller.js`
|
|
380
|
+
|
|
381
|
+
```javascript
|
|
382
|
+
import { createAgentSessionTranscriptController, validateAgentSessionTranscript } from '@a5c-ai/krate-sdk';
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
### createAgentSubagentController()
|
|
386
|
+
|
|
387
|
+
Source: `packages/krate/core/src/agent-subagent-controller.js`
|
|
388
|
+
|
|
389
|
+
```javascript
|
|
390
|
+
import { createAgentSubagentController } from '@a5c-ai/krate-sdk';
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### createAgentWritebackController()
|
|
394
|
+
|
|
395
|
+
Source: `packages/krate/core/src/agent-writeback-controller.js`
|
|
396
|
+
|
|
397
|
+
```javascript
|
|
398
|
+
import { createAgentWritebackController } from '@a5c-ai/krate-sdk';
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
---
|
|
402
|
+
|
|
403
|
+
## 6. Memory System
|
|
404
|
+
|
|
405
|
+
Source: `packages/krate/core/src/agent-memory-query.js`
|
|
406
|
+
|
|
407
|
+
### queryGraph({ records, edges, query, kinds?, depth? })
|
|
408
|
+
|
|
409
|
+
Execute a graph query over memory records.
|
|
410
|
+
|
|
411
|
+
```javascript
|
|
412
|
+
import { queryGraph } from '@a5c-ai/krate-sdk';
|
|
413
|
+
|
|
414
|
+
const result = queryGraph({
|
|
415
|
+
records: [{ id: 'n1', nodeKind: 'concept', attributes: { title: 'Agent Design' }, edges: [] }],
|
|
416
|
+
edges: [{ source: 'n1', target: 'n2', kind: 'related-to' }],
|
|
417
|
+
query: 'agent',
|
|
418
|
+
kinds: ['concept'],
|
|
419
|
+
depth: 2
|
|
420
|
+
});
|
|
421
|
+
// { matches: [...], totalMatches: number }
|
|
422
|
+
```
|
|
423
|
+
|
|
424
|
+
**Parameters:**
|
|
425
|
+
| Param | Type | Required | Description |
|
|
426
|
+
|-------|------|----------|-------------|
|
|
427
|
+
| `records` | `Array<{ id, nodeKind, attributes, edges }>` | Yes | Graph records |
|
|
428
|
+
| `edges` | `Array<{ source, target, kind }>` | No | Flat edges (supplements per-record edges) |
|
|
429
|
+
| `query` | `string` | Yes | Search text (non-empty) |
|
|
430
|
+
| `kinds` | `string[]` | No | nodeKind filter (empty = no filter) |
|
|
431
|
+
| `depth` | `number` | No | Edge-follow depth (default: 1) |
|
|
432
|
+
|
|
433
|
+
### queryGrep({ documents, query, contextLines? })
|
|
434
|
+
|
|
435
|
+
Execute full-text grep over documents.
|
|
436
|
+
|
|
437
|
+
```javascript
|
|
438
|
+
import { queryGrep } from '@a5c-ai/krate-sdk';
|
|
439
|
+
|
|
440
|
+
const result = queryGrep({
|
|
441
|
+
documents: [{ id: 'doc1', content: 'Agent memory stores knowledge...' }],
|
|
442
|
+
query: 'knowledge',
|
|
443
|
+
contextLines: 2
|
|
444
|
+
});
|
|
445
|
+
// { matches: [...], totalMatches: number }
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### queryMemory({ records, documents, edges, query, mode, kinds?, depth?, contextLines? })
|
|
449
|
+
|
|
450
|
+
Combined graph + grep query.
|
|
451
|
+
|
|
452
|
+
```javascript
|
|
453
|
+
import { queryMemory } from '@a5c-ai/krate-sdk';
|
|
454
|
+
|
|
455
|
+
const result = queryMemory({
|
|
456
|
+
records,
|
|
457
|
+
documents,
|
|
458
|
+
edges,
|
|
459
|
+
query: 'agent design',
|
|
460
|
+
mode: 'graph-and-grep', // 'graph-only' | 'grep-only' | 'graph-and-grep'
|
|
461
|
+
kinds: [],
|
|
462
|
+
depth: 1,
|
|
463
|
+
contextLines: 3
|
|
464
|
+
});
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
### Memory Import Utilities
|
|
468
|
+
|
|
469
|
+
Source: `packages/krate/core/src/agent-memory-import.js`
|
|
470
|
+
|
|
471
|
+
```javascript
|
|
472
|
+
import {
|
|
473
|
+
parseJournalForImport,
|
|
474
|
+
createMemorySnapshot,
|
|
475
|
+
validateMemoryImport,
|
|
476
|
+
validateMemorySnapshot,
|
|
477
|
+
validateOntology,
|
|
478
|
+
getOntologyNodeKinds,
|
|
479
|
+
getOntologyEdgeKinds
|
|
480
|
+
} from '@a5c-ai/krate-sdk';
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
| Function | Description |
|
|
484
|
+
|----------|-------------|
|
|
485
|
+
| `parseJournalForImport(journal)` | Parse babysitter run journal for importable data |
|
|
486
|
+
| `createMemorySnapshot(options)` | Create an AgentMemorySnapshot resource |
|
|
487
|
+
| `validateMemoryImport(importResource)` | Validate an AgentRunMemoryImport |
|
|
488
|
+
| `validateMemorySnapshot(snapshot)` | Validate an AgentMemorySnapshot |
|
|
489
|
+
| `validateOntology(ontology)` | Validate an AgentMemoryOntology |
|
|
490
|
+
| `getOntologyNodeKinds(ontology)` | Extract valid node kinds from ontology |
|
|
491
|
+
| `getOntologyEdgeKinds(ontology)` | Extract valid edge kinds from ontology |
|
|
492
|
+
|
|
493
|
+
---
|
|
494
|
+
|
|
495
|
+
## 7. External Backend Controllers
|
|
496
|
+
|
|
497
|
+
### createWebhookController(options?)
|
|
498
|
+
|
|
499
|
+
Source: `packages/krate/core/src/external/webhook-controller.js`
|
|
500
|
+
|
|
501
|
+
```javascript
|
|
502
|
+
import { createWebhookController } from '@a5c-ai/krate-sdk';
|
|
503
|
+
const webhookCtrl = createWebhookController({ secret: 'webhook-secret' });
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
**Methods:**
|
|
507
|
+
- `verifySignature(body, signature)` — HMAC-SHA256 verification → `{ valid, reason }`
|
|
508
|
+
- `createDelivery(event)` — Create delivery record with dedup
|
|
509
|
+
- `subscribe(handler)` — Subscribe to delivery events
|
|
510
|
+
- `getDelivery(id)` — Get delivery by ID
|
|
511
|
+
- `listDeliveries()` — List all deliveries
|
|
512
|
+
|
|
513
|
+
### createSyncController()
|
|
514
|
+
|
|
515
|
+
Source: `packages/krate/core/src/external/sync-controller.js`
|
|
516
|
+
|
|
517
|
+
```javascript
|
|
518
|
+
import { createSyncController } from '@a5c-ai/krate-sdk';
|
|
519
|
+
const syncCtrl = createSyncController();
|
|
520
|
+
```
|
|
521
|
+
|
|
522
|
+
**Methods:**
|
|
523
|
+
- `processSync(event)` — Process sync event, update state
|
|
524
|
+
- `getSyncState(provider, resource)` — Get current sync state
|
|
525
|
+
- `listSyncEvents(options)` — List events with filtering
|
|
526
|
+
|
|
527
|
+
### createWriteController()
|
|
528
|
+
|
|
529
|
+
Source: `packages/krate/core/src/external/write-controller.js`
|
|
530
|
+
|
|
531
|
+
```javascript
|
|
532
|
+
import { createWriteController } from '@a5c-ai/krate-sdk';
|
|
533
|
+
const writeCtrl = createWriteController();
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
**Methods:**
|
|
537
|
+
- `createWriteIntent(options)` — Queue write-back intent
|
|
538
|
+
- `approveIntent(name, approvedBy)` — Approve for execution
|
|
539
|
+
- `cancelIntent(name, cancelledBy)` — Cancel intent
|
|
540
|
+
- `listIntents(options)` — List pending intents
|
|
541
|
+
|
|
542
|
+
### createConflictController()
|
|
543
|
+
|
|
544
|
+
Source: `packages/krate/core/src/external/conflict-controller.js`
|
|
545
|
+
|
|
546
|
+
```javascript
|
|
547
|
+
import { createConflictController } from '@a5c-ai/krate-sdk';
|
|
548
|
+
const conflictCtrl = createConflictController();
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
**Methods:**
|
|
552
|
+
- `detectConflict(local, external)` — Compare and detect conflicts
|
|
553
|
+
- `resolveConflict(name, strategy, resolvedValue)` — Resolve with strategy
|
|
554
|
+
- `listConflicts(options)` — List unresolved conflicts
|
|
555
|
+
|
|
556
|
+
### createDefaultProviderRegistry()
|
|
557
|
+
|
|
558
|
+
Source: `packages/krate/core/src/external/provider-resource-factory.js`
|
|
559
|
+
|
|
560
|
+
```javascript
|
|
561
|
+
import { createDefaultProviderRegistry, createExternalBackendProvider } from '@a5c-ai/krate-sdk';
|
|
562
|
+
const registry = createDefaultProviderRegistry();
|
|
563
|
+
```
|
|
564
|
+
|
|
565
|
+
---
|
|
566
|
+
|
|
567
|
+
## 8. Event System
|
|
568
|
+
|
|
569
|
+
Source: `packages/krate/core/src/event-bus.js`
|
|
570
|
+
|
|
571
|
+
### globalEventBus
|
|
572
|
+
|
|
573
|
+
Singleton event bus instance.
|
|
574
|
+
|
|
575
|
+
```javascript
|
|
576
|
+
import { globalEventBus } from '@a5c-ai/krate-sdk';
|
|
577
|
+
|
|
578
|
+
globalEventBus.subscribe((event) => {
|
|
579
|
+
console.log('Event:', event.type, event.kind, event.name);
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
globalEventBus.emit({ type: 'resource-change', kind: 'Repository', name: 'my-repo', operation: 'apply' });
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
### createEventBus()
|
|
586
|
+
|
|
587
|
+
Create a new isolated event bus.
|
|
588
|
+
|
|
589
|
+
```javascript
|
|
590
|
+
import { createEventBus } from '@a5c-ai/krate-sdk';
|
|
591
|
+
const bus = createEventBus();
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
**Methods:**
|
|
595
|
+
| Method | Signature | Description |
|
|
596
|
+
|--------|-----------|-------------|
|
|
597
|
+
| `subscribe(fn)` | `(fn: (event) => void) => void` | Add listener |
|
|
598
|
+
| `unsubscribe(fn)` | `(fn: Function) => void` | Remove listener |
|
|
599
|
+
| `emit(event)` | `(event: object) => void` | Broadcast to all |
|
|
600
|
+
| `emitResourceChange(kind, name, operation)` | `(kind, name, op) => void` | Emit resource-change event |
|
|
601
|
+
|
|
602
|
+
---
|
|
603
|
+
|
|
604
|
+
## 9. Audit
|
|
605
|
+
|
|
606
|
+
Source: `packages/krate/core/src/audit-controller.js`
|
|
607
|
+
|
|
608
|
+
### createAuditController()
|
|
609
|
+
|
|
610
|
+
```javascript
|
|
611
|
+
import { createAuditController } from '@a5c-ai/krate-sdk';
|
|
612
|
+
const audit = createAuditController();
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
**Methods:**
|
|
616
|
+
- `record(event)` — Record an audit event
|
|
617
|
+
- `query(options)` — Query events by org, action, time range, pagination
|
|
618
|
+
|
|
619
|
+
### createEventPoller(options)
|
|
620
|
+
|
|
621
|
+
Polling mechanism for audit event consumption.
|
|
622
|
+
|
|
623
|
+
---
|
|
624
|
+
|
|
625
|
+
## 10. Async Utilities
|
|
626
|
+
|
|
627
|
+
Source: `packages/krate/core/src/async-controller.js`
|
|
628
|
+
|
|
629
|
+
### createEventBatcher(handler, options?)
|
|
630
|
+
|
|
631
|
+
Batch events with size and time-based flushing.
|
|
632
|
+
|
|
633
|
+
```javascript
|
|
634
|
+
import { createEventBatcher } from '@a5c-ai/krate-sdk';
|
|
635
|
+
|
|
636
|
+
const batcher = createEventBatcher(async (events) => {
|
|
637
|
+
await saveAll(events);
|
|
638
|
+
}, { maxBatchSize: 50, flushIntervalMs: 1000 });
|
|
639
|
+
|
|
640
|
+
batcher.push(event);
|
|
641
|
+
await batcher.flush();
|
|
642
|
+
batcher.stop();
|
|
643
|
+
```
|
|
644
|
+
|
|
645
|
+
**Options:** `{ maxBatchSize: 50, flushIntervalMs: 1000 }`
|
|
646
|
+
**Returns:** `{ push(event), flush(), stop() }`
|
|
647
|
+
|
|
648
|
+
### createRetryPolicy(options?)
|
|
649
|
+
|
|
650
|
+
Retry operations with exponential backoff and jitter.
|
|
651
|
+
|
|
652
|
+
```javascript
|
|
653
|
+
import { createRetryPolicy } from '@a5c-ai/krate-sdk';
|
|
654
|
+
const retry = createRetryPolicy({ maxRetries: 3, baseDelayMs: 100 });
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
### createDeliveryQueue(options?)
|
|
658
|
+
|
|
659
|
+
Ordered async delivery queue with error isolation.
|
|
660
|
+
|
|
661
|
+
```javascript
|
|
662
|
+
import { createDeliveryQueue } from '@a5c-ai/krate-sdk';
|
|
663
|
+
const queue = createDeliveryQueue({ concurrency: 5 });
|
|
664
|
+
```
|
|
665
|
+
|
|
666
|
+
### createCheckpointer(options?)
|
|
667
|
+
|
|
668
|
+
Checkpoint and resume for long-running operations.
|
|
669
|
+
|
|
670
|
+
```javascript
|
|
671
|
+
import { createCheckpointer } from '@a5c-ai/krate-sdk';
|
|
672
|
+
const cp = createCheckpointer({ storageKey: 'sync-progress' });
|
|
673
|
+
```
|
|
674
|
+
|
|
675
|
+
---
|
|
676
|
+
|
|
677
|
+
## 11. Other Utilities
|
|
678
|
+
|
|
679
|
+
### Runner Controller
|
|
680
|
+
|
|
681
|
+
Source: `packages/krate/core/src/runner-controller.js`
|
|
682
|
+
|
|
683
|
+
```javascript
|
|
684
|
+
import { createRunnerController } from '@a5c-ai/krate-sdk';
|
|
685
|
+
const runners = createRunnerController();
|
|
686
|
+
```
|
|
687
|
+
|
|
688
|
+
### Notification Controller
|
|
689
|
+
|
|
690
|
+
Source: `packages/krate/core/src/notification-controller.js`
|
|
691
|
+
|
|
692
|
+
```javascript
|
|
693
|
+
import { createNotificationController } from '@a5c-ai/krate-sdk';
|
|
694
|
+
const notifications = createNotificationController();
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
### Org Scoping
|
|
698
|
+
|
|
699
|
+
Source: `packages/krate/core/src/org-scoping.js`
|
|
700
|
+
|
|
701
|
+
```javascript
|
|
702
|
+
import { orgNamespaceName, normalizeOrgSlug } from '@a5c-ai/krate-sdk';
|
|
703
|
+
|
|
704
|
+
orgNamespaceName('acme'); // 'krate-org-acme'
|
|
705
|
+
normalizeOrgSlug('Acme Inc'); // 'acme-inc'
|
|
706
|
+
```
|
|
707
|
+
|
|
708
|
+
### Permission Review
|
|
709
|
+
|
|
710
|
+
Source: `packages/krate/core/src/agent-permission-review.js`
|
|
711
|
+
|
|
712
|
+
```javascript
|
|
713
|
+
import { createPermissionReviewer } from '@a5c-ai/krate-sdk';
|
|
714
|
+
const reviewer = createPermissionReviewer();
|
|
715
|
+
const result = reviewer.reviewPermissions({ repository, ref, actor, agentStack, resources });
|
|
716
|
+
```
|
|
717
|
+
|
|
718
|
+
### Secret/Config Grant Management
|
|
719
|
+
|
|
720
|
+
Source: `packages/krate/core/src/agent-secret-config-grant-controller.js`
|
|
721
|
+
|
|
722
|
+
```javascript
|
|
723
|
+
import {
|
|
724
|
+
createAgentSecretGrantController,
|
|
725
|
+
createAgentConfigGrantController,
|
|
726
|
+
validateAgentSecretGrant,
|
|
727
|
+
validateAgentConfigGrant,
|
|
728
|
+
listGrantsForAgent,
|
|
729
|
+
revokeGrant
|
|
730
|
+
} from '@a5c-ai/krate-sdk';
|
|
731
|
+
```
|
|
732
|
+
|
|
733
|
+
### Gitea Service
|
|
734
|
+
|
|
735
|
+
Source: `packages/krate/core/src/gitea-service.js`
|
|
736
|
+
|
|
737
|
+
```javascript
|
|
738
|
+
import { createGiteaService } from '@a5c-ai/krate-sdk';
|
|
739
|
+
const gitea = createGiteaService({ baseUrl: 'http://gitea:3000', token: '...' });
|
|
740
|
+
```
|
|
741
|
+
|
|
742
|
+
### Atlas Graph Client
|
|
743
|
+
|
|
744
|
+
Source: `packages/krate/sdk/src/atlas-graph-client.js`
|
|
745
|
+
|
|
746
|
+
```javascript
|
|
747
|
+
import { fetchAtlasRecordsByKinds, searchAtlasGraph, STACK_LAYERS, COMPOSITION_FACETS, ALL_LAYER_DEFS } from '@a5c-ai/krate-sdk';
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
| Export | Description |
|
|
751
|
+
|--------|-------------|
|
|
752
|
+
| `fetchAtlasRecordsByKinds(kinds, options)` | Fetch graph records by node kinds |
|
|
753
|
+
| `searchAtlasGraph(query, options)` | Full-text search across Atlas graph |
|
|
754
|
+
| `STACK_LAYERS` | Stack layer definitions |
|
|
755
|
+
| `COMPOSITION_FACETS` | Composition facet catalog |
|
|
756
|
+
| `ALL_LAYER_DEFS` | All layer definition objects |
|
|
757
|
+
|
|
758
|
+
### Controller Client
|
|
759
|
+
|
|
760
|
+
Source: `packages/krate/core/src/controller-client.js`
|
|
761
|
+
|
|
762
|
+
```javascript
|
|
763
|
+
import { fetchControllerUiModel } from '@a5c-ai/krate-sdk';
|
|
764
|
+
const uiModel = await fetchControllerUiModel({ baseUrl: 'http://localhost:3080', org: 'acme' });
|
|
765
|
+
```
|
|
766
|
+
|
|
767
|
+
### Snapshot Cache
|
|
768
|
+
|
|
769
|
+
Source: `packages/krate/core/src/snapshot-cache.js`
|
|
770
|
+
|
|
771
|
+
```javascript
|
|
772
|
+
import { clearSnapshotCache } from '@a5c-ai/krate-sdk';
|
|
773
|
+
clearSnapshotCache(); // Invalidate all cached data
|
|
774
|
+
```
|
|
775
|
+
|
|
776
|
+
### Identity Policy
|
|
777
|
+
|
|
778
|
+
Source: `packages/krate/core/src/identity-policy.js`
|
|
779
|
+
|
|
780
|
+
```javascript
|
|
781
|
+
import { mapOidcIdentity } from '@a5c-ai/krate-sdk';
|
|
782
|
+
```
|