create-relkit 0.7.4 → 0.7.6
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/dist/create-capabilities.d.ts +24 -33
- package/dist/create-capabilities.d.ts.map +1 -1
- package/dist/create-capabilities.js +52 -9
- package/dist/create-capabilities.js.map +1 -1
- package/dist/create-capabilities.types.d.ts +55 -0
- package/dist/create-capabilities.types.d.ts.map +1 -0
- package/dist/create-capabilities.types.js +2 -0
- package/dist/create-capabilities.types.js.map +1 -0
- package/dist/domain-artifact.d.ts.map +1 -1
- package/dist/domain-artifact.js +11 -3
- package/dist/domain-artifact.js.map +1 -1
- package/dist/domain-planning.d.ts +5 -0
- package/dist/domain-planning.d.ts.map +1 -1
- package/dist/domain-planning.js +25 -16
- package/dist/domain-planning.js.map +1 -1
- package/dist/generate-deployment-manifest.d.ts +10 -0
- package/dist/generate-deployment-manifest.d.ts.map +1 -0
- package/dist/generate-deployment-manifest.js +56 -0
- package/dist/generate-deployment-manifest.js.map +1 -0
- package/dist/generate-deployment.d.ts +2 -3
- package/dist/generate-deployment.d.ts.map +1 -1
- package/dist/generate-deployment.js +6 -47
- package/dist/generate-deployment.js.map +1 -1
- package/dist/generate-examples.d.ts +11 -0
- package/dist/generate-examples.d.ts.map +1 -0
- package/dist/generate-examples.js +28 -0
- package/dist/generate-examples.js.map +1 -0
- package/dist/generate-files-utilities.d.ts +1 -8
- package/dist/generate-files-utilities.d.ts.map +1 -1
- package/dist/generate-files-utilities.js +5 -19
- package/dist/generate-files-utilities.js.map +1 -1
- package/dist/project-discovery-artifacts.d.ts +15 -0
- package/dist/project-discovery-artifacts.d.ts.map +1 -0
- package/dist/project-discovery-artifacts.js +107 -0
- package/dist/project-discovery-artifacts.js.map +1 -0
- package/dist/project-discovery-artifacts.types.d.ts +22 -0
- package/dist/project-discovery-artifacts.types.d.ts.map +1 -0
- package/dist/project-discovery-artifacts.types.js +2 -0
- package/dist/project-discovery-artifacts.types.js.map +1 -0
- package/dist/project-discovery-facts.d.ts +8 -9
- package/dist/project-discovery-facts.d.ts.map +1 -1
- package/dist/project-discovery-facts.js +29 -135
- package/dist/project-discovery-facts.js.map +1 -1
- package/dist/project-discovery-members.d.ts +16 -0
- package/dist/project-discovery-members.d.ts.map +1 -0
- package/dist/project-discovery-members.js +57 -0
- package/dist/project-discovery-members.js.map +1 -0
- package/dist/project-discovery-types.d.ts +8 -0
- package/dist/project-discovery-types.d.ts.map +1 -1
- package/dist/render-auth-database.d.ts +33 -0
- package/dist/render-auth-database.d.ts.map +1 -0
- package/dist/render-auth-database.js +69 -0
- package/dist/render-auth-database.js.map +1 -0
- package/dist/render-auth-sources.d.ts +8 -2
- package/dist/render-auth-sources.d.ts.map +1 -1
- package/dist/render-auth-sources.js +9 -3
- package/dist/render-auth-sources.js.map +1 -1
- package/dist/render-auth.d.ts +14 -11
- package/dist/render-auth.d.ts.map +1 -1
- package/dist/render-auth.js +41 -108
- package/dist/render-auth.js.map +1 -1
- package/dist/render-database-sources.d.ts +7 -1
- package/dist/render-database-sources.d.ts.map +1 -1
- package/dist/render-database-sources.js +3 -2
- package/dist/render-database-sources.js.map +1 -1
- package/dist/render-database.d.ts +7 -10
- package/dist/render-database.d.ts.map +1 -1
- package/dist/render-database.js +12 -4
- package/dist/render-database.js.map +1 -1
- package/dist/render-database.types.d.ts +15 -0
- package/dist/render-database.types.d.ts.map +1 -0
- package/dist/render-database.types.js +2 -0
- package/dist/render-database.types.js.map +1 -0
- package/dist/render-route-sources.d.ts +3 -1
- package/dist/render-route-sources.d.ts.map +1 -1
- package/dist/render-route-sources.js +4 -2
- package/dist/render-route-sources.js.map +1 -1
- package/dist/render-routes.d.ts +1 -0
- package/dist/render-routes.d.ts.map +1 -1
- package/dist/render-routes.js +2 -1
- package/dist/render-routes.js.map +1 -1
- package/dist/render-service-members.d.ts +32 -0
- package/dist/render-service-members.d.ts.map +1 -0
- package/dist/render-service-members.js +61 -0
- package/dist/render-service-members.js.map +1 -0
- package/dist/render-service-requests.d.ts +35 -0
- package/dist/render-service-requests.d.ts.map +1 -0
- package/dist/render-service-requests.js +62 -0
- package/dist/render-service-requests.js.map +1 -0
- package/dist/render-service-support.d.ts +37 -0
- package/dist/render-service-support.d.ts.map +1 -0
- package/dist/render-service-support.js +74 -0
- package/dist/render-service-support.js.map +1 -0
- package/dist/render-service.d.ts +16 -13
- package/dist/render-service.d.ts.map +1 -1
- package/dist/render-service.js +33 -149
- package/dist/render-service.js.map +1 -1
- package/dist/render-service.types.d.ts +13 -0
- package/dist/render-service.types.d.ts.map +1 -0
- package/dist/render-service.types.js +2 -0
- package/dist/render-service.types.js.map +1 -0
- package/dist/scaffold-layout.d.ts +10 -0
- package/dist/scaffold-layout.d.ts.map +1 -0
- package/dist/scaffold-layout.js +29 -0
- package/dist/scaffold-layout.js.map +1 -0
- package/dist/templates/default/README.md +1 -1
- package/dist/templates/default/v1/agent/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/agent/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/agent/README.md +9 -0
- package/dist/templates/default/v1/agent/package.json +4 -4
- package/dist/templates/default/v1/agent/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/agents/assistant.agent.ts +2 -1
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/agents/review.agent.ts +1 -0
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/functions/hello.function.ts +7 -0
- package/dist/templates/default/v1/agent/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/agent/src/{hello → services/hello}/tools/lookup.tool.ts +2 -1
- package/dist/templates/default/v1/agent/tests/fixtures/lookup.tool.ts +2 -1
- package/dist/templates/default/v1/agent/tests/fixtures/mcp-options.ts +2 -1
- package/dist/templates/default/v1/agent/tests/unit/assistant.agent.test.ts +3 -2
- package/dist/templates/default/v1/agent/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/agent/tests/unit/lookup.tool.test.ts +2 -1
- package/dist/templates/default/v1/agent/tests/unit/review.agent.test.ts +2 -1
- package/dist/templates/default/v1/agent/tsconfig.json +1 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/api/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/api/README.md +10 -0
- package/dist/templates/default/v1/api/package.json +3 -3
- package/dist/templates/default/v1/api/src/routes/echo/route.ts +2 -1
- package/dist/templates/default/v1/api/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/api/src/routes/orders/route.ts +2 -1
- package/dist/templates/default/v1/api/src/{echo → services/echo}/functions/echo.function.ts +1 -0
- package/dist/templates/default/v1/api/src/services/echo/service.ts +5 -0
- package/dist/templates/default/v1/api/src/{hello → services/hello}/functions/hello.function.ts +7 -0
- package/dist/templates/default/v1/api/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/api/src/{orders → services/orders}/functions/create-order.function.ts +2 -1
- package/dist/templates/default/v1/api/src/{orders → services/orders}/functions/price-order.function.ts +1 -0
- package/dist/templates/default/v1/api/src/services/orders/service.ts +8 -0
- package/dist/templates/default/v1/api/tests/unit/echo.function.test.ts +2 -1
- package/dist/templates/default/v1/api/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/api/tests/unit/orders.function.test.ts +2 -1
- package/dist/templates/default/v1/api/tsconfig.json +1 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/fullstack/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/fullstack/README.md +9 -0
- package/dist/templates/default/v1/fullstack/package.json +5 -5
- package/dist/templates/default/v1/fullstack/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/agents/assistant.agent.ts +2 -1
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/agents/review.agent.ts +1 -0
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/functions/hello.function.ts +1 -0
- package/dist/templates/default/v1/fullstack/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/fullstack/src/{hello → services/hello}/tools/lookup.tool.ts +2 -1
- package/dist/templates/default/v1/fullstack/tests/unit/assistant.agent.test.ts +3 -2
- package/dist/templates/default/v1/fullstack/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/fullstack/tests/unit/review.agent.test.ts +2 -1
- package/dist/templates/default/v1/fullstack/tsconfig.json +1 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/minimal/README.md +10 -0
- package/dist/templates/default/v1/minimal/package.json +3 -3
- package/dist/templates/default/v1/minimal/src/routes/hello/route.ts +2 -1
- package/dist/templates/default/v1/minimal/src/{hello → services/hello}/functions/hello.function.ts +7 -0
- package/dist/templates/default/v1/minimal/src/services/hello/service.ts +5 -0
- package/dist/templates/default/v1/minimal/tests/unit/hello.function.test.ts +2 -1
- package/dist/templates/default/v1/minimal/tsconfig.json +1 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/SKILL.md +48 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/agent-apis.md +59 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/cli.md +63 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/config-environments.md +96 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/data-apis.md +74 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/domain-apis.md +92 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/http-apis.md +70 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/jobs-apis.md +49 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/layout-migration.md +35 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/observability-apis.md +53 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/realtime-apis.md +98 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/streaming-apis.md +75 -0
- package/dist/templates/default/v1/tasks/.agents/skills/relkit/references/testing-apis.md +71 -0
- package/dist/templates/default/v1/tasks/README.md +8 -1
- package/dist/templates/default/v1/tasks/package.json +3 -3
- package/dist/templates/default/v1/tasks/src/routes/health/route.ts +2 -1
- package/dist/templates/default/v1/tasks/src/{orders → services/orders}/functions/health.function.ts +1 -0
- package/dist/templates/default/v1/tasks/src/{orders → services/orders}/jobs/export-orders.job.ts +2 -1
- package/dist/templates/default/v1/tasks/src/services/orders/service.ts +11 -0
- package/dist/templates/default/v1/tasks/src/{orders → services/orders}/tasks/export-orders.task.ts +1 -0
- package/dist/templates/default/v1/tasks/tests/unit/export-orders.task.test.ts +2 -1
- package/dist/templates/default/v1/tasks/tsconfig.json +2 -0
- package/package.json +3 -3
- package/dist/templates/default/v1/agent/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/api/src/echo/service.ts +0 -4
- package/dist/templates/default/v1/api/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/api/src/orders/service.ts +0 -7
- package/dist/templates/default/v1/fullstack/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/minimal/src/hello/service.ts +0 -4
- package/dist/templates/default/v1/tasks/src/orders/service.ts +0 -10
package/dist/templates/default/v1/minimal/.agents/skills/relkit/references/observability-apis.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Observability and tracing
|
|
2
|
+
|
|
3
|
+
RELKIT records HTTP requests and invocation spans automatically. Use `context.log` for structured application records and `context.trace` for application work inside an existing function that needs more detail.
|
|
4
|
+
|
|
5
|
+
## Log and trace inside a function
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { defineFunction } from "@relkit/app/functions";
|
|
9
|
+
import { z } from "@relkit/app/schema";
|
|
10
|
+
|
|
11
|
+
export default defineFunction({
|
|
12
|
+
id: "orders.total",
|
|
13
|
+
input: z.object({ quantity: z.number().int().positive() }),
|
|
14
|
+
output: z.object({ totalCents: z.number().int().nonnegative() }),
|
|
15
|
+
handler: async ({ quantity }, context) => {
|
|
16
|
+
const totalCents = await context.trace.span(
|
|
17
|
+
"pricing.calculate",
|
|
18
|
+
{ attributes: { "pricing.strategy": "catalog" } },
|
|
19
|
+
async () => quantity * 1_000,
|
|
20
|
+
);
|
|
21
|
+
context.trace.event("pricing.calculated", { "pricing.total_cents": totalCents });
|
|
22
|
+
context.trace.setAttributes({ "pricing.quantity": quantity });
|
|
23
|
+
context.log.info("orders.total.calculated", { quantity, totalCents });
|
|
24
|
+
return { totalCents };
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`span(name, callback)` creates an internal child span; `span(name, { attributes, kind }, callback)` adds attributes and an `internal` or `client` kind. `event(name, attributes?)` adds an event to the active span, and `setAttributes` annotates it. RELKIT ends child spans on success or failure. Attribute values must be strings, finite numbers, or booleans. Do not log secrets or put payloads or random IDs in span attributes.
|
|
30
|
+
|
|
31
|
+
## Configure capture and export
|
|
32
|
+
|
|
33
|
+
Edit the existing `relkit.config.ts` and preserve its environment and provider settings:
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { defineApp } from "@relkit/app/config";
|
|
37
|
+
import env from "@app/platform/env.js";
|
|
38
|
+
|
|
39
|
+
export default defineApp({
|
|
40
|
+
env,
|
|
41
|
+
telemetry: {
|
|
42
|
+
redaction: { mode: "development-redacted", maxBytes: 65_536 },
|
|
43
|
+
localRetention: { maxRecords: 2_000, maxAgeMs: 3_600_000, maxBytes: 16_777_216 },
|
|
44
|
+
exportSampling: { traceRate: 0.25, minimumLogLevel: "info" },
|
|
45
|
+
},
|
|
46
|
+
server: { port: 3000 },
|
|
47
|
+
inspector: { port: 3210 },
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The template already supplies redaction. `localRetention` bounds development history; `exportSampling` controls remote export independently of local capture. Add named Sentry or OTLP exporters only when those integrations and their secret environment bindings are configured. Redact before storage or export. No `relkit add observability` kind exists; configure `telemetry` in `defineApp`.
|
|
52
|
+
|
|
53
|
+
Run `bun run dev`, make one identifiable HTTP request, then inspect Requests, Traces, and Logs in the Inspector. Use `bun run dev -- --verbose` for DEBUG terminal output or `--json` for structured terminal records. Development history is stored in `.relkit/observability/observability.duckdb`; this is diagnostic history, not business storage.
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Realtime channels
|
|
2
|
+
|
|
3
|
+
Use a channel to notify connected clients about a change. Keep the authoritative state in a route or database query; use channel events to refresh or update that state. Application events deliver backend work, while channels deliver live client updates.
|
|
4
|
+
|
|
5
|
+
## `defineChannel`
|
|
6
|
+
|
|
7
|
+
Create `src/services/announcements/channels/announcements.channel.ts`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineChannel } from "@relkit/app/realtime";
|
|
11
|
+
import { z } from "@relkit/app/schema";
|
|
12
|
+
|
|
13
|
+
const announcements = defineChannel({
|
|
14
|
+
id: "announcements.feed",
|
|
15
|
+
params: z.object({}),
|
|
16
|
+
events: { posted: z.object({ message: z.string(), postedAt: z.string() }) },
|
|
17
|
+
client: { public: true },
|
|
18
|
+
replay: { retentionMs: 300_000, maxEvents: 1_000 },
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
export default announcements;
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`params` selects a partition, `events` validates named payloads, and `client` controls browser exposure. Omit `client` for backend-only channels. Use `client: { authorize: async (params, context) => ... }` for protected partitions and verify access to the specific resource, not merely that a session exists. `presence: "count"` adds connection counts. A channel with no events must declare presence.
|
|
25
|
+
|
|
26
|
+
## Publish and subscribe
|
|
27
|
+
|
|
28
|
+
After the application change succeeds, publish one validated event from a backend function:
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { defineFunction } from "@relkit/app/functions";
|
|
32
|
+
import { z } from "@relkit/app/schema";
|
|
33
|
+
import announcements from "@app/services/announcements/channels/announcements.channel.js";
|
|
34
|
+
|
|
35
|
+
export default defineFunction({
|
|
36
|
+
id: "announcements.post",
|
|
37
|
+
input: z.object({ message: z.string().min(1) }),
|
|
38
|
+
output: z.object({ accepted: z.literal(true) }),
|
|
39
|
+
handler: async ({ message }) => {
|
|
40
|
+
await announcements.trigger({}, "posted", {
|
|
41
|
+
message,
|
|
42
|
+
postedAt: new Date().toISOString(),
|
|
43
|
+
});
|
|
44
|
+
return { accepted: true as const };
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
The `trigger()` receipt confirms the provider accepted the append; it does not prove delivery to every browser. If a database write and publication must be atomic, use an outbox in the database transaction. A retryable publish can pass a RELKIT-issued `idempotencyKey` as the fourth argument.
|
|
50
|
+
|
|
51
|
+
In a React client with `@relkit/client`, subscribe using the generated channel registry:
|
|
52
|
+
|
|
53
|
+
```tsx
|
|
54
|
+
"use client";
|
|
55
|
+
|
|
56
|
+
import { useChannel, useRoute } from "@relkit/client/react";
|
|
57
|
+
|
|
58
|
+
export default function Announcements() {
|
|
59
|
+
const announcements = useRoute("GET /announcements", { input: {} });
|
|
60
|
+
const channel = useChannel("announcements.feed", {
|
|
61
|
+
params: {},
|
|
62
|
+
on: { posted: () => void announcements.refetch() },
|
|
63
|
+
onCaughtUp: async () => {
|
|
64
|
+
await announcements.refetch();
|
|
65
|
+
},
|
|
66
|
+
onGap: async () => {
|
|
67
|
+
await announcements.refetch();
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
return <p>Channel: {channel.status}</p>;
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Load authoritative state through a route before relying on updates. `onGap` must restore it when replay cannot bridge a disconnect. `channel.status` and `channel.caughtUp` report connection and recovery state. `useRealtime()` is the lower-level subscription manager; a channel descriptor's `getPresence(params)` reads presence when declared.
|
|
76
|
+
|
|
77
|
+
## Provider and verification
|
|
78
|
+
|
|
79
|
+
Configure a compatible `realtime` provider and `defaults.realtime` in `relkit.config.ts`. For a one-machine app with `@relkit/local` installed, the relevant configuration is:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { defineApp } from "@relkit/app/config";
|
|
83
|
+
import { localRealtime } from "@relkit/local";
|
|
84
|
+
import env from "@app/platform/env.js";
|
|
85
|
+
|
|
86
|
+
export default defineApp({
|
|
87
|
+
env,
|
|
88
|
+
realtime: localRealtime(),
|
|
89
|
+
defaults: { realtime: "default" },
|
|
90
|
+
telemetry: { redaction: { mode: "development-redacted", maxBytes: 65_536 } },
|
|
91
|
+
server: { port: 3000 },
|
|
92
|
+
inspector: { port: 3210 },
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Merge these fields into an existing `defineApp` while preserving its other providers and settings. Redis supports fanout across application instances. Provider storage, retention, and Redis persistence determine recovery guarantees. Run `bun run check`, `bun run typecheck`, then test publication, browser subscription, reconnect, and gap recovery. Inspect channels in the Inspector while `bun run dev` is running.
|
|
97
|
+
|
|
98
|
+
The current `relkit add` kinds do not include `channel`. Create the descriptor and provider configuration in the app source.
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Streaming responses
|
|
2
|
+
|
|
3
|
+
Use a typed stream when one request returns a sequence to its caller. It ends with that request and can be cancelled. A realtime channel notifies connected clients across requests; a job watch follows one accepted background run. Agent and job content streams have their own client contracts.
|
|
4
|
+
|
|
5
|
+
## `streamOf` with `defineFunction`
|
|
6
|
+
|
|
7
|
+
Create a function in `src/services/reports/functions/stream-report.function.ts`:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineFunction, streamOf } from "@relkit/app/functions";
|
|
11
|
+
import { z } from "@relkit/app/schema";
|
|
12
|
+
|
|
13
|
+
export default defineFunction({
|
|
14
|
+
id: "reports.stream",
|
|
15
|
+
input: z.object({ reportId: z.string().min(1) }),
|
|
16
|
+
output: streamOf(z.object({ completed: z.number().int(), total: z.number().int() })),
|
|
17
|
+
handler: async function* (_input, context) {
|
|
18
|
+
for (let completed = 1; completed <= 10; completed += 1) {
|
|
19
|
+
if (context.signal.aborted) return;
|
|
20
|
+
yield { completed, total: 10 };
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
`streamOf(itemSchema)` validates each yielded item. The iterator is lazy and single-consumer; its invocation scope stays open until completion or cancellation. Expose this function from its domain service before mapping it to HTTP.
|
|
27
|
+
|
|
28
|
+
For protected data, read the authenticated session and enforce ownership inside the
|
|
29
|
+
function. Verify an authorized stream through the actual generated HTTP server to
|
|
30
|
+
its completion event, then check other users/tenants and cancellation cleanup.
|
|
31
|
+
Direct test-runtime invocation alone does not verify request context through lazy
|
|
32
|
+
iterator pulls. Keep public descriptors as plain TypeScript.
|
|
33
|
+
|
|
34
|
+
## `defineRoute` for a stream
|
|
35
|
+
|
|
36
|
+
In `src/routes/reports/[reportId]/route.ts`, import the public service member:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineRoute, http } from "@relkit/app/routes";
|
|
40
|
+
import reports from "@app/services/reports/service.js";
|
|
41
|
+
|
|
42
|
+
export const GET = defineRoute({
|
|
43
|
+
target: reports.streamReport,
|
|
44
|
+
request: http.input({ reportId: http.path("reportId") }),
|
|
45
|
+
client: { operation: "query" },
|
|
46
|
+
stream: { format: "sse" },
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A function-backed stream preserves typed items and failures with the managed client. Native SSE sends `relkit-item` events and an explicit completion or sanitized error event. For custom text, byte, or Web stream responses, use a raw `defineRoute({ handler })` and a Web `Response`. A raw response does not provide the managed item contract.
|
|
51
|
+
|
|
52
|
+
## `useStream` in React
|
|
53
|
+
|
|
54
|
+
With `@relkit/client` and a generated route registry:
|
|
55
|
+
|
|
56
|
+
```tsx
|
|
57
|
+
"use client";
|
|
58
|
+
|
|
59
|
+
import { useStream } from "@relkit/client/react";
|
|
60
|
+
|
|
61
|
+
export default function Report() {
|
|
62
|
+
const report = useStream("GET /reports/:reportId");
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<section>
|
|
66
|
+
<button onClick={() => void report.start({ reportId: "daily" })}>Start</button>
|
|
67
|
+
<button onClick={() => report.cancel()}>Cancel</button>
|
|
68
|
+
<p>Status: {report.status}</p>
|
|
69
|
+
<p>Items: {report.items.length}</p>
|
|
70
|
+
</section>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
`useStream` also exposes `reset`. Query-classified streams can opt into `autoStart`; mutation streams require an explicit `start`. Cancelling or ending iteration releases upstream work. Test item validation, normal completion, cancellation, and a failure after the first item by exercising the HTTP/client path.
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# Testing a RELKIT application
|
|
2
|
+
|
|
3
|
+
Generated projects use Bun's test runner and `@relkit/testing`. Start with the existing `tests/unit` and `tests/integration` examples, then test the boundary that owns the behavior. Keep external providers and test state explicit; `RELKIT_ENV=test` alone does not select fakes.
|
|
4
|
+
|
|
5
|
+
## Direct function tests
|
|
6
|
+
|
|
7
|
+
`invokeFunction` runs a function descriptor through RELKIT's input/output validation and handler path without an HTTP server. Import a service's public function through its `service.ts` when testing the public member:
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { expect, test } from "bun:test";
|
|
11
|
+
import { invokeFunction } from "@relkit/testing";
|
|
12
|
+
import orders from "@app/services/orders/service.js";
|
|
13
|
+
|
|
14
|
+
test("createOrder calculates its total", async () => {
|
|
15
|
+
await expect(
|
|
16
|
+
invokeFunction(orders.createOrder, { orderId: "order-1", sku: "book", quantity: 3 }),
|
|
17
|
+
).resolves.toEqual({ orderId: "order-1", sku: "book", totalCents: 300 });
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Pass explicit `env`, `context`, `clients`, or other `InvokeFunctionOptions` when the function needs them. Test invalid input and declared errors as well as success. Direct invocation does not test route mapping or middleware.
|
|
22
|
+
|
|
23
|
+
For several invocations that share a deterministic clock or provider state, use `createTestRuntime({ app, env, providers, startTimeMs })` and `runtime.invoke(target, input)`. `runtime.clock.advance(ms)` controls its test clock. Always `await runtime.close()` in `finally` or `afterAll`.
|
|
24
|
+
|
|
25
|
+
## Application and HTTP tests
|
|
26
|
+
|
|
27
|
+
`createTestApplication` discovers the generated project's routes and services. Pass its existing `relkit.config.ts`; `resourceProviders: "fake"` explicitly replaces graph-required resource providers for local tests:
|
|
28
|
+
|
|
29
|
+
```ts
|
|
30
|
+
import { afterAll, expect, test } from "bun:test";
|
|
31
|
+
import { createTestApplication } from "@relkit/testing";
|
|
32
|
+
import config from "../../relkit.config.js";
|
|
33
|
+
|
|
34
|
+
const app = await createTestApplication(config, { resourceProviders: "fake" });
|
|
35
|
+
afterAll(() => app.close());
|
|
36
|
+
|
|
37
|
+
test("POST /orders maps and validates input", async () => {
|
|
38
|
+
const response = await app.http.request("/orders", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "content-type": "application/json" },
|
|
41
|
+
body: JSON.stringify({ orderId: "order-1", sku: "book", quantity: 3 }),
|
|
42
|
+
});
|
|
43
|
+
expect(response.status).toBe(201);
|
|
44
|
+
expect(await response.json()).toEqual({ orderId: "order-1", sku: "book", totalCents: 300 });
|
|
45
|
+
});
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Use `app.http.request`, `get`, or other client methods to assert status, body, and headers. Add requests for invalid input, anonymous callers, and unauthorized resource access where relevant. The harness has `runtime`, `clock`, `fakes`, and `observability` for controlled state and inspection. Options include `env`, `environment`, `bindingValues`, `providers`, and `projectRoot`; use explicit values for test-only configuration. This in-process HTTP boundary does not prove the full production middleware, cookie/origin policy, OpenAPI, or network transport. Verify those against a running backend when relevant.
|
|
49
|
+
|
|
50
|
+
## Provider and feature tests
|
|
51
|
+
|
|
52
|
+
- `createTestCacheFake`, `createTestBucketFake`, `createTestJobFake`, and `createTestEventFake` provide owned, inspectable test dependencies. `createTestFakes` groups native clients. Close any separately created fake after use. Replace every configured provider profile the graph needs, not only the one under direct assertion.
|
|
53
|
+
- `createTestHttpClient` exercises a standalone in-memory HTTP application. Use `createTestApplication` when route discovery and service wiring matter. `createTestRealtimeProvider` and `createTestAgentStateProvider` supply local stateful provider replacements.
|
|
54
|
+
- `createTestModel`, `createTestAgent`, and `assertAgentTrace` support deterministic agent execution. Use scripted responses and inspect tool calls or traces instead of live model calls or sleeps.
|
|
55
|
+
- For jobs, assert behavior beyond the descriptor shape: input/output, accepted run handle, progress, retry or cancellation policy, and idempotency where applicable. Use the test job adapter or fake appropriate to the contract.
|
|
56
|
+
- For database and auth integration, migrate an isolated temporary database before starting the application. Supply both parsed RELKIT environment and any native auth process environment required by the provider; close the app before removing test-owned files. Test public and protected requests with real cookies and separate users. A direct function mock does not verify migrations, sessions, or route protection.
|
|
57
|
+
- For realtime, streaming, and observability, test the exposed route or channel contract and recorded events/spans as applicable. Use a running backend for actual transport, connection, and browser behavior.
|
|
58
|
+
|
|
59
|
+
## Run the generated project checks
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
bun test tests/unit/hello.function.test.ts
|
|
63
|
+
bun run test:unit
|
|
64
|
+
bun run test:integration
|
|
65
|
+
bun run test
|
|
66
|
+
bun run check
|
|
67
|
+
bun run typecheck
|
|
68
|
+
bun run build
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Run only scripts present in the generated `package.json`; the task template may have a different test layout. Keep Docker, external providers, and cloud acceptance as explicit integration gates. The installed `@relkit/testing` declarations and the project's existing tests are the source for exact helper options.
|
|
@@ -16,3 +16,13 @@ bun run build
|
|
|
16
16
|
|
|
17
17
|
The example route is `GET /hello?name=RelKit`. The default project needs no
|
|
18
18
|
Docker daemon, cloud account, or deployment credentials.
|
|
19
|
+
|
|
20
|
+
Hello lives in `src/services/hello/`, with its public boundary at `service.ts`
|
|
21
|
+
and behavior in `functions/hello.function.ts`. Routes stay in `src/routes/`;
|
|
22
|
+
shared configuration belongs in `src/platform/`. Public descriptors and
|
|
23
|
+
ordinary handlers remain plain TypeScript.
|
|
24
|
+
|
|
25
|
+
Creation with installation prepares development automatically. After
|
|
26
|
+
`--no-install`, run `bun install` and `bunx --no-install relkit dev --prepare`
|
|
27
|
+
before `bun run dev`. Existing flat applications remain supported; additions
|
|
28
|
+
preserve their root, and `bun run relkit migrate layout` previews an optional move.
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"graph": "relkit graph print"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@relkit/app": "0.7.
|
|
18
|
+
"@relkit/app": "0.7.6",
|
|
19
19
|
"effect": "4.0.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "1.3.10",
|
|
23
|
-
"@relkit/cli": "0.7.
|
|
24
|
-
"@relkit/testing": "0.7.
|
|
23
|
+
"@relkit/cli": "0.7.6",
|
|
24
|
+
"@relkit/testing": "0.7.6",
|
|
25
25
|
"typescript": "5.9.3"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
/** Maps the HTTP endpoint to its owning service's public member. */
|
|
1
2
|
import { defineRoute } from "@relkit/app/routes";
|
|
2
|
-
import hello from "@app/hello/service.js";
|
|
3
|
+
import hello from "@app/services/hello/service.js";
|
|
3
4
|
|
|
4
5
|
export const GET = defineRoute({
|
|
5
6
|
target: hello.hello,
|
package/dist/templates/default/v1/minimal/src/{hello → services/hello}/functions/hello.function.ts
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** Returns a validated named greeting and logs each invocation through RELKIT's request context. */
|
|
1
2
|
import { defineFunction } from "@relkit/app/functions";
|
|
2
3
|
import { z } from "@relkit/app/schema";
|
|
3
4
|
|
|
@@ -5,6 +6,12 @@ const hello = defineFunction({
|
|
|
5
6
|
id: "hello.greet",
|
|
6
7
|
input: z.object({ name: z.string().min(1).default("world") }),
|
|
7
8
|
output: z.object({ message: z.string() }),
|
|
9
|
+
/**
|
|
10
|
+
* Logs the greeting invocation and returns the validated greeting response.
|
|
11
|
+
* @param input - Validated name from the function schema.
|
|
12
|
+
* @param context - RELKIT invocation context owning structured logging.
|
|
13
|
+
* @returns Greeting response matching the output schema.
|
|
14
|
+
*/
|
|
8
15
|
handler: async ({ name }, context) => {
|
|
9
16
|
context.log.info("hello invoked", { name });
|
|
10
17
|
return { message: `Hello, ${name}!` };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
/** Checks hello.function through the supported public RELKIT APIs. */
|
|
1
2
|
import { expect, test } from "bun:test";
|
|
2
3
|
import { invokeFunction } from "@relkit/testing";
|
|
3
|
-
import hello from "@app/hello/functions/hello.function.js";
|
|
4
|
+
import hello from "@app/services/hello/functions/hello.function.js";
|
|
4
5
|
|
|
5
6
|
test("hello returns a greeting", async () => {
|
|
6
7
|
await expect(invokeFunction(hello, { name: "Mustafa" })).resolves.toEqual({
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: relkit
|
|
3
|
+
description: Build or extend a RELKIT CLI-generated application using its installed scaffolding and project commands. Use for application config, environments, services, functions, routes, auth, database, jobs, providers, and related app work.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Work in a RELKIT application
|
|
7
|
+
|
|
8
|
+
Run commands from the generated application's root, where `relkit.config.ts` and `package.json` live. Use `bun run relkit` to invoke the project's installed CLI. Check `bun run relkit <command> --help` before relying on an option, especially after a dependency upgrade.
|
|
9
|
+
|
|
10
|
+
## Source placement
|
|
11
|
+
|
|
12
|
+
New projects place every generic, database, and auth boundary at `src/services/<name>/service.ts`. Keep its functions, events, tasks, jobs, tools, agents, channels, schemas, resources, helpers, and assets under that service. Routes live at `src/routes`; configuration support and environment contracts live at `src/platform`. Application descriptors use plain TypeScript and supported public APIs; Effect imports are not required.
|
|
13
|
+
|
|
14
|
+
Existing flat projects with `src/<name>/service.ts` remain supported. `relkit add` preserves the detected layout; empty projects default to grouped. Never mix flat and grouped boundaries or add an aggregate `src/services/service.ts`. Across services and from routes, import only the destination's `service.ts`; Platform cannot import services or Routes. Ordinary helpers do not become independently discovered descriptors.
|
|
15
|
+
|
|
16
|
+
Read [layout migration](references/layout-migration.md) before moving an existing app. Keep logical IDs, exposure, provider profiles, and durable contract versions stable during a source-only move.
|
|
17
|
+
|
|
18
|
+
## Add application artifacts
|
|
19
|
+
|
|
20
|
+
Inspect the existing `src/` tree and `relkit.config.ts` before scaffolding. Prefer `relkit add` for supported artifacts, then edit the generated source for the required behavior. An interactive terminal can prompt for missing choices; scripts and noninteractive runs should provide the kind, name, service, route mode, and mappings explicitly.
|
|
21
|
+
|
|
22
|
+
Read [the CLI reference](references/cli.md) for commands and option patterns covering services, functions, routes, auth, database, and the other add kinds.
|
|
23
|
+
|
|
24
|
+
## Authoring API references
|
|
25
|
+
|
|
26
|
+
Read only the reference relevant to the requested change. These examples describe the template's public APIs; check the installed package's TypeScript declarations when an exact option or signature matters.
|
|
27
|
+
|
|
28
|
+
- [Application configuration and environments](references/config-environments.md)
|
|
29
|
+
- [Functions, services, events, and errors](references/domain-apis.md)
|
|
30
|
+
- [HTTP routes and request policy](references/http-apis.md)
|
|
31
|
+
- [Streaming responses](references/streaming-apis.md)
|
|
32
|
+
- [Tasks and jobs](references/jobs-apis.md)
|
|
33
|
+
- [Agents, tools, and prompts](references/agent-apis.md)
|
|
34
|
+
- [Database, auth, cache, and storage](references/data-apis.md)
|
|
35
|
+
- [Realtime channels](references/realtime-apis.md)
|
|
36
|
+
- [Observability and tracing](references/observability-apis.md)
|
|
37
|
+
- [Testing functions, routes, and providers](references/testing-apis.md)
|
|
38
|
+
|
|
39
|
+
## Working conventions
|
|
40
|
+
|
|
41
|
+
- Generic domain services own callable functions and public event contracts. Other domains and routes should import a service's public members through its `service.ts`.
|
|
42
|
+
- A service route maps HTTP methods to existing public callable members. A raw route is a standalone handler. The CLI will not overwrite an existing route file.
|
|
43
|
+
- Database and auth are singletons under `src/services/database` and `src/services/auth`; extend an existing one instead of creating another. Auth may create a database baseline if none exists. Scaffolding does not run migrations, create secrets, or provision cloud resources.
|
|
44
|
+
- Preserve existing application configuration, environment fields, service members, routes, and user changes when specializing generated files.
|
|
45
|
+
|
|
46
|
+
## Verify the result
|
|
47
|
+
|
|
48
|
+
Review the CLI's created and updated files, warnings, and next steps. Run `bun run check`, `bun run typecheck`, and focused tests after editing. For HTTP work, exercise the route itself; a direct function test does not cover request mapping. Database and auth work also needs the reported environment and migration steps before runtime verification.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Agents, tools, and prompts
|
|
2
|
+
|
|
3
|
+
| API | Import | Role |
|
|
4
|
+
| ----------------------------------------------- | -------------------- | ------------------------------------ |
|
|
5
|
+
| `defineAgent`, `defineGraph`, `defineGraphNode` | `@relkit/app/agents` | Model-driven agent or explicit graph |
|
|
6
|
+
| `defineTool` | `@relkit/app/tools` | Policy-controlled view of a function |
|
|
7
|
+
| `definePrompt` | `@relkit/app` | Reusable instructions |
|
|
8
|
+
| `z` | `@relkit/app/schema` | Agent and tool schemas |
|
|
9
|
+
|
|
10
|
+
## `defineAgent`
|
|
11
|
+
|
|
12
|
+
Use `defineAgent` when a model should choose among tools. The agent template provides an executable offline LangChain model example. This shortened form uses the same public options:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { defineAgent } from "@relkit/app/agents";
|
|
16
|
+
import { z } from "@relkit/app/schema";
|
|
17
|
+
import { FakeToolCallingModel } from "langchain";
|
|
18
|
+
import lookup from "@app/services/hello/tools/lookup.tool.js";
|
|
19
|
+
export default defineAgent({
|
|
20
|
+
id: "hello.assistant",
|
|
21
|
+
input: z.object({ message: z.string().min(1) }),
|
|
22
|
+
output: z.object({ answer: z.string() }),
|
|
23
|
+
model: new FakeToolCallingModel({
|
|
24
|
+
toolCalls: [[{ name: "relkit_output", args: { value: { answer: "Hello!" } }, id: "output-1" }]],
|
|
25
|
+
}),
|
|
26
|
+
instructions: "Answer greeting questions with the available tools.",
|
|
27
|
+
tools: [lookup],
|
|
28
|
+
limits: { maxSteps: 4, maxToolCalls: 4, timeoutMs: 10_000 },
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Other generated projects may need a native model package and application-owned provider configuration. `limits` requires positive `maxSteps`, `maxToolCalls`, and `timeoutMs`. `instructions` can be text or a `definePrompt` descriptor. A model can call only tools listed in the agent's `tools` array. A fixed sequence can be a function; a stateful explicit workflow can use `defineGraph` and `defineGraphNode`.
|
|
33
|
+
|
|
34
|
+
## `defineTool` and `definePrompt`
|
|
35
|
+
|
|
36
|
+
A RELKIT tool wraps a callable function without duplicating its schemas:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { defineTool } from "@relkit/app/tools";
|
|
40
|
+
import lookup from "@app/services/orders/functions/lookup.function.js";
|
|
41
|
+
export default defineTool({
|
|
42
|
+
id: "orders.lookup",
|
|
43
|
+
target: lookup,
|
|
44
|
+
description: "Look up an order by ID",
|
|
45
|
+
sideEffect: "read",
|
|
46
|
+
approval: "never",
|
|
47
|
+
timeoutMs: 2_000,
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { definePrompt } from "@relkit/app";
|
|
53
|
+
export default definePrompt("Answer using the available tools.", {
|
|
54
|
+
id: "hello.assistant-instructions",
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
`lookup.asTool({ ... })` is the alternate tool form. Choose accurate `sideEffect` (`none`, `read`, `write`, or `external`) and `approval` (`never`, `on-write`, or `always`) policies. Tools are available to MCP by default; set `mcp: false` when a tool should remain inside the app. Permission checks belong in application logic.
|
|
59
|
+
If a browser client needs an agent, configure its explicit `client` contract. Keep provider credentials and native model instances on the server. A typed agent run uses a stable thread ID; resume the same thread instead of creating a replacement run.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# CLI commands in a generated project
|
|
2
|
+
|
|
3
|
+
These examples use the local binary through `bun run relkit`. The installed CLI's `--help` is authoritative if its version differs from the template.
|
|
4
|
+
|
|
5
|
+
## Service and HTTP scaffolding
|
|
6
|
+
|
|
7
|
+
| Goal | Command |
|
|
8
|
+
| ---------------------------------------------- | ---------------------------------------------------------------------------------------------- |
|
|
9
|
+
| Create a domain with a public example function | `bun run relkit add service Billing` |
|
|
10
|
+
| Select extra domain artifacts | `bun run relkit add service Billing --include function --include error` |
|
|
11
|
+
| Create the full domain bundle | `bun run relkit add service Billing --full` |
|
|
12
|
+
| Add a public callable function | `bun run relkit add function "Send Receipt" --service billing` |
|
|
13
|
+
| Add a standalone GET handler | `bun run relkit add route '/status' --mode route` |
|
|
14
|
+
| Map an existing public member to HTTP | `bun run relkit add route '/billing' --mode service-route --service billing --map GET=example` |
|
|
15
|
+
|
|
16
|
+
`--include` is repeatable and exclusive with `--full`. `--service` selects an existing generic domain; `--create-service` creates it while adding an artifact. Use `--internal` on a function or event that should stay out of the public service API. A service route needs one or more `--map METHOD=member` values in noninteractive use; the member must be a public callable function. Quote paths containing `*` or `?`.
|
|
17
|
+
|
|
18
|
+
## Database and auth
|
|
19
|
+
|
|
20
|
+
| Goal | Command |
|
|
21
|
+
| -------------------------------------------- | ------------------------------------------------------------------------- |
|
|
22
|
+
| Scaffold a SQLite Drizzle service | `bun run relkit add database --orm drizzle --dialect sqlite` |
|
|
23
|
+
| Scaffold Better Auth and its catch-all route | `bun run relkit add auth --adapter better-auth --database-dialect sqlite` |
|
|
24
|
+
|
|
25
|
+
Database `--dialect` and auth `--database-dialect` also accept `postgresql` and `mysql`. Auth's `--base-path` changes the default `/api/auth` mount. The CLI adds dependencies and an environment example as needed, but it does not apply database migrations or populate secrets. Follow the scaffold's reported next steps after reviewing the schema and environment values.
|
|
26
|
+
|
|
27
|
+
## Other add kinds
|
|
28
|
+
|
|
29
|
+
Run `bun run relkit add <kind> --help` for each kind's flags and requirements:
|
|
30
|
+
|
|
31
|
+
| Area | Kinds |
|
|
32
|
+
| --------------- | ---------------------------------------- |
|
|
33
|
+
| Domain behavior | `function`, `task`, `error`, `constants` |
|
|
34
|
+
| Events and work | `event`, `event-function`, `job` |
|
|
35
|
+
| Providers | `cache`, `bucket` |
|
|
36
|
+
| AI | `tool`, `prompt`, `agent` |
|
|
37
|
+
| HTTP | `middleware`, `transform`, `route` |
|
|
38
|
+
|
|
39
|
+
For example, jobs need a target task, tools need an existing or newly created function, and agents need a prompt or inline instructions. Check the existing service and profile before selecting one. `--no-install` skips installing newly required packages and may skip verification; `--project-root <directory>` targets another app. `bun run relkit --json add ...` disables prompts and emits structured results for automation.
|
|
40
|
+
|
|
41
|
+
There is no `relkit add channel` or `relkit add observability` kind. Author channels with `defineChannel` and configure observability in `defineApp({ telemetry })`; see the [realtime](realtime-apis.md) and [observability](observability-apis.md) references.
|
|
42
|
+
|
|
43
|
+
For streaming responses, scaffold a function and route, then edit the function's output to `streamOf(itemSchema)` and the route's `stream` option; see the [streaming reference](streaming-apis.md).
|
|
44
|
+
|
|
45
|
+
## Inspect and run the app
|
|
46
|
+
|
|
47
|
+
| Goal | Command |
|
|
48
|
+
| --------------------------------------- | ----------------------------------- |
|
|
49
|
+
| Validate the application graph | `bun run check` |
|
|
50
|
+
| Typecheck and test | `bun run typecheck`, `bun run test` |
|
|
51
|
+
| Start app, inspector, and API reference | `bun run dev` |
|
|
52
|
+
| Inspect the graph | `bun run relkit graph print` |
|
|
53
|
+
| Inspect environment value status | `bun run relkit env list` |
|
|
54
|
+
| Validate active environment values | `bun run relkit env check` |
|
|
55
|
+
| Explain one environment declaration | `bun run relkit env explain NAME` |
|
|
56
|
+
| Render a safe environment example | `bun run relkit env example` |
|
|
57
|
+
| Check local prerequisites | `bun run relkit doctor` |
|
|
58
|
+
| Inspect local service status | `bun run relkit local status` |
|
|
59
|
+
| Build or start a built app | `bun run build`, `bun run start` |
|
|
60
|
+
|
|
61
|
+
Use `bun run relkit --help` to discover additional `graph`, `env`, `local`, `jobs`, `client`, and deployment commands. Start Docker-backed local services with `bun run relkit local up --detach` only when the app actually declares and needs them. Deployment commands require a configured deployment target.
|
|
62
|
+
|
|
63
|
+
For optional flat-to-grouped migration, use `bun run relkit migrate layout` for preview, `--write` for validated publication, and `--rollback <receipt>` for guarded restoration. See [layout migration](layout-migration.md). After `--no-install`, install dependencies and run `bun run relkit dev --prepare` before evaluating prepared-start readiness.
|