@pikku/cli 0.12.91 → 0.12.92
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/LICENSE +106 -0
- package/console-app/assets/{index-CpkvmAGb.js → index-DDpIMCpy.js} +149 -149
- package/console-app/index.html +1 -1
- package/dist/.pikku/agent/pikku-agent-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.d.ts +1 -1
- package/dist/.pikku/channel/pikku-channel-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-channel.js +6 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-client.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-contracts-meta.gen.json +15 -0
- package/dist/.pikku/cli/pikku-cli-types.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-types.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings-meta.gen.json +21 -0
- package/dist/.pikku/cli/pikku-cli-wirings.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli-wirings.gen.js +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.d.ts +1 -1
- package/dist/.pikku/cli/pikku-cli.gen.js +1 -1
- package/dist/.pikku/console/pikku-node-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.d.ts +1 -1
- package/dist/.pikku/function/pikku-function-types.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.js +1 -1
- package/dist/.pikku/function/pikku-functions-meta.gen.json +35 -40
- package/dist/.pikku/function/pikku-functions.gen.js +1 -3
- package/dist/.pikku/http/pikku-http-types.gen.d.ts +1 -1
- package/dist/.pikku/http/pikku-http-types.gen.js +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.d.ts +1 -1
- package/dist/.pikku/mcp/pikku-mcp-types.gen.js +1 -1
- package/dist/.pikku/pikku-bootstrap-scenarios.gen.d.ts +2 -1
- package/dist/.pikku/pikku-bootstrap-scenarios.gen.js +2 -1
- package/dist/.pikku/pikku-bootstrap.gen.d.ts +1 -1
- package/dist/.pikku/pikku-bootstrap.gen.js +1 -1
- package/dist/.pikku/pikku-meta-service.gen.d.ts +1 -1
- package/dist/.pikku/pikku-meta-service.gen.js +1 -1
- package/dist/.pikku/pikku-services.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.d.ts +1 -1
- package/dist/.pikku/pikku-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-types.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings-meta.gen.js +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.d.ts +1 -1
- package/dist/.pikku/queue/pikku-queue-workers-wirings.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.js +1 -1
- package/dist/.pikku/rpc/pikku-rpc-wirings-meta.internal.gen.json +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.js +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-functions.gen.d.ts +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.js +1 -1
- package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.d.ts +1 -1
- package/dist/.pikku/scenarios/schemas/register.gen.d.ts +4 -0
- package/dist/.pikku/scenarios/schemas/register.gen.js +4 -0
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.d.ts +1 -1
- package/dist/.pikku/scheduler/pikku-scheduler-types.gen.js +1 -1
- package/dist/.pikku/schemas/register.gen.js +5 -3
- package/dist/.pikku/schemas/schemas/FabricSecretsListOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/FabricSecretsRotateInput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/FabricSecretsRotateOutput.schema.json +1 -0
- package/dist/.pikku/schemas/schemas/FabricSecretsSetOutput.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/PikkuCLIConfig.schema.json +1 -1
- package/dist/.pikku/schemas/schemas/ScenarioRunInput.schema.json +1 -1
- package/dist/.pikku/scopes/pikku-scope-types.gen.d.ts +1 -1
- package/dist/.pikku/scopes/pikku-scope-types.gen.js +1 -1
- package/dist/.pikku/scopes/pikku-scopes.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secret-types.gen.js +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.d.ts +1 -1
- package/dist/.pikku/secrets/pikku-secrets.gen.js +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.d.ts +1 -1
- package/dist/.pikku/trigger/pikku-trigger-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variable-types.gen.js +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.d.ts +1 -1
- package/dist/.pikku/variables/pikku-variables.gen.js +1 -1
- package/dist/.pikku/workflow/meta/allWorkflow.gen.json +2 -8
- package/dist/.pikku/workflow/pikku-scenario-actors.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-scenario-actors.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +1 -1
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings-meta.gen.js +1 -1
- package/dist/.pikku/workflow/pikku-workflow-wirings.gen.js +1 -1
- package/dist/bin/pikku-bin.mjs +2 -2
- package/dist/src/cli.wiring.js +6 -0
- package/dist/src/deploy/analyzer/analyzer.js +22 -5
- package/dist/src/deploy/build-pipeline.js +5 -1
- package/dist/src/fabric/fabric-commands.d.ts +37 -9
- package/dist/src/fabric/fabric-commands.js +12 -0
- package/dist/src/fabric/functions/domains-add.function.d.ts +4 -4
- package/dist/src/fabric/functions/secrets-list.function.d.ts +16 -4
- package/dist/src/fabric/functions/secrets-list.function.js +12 -10
- package/dist/src/fabric/functions/secrets-rotate.function.d.ts +24 -0
- package/dist/src/fabric/functions/secrets-rotate.function.js +36 -0
- package/dist/src/fabric/functions/secrets-set.function.d.ts +8 -4
- package/dist/src/fabric/functions/secrets-set.function.js +18 -7
- package/dist/src/fabric/lib/http.d.ts +7 -1
- package/dist/src/fabric/lib/sealed-box.d.ts +16 -0
- package/dist/src/fabric/lib/sealed-box.js +72 -0
- package/dist/src/functions/commands/dev.js +9 -0
- package/dist/src/functions/commands/pikku-command-bootstrap.js +1 -0
- package/dist/src/functions/commands/scenario-browser.d.ts +17 -2
- package/dist/src/functions/commands/scenario-browser.js +16 -8
- package/dist/src/functions/commands/scenario-environment.d.ts +32 -0
- package/dist/src/functions/commands/scenario-environment.js +61 -0
- package/dist/src/functions/commands/scenario.d.ts +6 -0
- package/dist/src/functions/commands/scenario.js +14 -9
- package/dist/src/functions/commands/skills.js +27 -61
- package/dist/src/functions/db/db-codegen.d.ts +6 -0
- package/dist/src/functions/db/db-codegen.js +9 -0
- package/dist/src/functions/db/db-migrator.js +14 -0
- package/dist/src/functions/db/local-db.d.ts +8 -0
- package/dist/src/functions/db/local-db.js +24 -2
- package/dist/src/functions/db/migration-identifiers.d.ts +58 -0
- package/dist/src/functions/db/migration-identifiers.js +262 -0
- package/dist/src/functions/db/migration-provenance.d.ts +35 -0
- package/dist/src/functions/db/migration-provenance.js +80 -0
- package/dist/src/functions/db/schema-sql.d.ts +43 -0
- package/dist/src/functions/db/schema-sql.js +135 -0
- package/dist/src/functions/db/sqlite/sqlite-kysely.js +22 -2
- package/dist/src/functions/wirings/functions/schemas.js +13 -1
- package/dist/src/functions/wirings/rpc/pikku-command-rpc.js +6 -1
- package/dist/src/functions/wirings/scenarios/register-scenario-instrumentation.d.ts +10 -0
- package/dist/src/functions/wirings/scenarios/register-scenario-instrumentation.js +102 -0
- package/dist/src/functions/wirings/scenarios/scenario-partition.d.ts +13 -0
- package/dist/src/functions/wirings/scenarios/scenario-partition.js +15 -2
- package/dist/src/functions/wirings/scenarios/scenario-schema-partition.d.ts +33 -0
- package/dist/src/functions/wirings/scenarios/scenario-schema-partition.js +49 -0
- package/dist/src/functions/workflows/all.workflow.js +2 -7
- package/dist/src/utils/file-writer.js +14 -2
- package/dist/src/utils/pikku-cli-config.d.ts +14 -0
- package/dist/src/utils/pikku-cli-config.js +34 -0
- package/dist/src/utils/remove-legacy-scaffold-file.d.ts +14 -0
- package/dist/src/utils/remove-legacy-scaffold-file.js +23 -0
- package/dist/src/utils/serialize-schemas.d.ts +3 -1
- package/dist/src/utils/serialize-schemas.js +39 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
- package/dist/.pikku/schemas/schemas/PikkuScenarioFunctionsOutput.schema.json +0 -1
- package/dist/src/functions/wirings/scenarios/pikku-command-scenario-functions.d.ts +0 -1
- package/dist/src/functions/wirings/scenarios/pikku-command-scenario-functions.js +0 -31
- package/dist/src/functions/wirings/scenarios/serialize-scenario-functions.d.ts +0 -10
- package/dist/src/functions/wirings/scenarios/serialize-scenario-functions.js +0 -104
- package/skills/pikku-addon/SKILL.md +0 -243
- package/skills/pikku-addon/references/addon-package-manifest.md +0 -63
- package/skills/pikku-ai-agent/SKILL.md +0 -231
- package/skills/pikku-ai-vercel/SKILL.md +0 -82
- package/skills/pikku-ai-voice/SKILL.md +0 -88
- package/skills/pikku-audit/SKILL.md +0 -175
- package/skills/pikku-aws/SKILL.md +0 -111
- package/skills/pikku-backblaze/SKILL.md +0 -71
- package/skills/pikku-better-auth/SKILL.md +0 -298
- package/skills/pikku-cli/SKILL.md +0 -198
- package/skills/pikku-cli/references/complete-example.md +0 -82
- package/skills/pikku-concepts/SKILL.md +0 -250
- package/skills/pikku-concepts/references/concept-mapping.md +0 -556
- package/skills/pikku-concepts/references/packages.md +0 -29
- package/skills/pikku-config/SKILL.md +0 -212
- package/skills/pikku-cron/SKILL.md +0 -214
- package/skills/pikku-deploy-azure/SKILL.md +0 -71
- package/skills/pikku-deploy-cloudflare/SKILL.md +0 -82
- package/skills/pikku-deploy-express/SKILL.md +0 -86
- package/skills/pikku-deploy-fastify/SKILL.md +0 -73
- package/skills/pikku-deploy-lambda/SKILL.md +0 -110
- package/skills/pikku-deploy-nextjs/SKILL.md +0 -78
- package/skills/pikku-deploy-uws/SKILL.md +0 -88
- package/skills/pikku-deps/SKILL.md +0 -98
- package/skills/pikku-emails/SKILL.md +0 -163
- package/skills/pikku-fabric/SKILL.md +0 -318
- package/skills/pikku-fabric-debug/SKILL.md +0 -112
- package/skills/pikku-feature/SKILL.md +0 -258
- package/skills/pikku-gateway-slack/SKILL.md +0 -115
- package/skills/pikku-http/SKILL.md +0 -220
- package/skills/pikku-http/references/http-options.md +0 -55
- package/skills/pikku-i18n/SKILL.md +0 -137
- package/skills/pikku-info/SKILL.md +0 -100
- package/skills/pikku-jose/SKILL.md +0 -105
- package/skills/pikku-kysely/SKILL.md +0 -219
- package/skills/pikku-machine-auth/SKILL.md +0 -183
- package/skills/pikku-mcp/SKILL.md +0 -241
- package/skills/pikku-middleware/SKILL.md +0 -231
- package/skills/pikku-middleware/references/middleware-patterns.md +0 -61
- package/skills/pikku-mongodb/SKILL.md +0 -105
- package/skills/pikku-n8n-import/SKILL.md +0 -109
- package/skills/pikku-n8n-import/SPEC.md +0 -84
- package/skills/pikku-n8n-import/references/addon-mapping.md +0 -121
- package/skills/pikku-n8n-import/references/code-translation.md +0 -121
- package/skills/pikku-n8n-import/references/loops-and-control.md +0 -87
- package/skills/pikku-paraglide/SKILL.md +0 -117
- package/skills/pikku-permissions/SKILL.md +0 -192
- package/skills/pikku-pino/SKILL.md +0 -79
- package/skills/pikku-product-second-opinion/README.md +0 -43
- package/skills/pikku-product-second-opinion/SKILL.md +0 -158
- package/skills/pikku-product-second-opinion/example/sample-report.md +0 -90
- package/skills/pikku-product-second-opinion/references/report-template.md +0 -73
- package/skills/pikku-queue/SKILL.md +0 -240
- package/skills/pikku-react/SKILL.md +0 -212
- package/skills/pikku-react-query/SKILL.md +0 -242
- package/skills/pikku-realtime/SKILL.md +0 -236
- package/skills/pikku-realtime/references/other-routes.md +0 -23
- package/skills/pikku-redis/SKILL.md +0 -90
- package/skills/pikku-rpc/SKILL.md +0 -171
- package/skills/pikku-rtl/SKILL.md +0 -219
- package/skills/pikku-scenario/SKILL.md +0 -382
- package/skills/pikku-schedule/SKILL.md +0 -57
- package/skills/pikku-schema-ajv/SKILL.md +0 -62
- package/skills/pikku-schema-cfworker/SKILL.md +0 -63
- package/skills/pikku-security/SKILL.md +0 -108
- package/skills/pikku-services/SKILL.md +0 -248
- package/skills/pikku-services/references/audit-wire-service.md +0 -34
- package/skills/pikku-software-archaeology/README.md +0 -70
- package/skills/pikku-software-archaeology/SKILL.md +0 -186
- package/skills/pikku-software-archaeology/references/blueprint.schema.json +0 -625
- package/skills/pikku-software-archaeology/references/pikku-mapping.md +0 -49
- package/skills/pikku-software-archaeology/scripts/validate.mjs +0 -173
- package/skills/pikku-tag-middleware/SKILL.md +0 -13
- package/skills/pikku-template-clone/SKILL.md +0 -40
- package/skills/pikku-trigger/SKILL.md +0 -181
- package/skills/pikku-versioning/SKILL.md +0 -173
- package/skills/pikku-websocket/SKILL.md +0 -243
- package/skills/pikku-workflow/SKILL.md +0 -172
- package/skills/pikku-workflow/references/workflow-reference.md +0 -63
- package/skills/pikku-workflows-client/SKILL.md +0 -150
- package/skills/pikku-ws/SKILL.md +0 -47
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pikku-realtime
|
|
3
|
-
description: 'Use Pikku''s realtime feature — typed pub/sub events over WebSocket (multi-topic) or SSE (single-topic, auto-cleanup). Covers declaring EventHubTopics, scaffolding the /events channel, the auto-generated `PikkuRealtime` client, and publishing events from a function. TRIGGER when: the user asks for realtime updates, pub/sub, push notifications, server-sent events, websocket events, eventhub, or "live" data on the frontend. DO NOT TRIGGER when: the user wants RPC-style request/response (use pikku-rpc / pikku-react-query) or a custom one-off WebSocket channel (use pikku-websocket).'
|
|
4
|
-
installGroups: [core]
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Pikku Realtime
|
|
8
|
-
|
|
9
|
-
## Agent Operating Procedure
|
|
10
|
-
|
|
11
|
-
Use this skill as an execution checklist, not reference material.
|
|
12
|
-
|
|
13
|
-
1. Discover before editing. Prefer OpenCode tools such as `pikku-meta` when available; otherwise run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
|
|
14
|
-
2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
|
|
15
|
-
3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
|
|
16
|
-
4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
|
|
17
|
-
5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
|
|
18
|
-
|
|
19
|
-
Most realtime UI is just typed pub/sub: a server pushes `todo-created`, the client
|
|
20
|
-
renders it. Pikku ships exactly that, two ways — both use the same `EventHubService`
|
|
21
|
-
and the same publish call, so choose by transport, not by code shape:
|
|
22
|
-
|
|
23
|
-
- **WebSocket** at `/events` — one connection, many topic subscriptions.
|
|
24
|
-
- **SSE** at `GET /events/:topic` — one connection per topic, auto-cleanup on
|
|
25
|
-
disconnect. Good when WebSocket is blocked or for trivially streaming one topic.
|
|
26
|
-
|
|
27
|
-
## 1. Declare your topics
|
|
28
|
-
|
|
29
|
-
In your project's types file (e.g. `types/eventhub-topics.d.ts`):
|
|
30
|
-
|
|
31
|
-
```ts
|
|
32
|
-
import type { Todo } from '../src/schemas.js'
|
|
33
|
-
|
|
34
|
-
export type EventHubTopics = {
|
|
35
|
-
'todo-created': { todo: Todo }
|
|
36
|
-
'todo-updated': { todo: Todo }
|
|
37
|
-
'todo-deleted': { todoId: string }
|
|
38
|
-
}
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Reference it in `application-types.d.ts` and instantiate it in `services.ts`:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
// application-types.d.ts
|
|
45
|
-
import type { EventHubService } from '@pikku/core/channel'
|
|
46
|
-
import type { EventHubTopics } from './eventhub-topics.js'
|
|
47
|
-
|
|
48
|
-
export interface SingletonServices extends CoreSingletonServices<Config> {
|
|
49
|
-
eventHub?: EventHubService<EventHubTopics>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// services.ts
|
|
53
|
-
import { LocalEventHubService } from '@pikku/core/channel'
|
|
54
|
-
const eventHub = new LocalEventHubService<EventHubTopics>()
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
For multi-instance deployments use `CloudflareEventHubService` /
|
|
58
|
-
`LambdaEventHubService` / `UWSEventHubService` instead — same interface.
|
|
59
|
-
|
|
60
|
-
## 2. Enable the server side
|
|
61
|
-
|
|
62
|
-
```bash
|
|
63
|
-
yarn pikku enable events # auth required by default
|
|
64
|
-
yarn pikku enable events --noAuth # public events
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
This sets `scaffold.events` in `pikku.config.json`. The next `pikku all` generates
|
|
68
|
-
`events.gen.ts` in your scaffold dir, wiring (using whatever `eventHub` is in your
|
|
69
|
-
singletons — you write neither by hand):
|
|
70
|
-
|
|
71
|
-
- A WebSocket channel at `/events` handling `{action: 'subscribe' | 'unsubscribe', topic}` messages.
|
|
72
|
-
- An SSE handler at `GET /events/:topic`.
|
|
73
|
-
|
|
74
|
-
## 3. Generate the typed client
|
|
75
|
-
|
|
76
|
-
Add to `pikku.config.json`:
|
|
77
|
-
|
|
78
|
-
```jsonc
|
|
79
|
-
{
|
|
80
|
-
"clientFiles": {
|
|
81
|
-
"realtimeFile": "packages/sdk/src/pikku/realtime.gen.ts",
|
|
82
|
-
// Optional: full type inference for subscribe/unsubscribe
|
|
83
|
-
"realtimeEventHubTopicsImport": "../../../functions/types/eventhub-topics.js#EventHubTopics",
|
|
84
|
-
},
|
|
85
|
-
}
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
Run `pikku all` (or `pikku realtime` to regenerate just this file). The generated
|
|
89
|
-
file exports two surfaces:
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
export class PikkuRealtime {
|
|
93
|
-
constructor(options: { url: string; reconnect?: boolean; ... })
|
|
94
|
-
subscribe<K extends keyof EventHubTopics>(topic: K, handler: (data: EventHubTopics[K]) => void): () => void
|
|
95
|
-
unsubscribe<K extends keyof EventHubTopics>(topic: K, handler?: ...): void
|
|
96
|
-
close(): void
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export function subscribeToTopicViaSSE<K extends keyof EventHubTopics>(
|
|
100
|
-
baseUrl: string, topic: K, handler: (data: EventHubTopics[K]) => void
|
|
101
|
-
): { close: () => void }
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
Without `realtimeEventHubTopicsImport`, the client falls back to
|
|
105
|
-
`Record<string, unknown>` — usable but untyped. Set the import for full typed
|
|
106
|
-
subscribe/unsubscribe.
|
|
107
|
-
|
|
108
|
-
## 4. Publish events from a function
|
|
109
|
-
|
|
110
|
-
The `/events` channel listens for client subscriptions; the eventHub fans out
|
|
111
|
-
publishes. Envelope the payload with `topic` so the client dispatcher works; the
|
|
112
|
-
`null` channelId means "broadcast to all subscribers" (pass a specific channel id
|
|
113
|
-
to exclude/include a single connection):
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
import { pikkuFunc } from '#pikku'
|
|
117
|
-
|
|
118
|
-
export const createTodo = pikkuFunc({
|
|
119
|
-
input: CreateTodoInput,
|
|
120
|
-
output: CreateTodoOutput,
|
|
121
|
-
func: async ({ kysely, eventHub }, data) => {
|
|
122
|
-
const todo = await kysely
|
|
123
|
-
.insertInto('todos').values(data).returningAll()
|
|
124
|
-
.executeTakeFirstOrThrow()
|
|
125
|
-
|
|
126
|
-
if (eventHub) {
|
|
127
|
-
await eventHub.publish('todo-created', null, {
|
|
128
|
-
topic: 'todo-created',
|
|
129
|
-
data: { todo },
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
return { id: todo.id }
|
|
133
|
-
},
|
|
134
|
-
})
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
A thin helper removes the duplication:
|
|
138
|
-
|
|
139
|
-
```ts
|
|
140
|
-
async function publishEvent<K extends keyof EventHubTopics>(
|
|
141
|
-
hub: EventHubService<EventHubTopics>, topic: K, data: EventHubTopics[K]
|
|
142
|
-
) {
|
|
143
|
-
return hub.publish(topic, null, { topic, data })
|
|
144
|
-
}
|
|
145
|
-
// usage: await publishEvent(eventHub, 'todo-created', { todo })
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
## 5. Wire it up — share fetch with PikkuRPC
|
|
149
|
-
|
|
150
|
-
`PikkuRealtime` mirrors `PikkuRPC`: it wraps the same `PikkuFetch`, so server URL +
|
|
151
|
-
auth are configured **once** and shared across HTTP, RPC, and realtime transports.
|
|
152
|
-
|
|
153
|
-
```tsx
|
|
154
|
-
import { createPikku, PikkuProvider } from '@pikku/react'
|
|
155
|
-
import { PikkuFetch } from './pikku/pikku-fetch.gen'
|
|
156
|
-
import { PikkuRPC } from './pikku/pikku-rpc.gen'
|
|
157
|
-
import { PikkuRealtime } from './pikku/realtime.gen'
|
|
158
|
-
|
|
159
|
-
const pikku = createPikku(
|
|
160
|
-
PikkuFetch,
|
|
161
|
-
PikkuRPC,
|
|
162
|
-
PikkuRealtime, // pass the realtime class as the third arg
|
|
163
|
-
{ serverUrl: apiUrl() } // shared env helper — see pikku-react
|
|
164
|
-
)
|
|
165
|
-
// pikku.fetch / pikku.rpc / pikku.realtime — all share the same fetch.
|
|
166
|
-
|
|
167
|
-
createRoot(document.getElementById('root')!).render(
|
|
168
|
-
<PikkuProvider pikku={pikku}><App /></PikkuProvider>
|
|
169
|
-
)
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
Or wire manually:
|
|
173
|
-
|
|
174
|
-
```ts
|
|
175
|
-
const realtime = new PikkuRealtime()
|
|
176
|
-
realtime.setPikkuFetch(pikku.fetch) // inherits serverUrl + auth
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
## 6. Subscribe from React
|
|
180
|
-
|
|
181
|
-
Subscribe inside `useEffect` (never the render path, or you create a subscription
|
|
182
|
-
per render). `subscribe` returns an unsubscribe function; SSE's `subscribeToTopic`
|
|
183
|
-
returns a handle with `close()`:
|
|
184
|
-
|
|
185
|
-
```tsx
|
|
186
|
-
import { useEffect, useState } from 'react'
|
|
187
|
-
|
|
188
|
-
function TodoList() {
|
|
189
|
-
const { realtime } = usePikku() // a hook over your context
|
|
190
|
-
const [todos, setTodos] = useState<Todo[]>([])
|
|
191
|
-
|
|
192
|
-
useEffect(() => {
|
|
193
|
-
// WebSocket multi-topic:
|
|
194
|
-
const off = realtime.subscribe('todo-created', ({ todo }) =>
|
|
195
|
-
setTodos((prev) => [...prev, todo]))
|
|
196
|
-
return off
|
|
197
|
-
|
|
198
|
-
// Single-topic SSE (auto-cleanup on close) instead:
|
|
199
|
-
// const sub = realtime.subscribeToTopic('todo-created', ({ todo }) =>
|
|
200
|
-
// setTodos((prev) => [...prev, todo]))
|
|
201
|
-
// return () => sub.close()
|
|
202
|
-
}, [realtime])
|
|
203
|
-
|
|
204
|
-
return <ul>{todos.map((t) => <li key={t.id}>{t.title}</li>)}</ul>
|
|
205
|
-
}
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Other SSE / WebSocket routes
|
|
209
|
-
|
|
210
|
-
The same client also subscribes to generic `sse: true` routes and raw `wireChannel`
|
|
211
|
-
sockets (`subscribeToSSE`, `connectToChannel`). See
|
|
212
|
-
[references/other-routes.md](references/other-routes.md).
|
|
213
|
-
|
|
214
|
-
## When to pick which transport
|
|
215
|
-
|
|
216
|
-
| Need | Use |
|
|
217
|
-
| ------------------------------------------ | ----------------------------- |
|
|
218
|
-
| Many topics in one connection | **PikkuRealtime** (WebSocket) |
|
|
219
|
-
| Single live stream, simple cleanup | **subscribeToTopicViaSSE** |
|
|
220
|
-
| Bidirectional (client also sends messages) | **PikkuRealtime** |
|
|
221
|
-
| WebSockets blocked by infra | **subscribeToTopicViaSSE** |
|
|
222
|
-
|
|
223
|
-
Both auto-clean on the server (the eventHub's `onChannelClosed` hook unsubscribes
|
|
224
|
-
all topics for the dead channel id). Don't write manual cleanup unless you're
|
|
225
|
-
unsubscribing partway through a session.
|
|
226
|
-
|
|
227
|
-
## What NOT to do
|
|
228
|
-
|
|
229
|
-
- Don't call `eventHub.publish(topic, ..., rawData)` without the `{topic, data}`
|
|
230
|
-
envelope — clients use `topic` to dispatch handlers.
|
|
231
|
-
- Don't create your own `/events` channel by hand — `pikku enable events` already
|
|
232
|
-
does it correctly with disconnect cleanup.
|
|
233
|
-
- Don't subscribe inside the render path — use `useEffect`.
|
|
234
|
-
- Don't subscribe to topics that don't exist in `EventHubTopics`. The generated
|
|
235
|
-
client's types prevent it; if you reach for `as any` to subscribe to a string,
|
|
236
|
-
declare the topic first.
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# Subscribing to other SSE / WebSocket routes
|
|
2
|
-
|
|
3
|
-
The same `PikkuRealtime` client also handles generic SSE + channel routes (not just
|
|
4
|
-
`/events` topics). Use the path; the base URL is inherited from `PikkuFetch`.
|
|
5
|
-
|
|
6
|
-
```ts
|
|
7
|
-
// Any `sse: true` HTTP route
|
|
8
|
-
const sub = realtime.subscribeToSSE<{ progress: number }>(
|
|
9
|
-
`/workflow-run/${runId}/stream`,
|
|
10
|
-
(event) => setProgress(event.progress)
|
|
11
|
-
)
|
|
12
|
-
// later: sub.close()
|
|
13
|
-
|
|
14
|
-
// Any wireChannel — open a raw socket, wrap in PikkuWebSocket for typed I/O
|
|
15
|
-
const ws = realtime.connectToChannel('/ws/kanban')
|
|
16
|
-
const typed = new PikkuWebSocket<'kanban-live'>(ws)
|
|
17
|
-
typed.getRoute('command').subscribe('message', (data) => {
|
|
18
|
-
/* ... */
|
|
19
|
-
})
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
Discover what's available with `pikku meta clients --json` — `channels` and any HTTP
|
|
23
|
-
`sse: true` routes are listed there.
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pikku-redis
|
|
3
|
-
description: >-
|
|
4
|
-
Use when setting up Redis-backed services in a Pikku app. Covers channel stores, workflow
|
|
5
|
-
services, secret services, event hubs, agent runs, and deployment services backed by Redis.
|
|
6
|
-
TRIGGER when: code uses RedisChannelStore, RedisWorkflowService, RedisSecretService, or user
|
|
7
|
-
asks about Redis setup with Pikku. DO NOT TRIGGER when: user asks about BullMQ queues (use
|
|
8
|
-
pikku-queue) or SQL databases (use pikku-kysely).
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# Pikku Redis
|
|
12
|
-
|
|
13
|
-
## Agent Operating Procedure
|
|
14
|
-
|
|
15
|
-
Use this skill as an execution checklist, not reference material.
|
|
16
|
-
|
|
17
|
-
1. Discover before editing. Prefer OpenCode tools such as `pikku-meta` when available; otherwise run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
|
|
18
|
-
2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
|
|
19
|
-
3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
|
|
20
|
-
4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
|
|
21
|
-
5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
|
|
22
|
-
|
|
23
|
-
`@pikku/redis` provides Redis-backed implementations of Pikku's core service interfaces using [ioredis](https://github.com/redis/ioredis).
|
|
24
|
-
|
|
25
|
-
## Installation
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
yarn add @pikku/redis
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
## API Reference
|
|
32
|
-
|
|
33
|
-
### Available Services
|
|
34
|
-
|
|
35
|
-
All services accept a Redis connection (ioredis `Redis` instance, `RedisOptions`, or connection string) in their constructor.
|
|
36
|
-
|
|
37
|
-
| Service | Interface | Purpose |
|
|
38
|
-
| ------------------------- | ---------------------- | ---------------------------------------------- |
|
|
39
|
-
| `RedisChannelStore` | `ChannelStore` | WebSocket channel state persistence |
|
|
40
|
-
| `RedisEventHubStore` | `EventHubStore` | Event hub state persistence |
|
|
41
|
-
| `RedisWorkflowService` | `PikkuWorkflowService` | Workflow definition storage |
|
|
42
|
-
| `RedisWorkflowRunService` | `WorkflowRunService` | Workflow execution tracking |
|
|
43
|
-
| `RedisDeploymentService` | `DeploymentService` | Deployment state management |
|
|
44
|
-
| `RedisAgentRunService` | `AgentRunService` | Agent execution tracking |
|
|
45
|
-
| `RedisSecretService` | `SecretService` | Encrypted secret storage (envelope encryption) |
|
|
46
|
-
|
|
47
|
-
### Secret Service
|
|
48
|
-
|
|
49
|
-
```typescript
|
|
50
|
-
import { RedisSecretService } from '@pikku/redis'
|
|
51
|
-
|
|
52
|
-
const secrets = new RedisSecretService(
|
|
53
|
-
connectionOrConfig: Redis | RedisOptions | string,
|
|
54
|
-
config: { kekSecret: string; salt: string }
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
await secrets.getSecret<T = string>(key: string): Promise<T>
|
|
58
|
-
await secrets.getSecrets<T>(keys: (keyof T & string)[]): Promise<Partial<T>>
|
|
59
|
-
await secrets.hasSecret(key: string): Promise<boolean>
|
|
60
|
-
await secrets.setSecret(key: string, value: unknown): Promise<void>
|
|
61
|
-
await secrets.deleteSecret(key: string): Promise<void>
|
|
62
|
-
await secrets.rotateKEK(): Promise<number>
|
|
63
|
-
await secrets.close(): Promise<void>
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Usage Patterns
|
|
67
|
-
|
|
68
|
-
### Full Setup
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
import {
|
|
72
|
-
RedisChannelStore,
|
|
73
|
-
RedisWorkflowService,
|
|
74
|
-
RedisSecretService,
|
|
75
|
-
} from '@pikku/redis'
|
|
76
|
-
|
|
77
|
-
const createSingletonServices = pikkuServices(async (config) => {
|
|
78
|
-
const logger = new PinoLogger()
|
|
79
|
-
|
|
80
|
-
const channelStore = new RedisChannelStore(config.redisUrl)
|
|
81
|
-
const workflowService = new RedisWorkflowService(config.redisUrl)
|
|
82
|
-
|
|
83
|
-
const secrets = new RedisSecretService(config.redisUrl, {
|
|
84
|
-
kekSecret: config.kekSecret,
|
|
85
|
-
salt: config.salt,
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
return { config, logger, channelStore, workflowService, secrets }
|
|
89
|
-
})
|
|
90
|
-
```
|
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pikku-rpc
|
|
3
|
-
description: >-
|
|
4
|
-
Use when making internal function-to-function calls within a Pikku app, composing functions, or
|
|
5
|
-
exposing RPC endpoints. Covers rpc.invoke, rpc.remote, rpc.exposed, and generated RPC client.
|
|
6
|
-
TRIGGER when: code uses wire.rpc or expose: true, user asks about calling one Pikku function
|
|
7
|
-
from another, function composition, or RPC endpoints. DO NOT TRIGGER when: user asks about HTTP
|
|
8
|
-
routes (use pikku-http) or addon cross-package calls (use pikku-addon).
|
|
9
|
-
installGroups: [core]
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Pikku RPC Wiring
|
|
13
|
-
|
|
14
|
-
## Agent Operating Procedure
|
|
15
|
-
|
|
16
|
-
Use this skill as an execution checklist, not reference material.
|
|
17
|
-
|
|
18
|
-
1. Discover before editing. Prefer OpenCode tools such as `pikku-meta` when available; otherwise run the relevant `pikku meta ... --json` command and inspect only the focused output you need.
|
|
19
|
-
2. Identify the source files that own the behavior. Do not start by reading generated output, `.pikku`, `node_modules`, vendored packages, or broad build artifacts.
|
|
20
|
-
3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
|
|
21
|
-
4. Validate with the narrowest relevant command first, then run `pikku-verify` or `pikku all` when functions, wirings, schemas, or generated clients may have changed.
|
|
22
|
-
5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
|
|
23
|
-
|
|
24
|
-
Call Pikku functions from other Pikku functions internally with full type safety. Use RPC to compose business logic without importing functions directly.
|
|
25
|
-
|
|
26
|
-
## Before You Start
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
pikku info functions --verbose # See existing functions and which could be called via RPC
|
|
30
|
-
pikku info tags --verbose # Understand project organization
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
See `pikku-concepts` for the core mental model.
|
|
34
|
-
|
|
35
|
-
## API Reference
|
|
36
|
-
|
|
37
|
-
### RPC Methods (on `wire.rpc`)
|
|
38
|
-
|
|
39
|
-
Four ways to call functions via RPC:
|
|
40
|
-
|
|
41
|
-
| Method | Purpose |
|
|
42
|
-
| -------------------------------- | ----------------------------------------- |
|
|
43
|
-
| `rpc.invoke(name, data)` | Internal call to any wired function |
|
|
44
|
-
| `rpc.remote(name, data)` | Remote call via DeploymentService |
|
|
45
|
-
| `rpc.exposed(name, data)` | Call functions marked with `expose: true` |
|
|
46
|
-
| `rpc.startWorkflow(name, input)` | Start a workflow |
|
|
47
|
-
|
|
48
|
-
### Exposed Functions
|
|
49
|
-
|
|
50
|
-
Mark a function as externally callable via RPC:
|
|
51
|
-
|
|
52
|
-
```typescript
|
|
53
|
-
const greet = pikkuSessionlessFunc({
|
|
54
|
-
title: 'Greet',
|
|
55
|
-
expose: true, // ← callable via rpc.exposed()
|
|
56
|
-
func: async ({}, { name }) => {
|
|
57
|
-
return { message: `Hello, ${name}!` }
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### HTTP RPC Endpoint
|
|
63
|
-
|
|
64
|
-
Expose all `expose: true` functions over HTTP:
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
wireHTTP({
|
|
68
|
-
route: '/rpc/:rpcName',
|
|
69
|
-
method: 'post',
|
|
70
|
-
auth: false,
|
|
71
|
-
func: rpcCaller,
|
|
72
|
-
})
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## Usage Patterns
|
|
76
|
-
|
|
77
|
-
### Internal Function Composition
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
const calculateTax = pikkuSessionlessFunc({
|
|
81
|
-
title: 'Calculate Tax',
|
|
82
|
-
func: async ({}, { amount, rate }) => {
|
|
83
|
-
return { tax: amount * rate }
|
|
84
|
-
},
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
const processOrder = pikkuFunc({
|
|
88
|
-
title: 'Process Order',
|
|
89
|
-
func: async ({ db }, { orderId }, { rpc }) => {
|
|
90
|
-
const order = await db.getOrder(orderId)
|
|
91
|
-
|
|
92
|
-
// Call another pikku function internally — fully typed
|
|
93
|
-
const { tax } = await rpc.invoke('calculateTax', {
|
|
94
|
-
amount: order.total,
|
|
95
|
-
rate: 0.08,
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
return { orderId, total: order.total + tax }
|
|
99
|
-
},
|
|
100
|
-
})
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### When to Use RPC vs Direct Imports
|
|
104
|
-
|
|
105
|
-
| Approach | Use When |
|
|
106
|
-
| -------------- | -------------------------------------------------------------------------------------------- |
|
|
107
|
-
| `rpc.invoke()` | Cross-domain calls, maintaining separation of concerns, function may be in different package |
|
|
108
|
-
| Direct import | Same module, tightly coupled logic, performance critical |
|
|
109
|
-
|
|
110
|
-
RPC calls go through Pikku's middleware and permission pipeline. Direct imports skip them.
|
|
111
|
-
|
|
112
|
-
### Generated RPC Client
|
|
113
|
-
|
|
114
|
-
After `npx pikku all`:
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
import { pikkuRPC } from '.pikku/pikku-rpc.gen.js'
|
|
118
|
-
|
|
119
|
-
pikkuRPC.setServerUrl('http://localhost:4002')
|
|
120
|
-
|
|
121
|
-
const result = await pikkuRPC.invoke('calculateTax', {
|
|
122
|
-
amount: 100,
|
|
123
|
-
rate: 0.08,
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
pikkuRPC.setAuthorizationJWT(token)
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
## Complete Example
|
|
130
|
-
|
|
131
|
-
```typescript
|
|
132
|
-
// functions/billing.functions.ts
|
|
133
|
-
export const calculateTax = pikkuSessionlessFunc({
|
|
134
|
-
title: 'Calculate Tax',
|
|
135
|
-
func: async ({}, { amount, region }) => {
|
|
136
|
-
const rates = { US: 0.08, EU: 0.2, UK: 0.2 }
|
|
137
|
-
return { tax: amount * (rates[region] || 0) }
|
|
138
|
-
},
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
export const calculateShipping = pikkuSessionlessFunc({
|
|
142
|
-
title: 'Calculate Shipping',
|
|
143
|
-
func: async ({}, { weight, region }) => {
|
|
144
|
-
const base = region === 'US' ? 5 : 15
|
|
145
|
-
return { shipping: base + weight * 0.5 }
|
|
146
|
-
},
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
// functions/orders.functions.ts
|
|
150
|
-
export const processOrder = pikkuFunc({
|
|
151
|
-
title: 'Process Order',
|
|
152
|
-
func: async ({ db }, { orderId }, { rpc }) => {
|
|
153
|
-
const order = await db.getOrder(orderId)
|
|
154
|
-
|
|
155
|
-
const { tax } = await rpc.invoke('calculateTax', {
|
|
156
|
-
amount: order.total,
|
|
157
|
-
region: order.region,
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
const { shipping } = await rpc.invoke('calculateShipping', {
|
|
161
|
-
weight: order.totalWeight,
|
|
162
|
-
region: order.region,
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
const finalTotal = order.total + tax + shipping
|
|
166
|
-
await db.updateOrder(orderId, { tax, shipping, finalTotal })
|
|
167
|
-
|
|
168
|
-
return { orderId, total: finalTotal, tax, shipping }
|
|
169
|
-
},
|
|
170
|
-
})
|
|
171
|
-
```
|