@pikku/cli 0.12.90 → 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/README.md +25 -2
- package/console-app/assets/{index-CSzCJzBb.css → index-D0HG8q0B.css} +1 -1
- package/console-app/assets/{index-C5Bd44e4.js → index-DDpIMCpy.js} +149 -149
- package/console-app/index.html +2 -2
- 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 +43 -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 +4 -4
- 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 +39 -44
- 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 +9 -0
- package/dist/.pikku/pikku-bootstrap-scenarios.gen.js +9 -0
- 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.d.ts +1 -0
- package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.js +10 -0
- package/dist/.pikku/scenarios/pikku-scenario-functions-meta.gen.json +1 -0
- package/dist/.pikku/scenarios/pikku-scenario-functions.gen.d.ts +4 -0
- package/dist/.pikku/scenarios/pikku-scenario-functions.gen.js +1 -0
- package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.d.ts +1 -0
- package/dist/.pikku/scenarios/pikku-scenario-wirings-meta.gen.js +10 -0
- package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.d.ts +4 -0
- package/dist/.pikku/scenarios/pikku-scenario-wirings.gen.js +1 -0
- 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 +19 -0
- package/dist/.pikku/workflow/pikku-scenario-actors.gen.js +17 -0
- package/dist/.pikku/workflow/pikku-workflow-types.gen.d.ts +152 -3
- package/dist/.pikku/workflow/pikku-workflow-types.gen.js +39 -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 +28 -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 +11 -0
- package/dist/src/functions/commands/load-user-project.d.ts +7 -0
- package/dist/src/functions/commands/load-user-project.js +21 -0
- package/dist/src/functions/commands/pikku-command-bootstrap.js +13 -0
- package/dist/src/functions/commands/scenario-browser.d.ts +84 -0
- package/dist/src/functions/commands/scenario-browser.js +68 -0
- 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-formatter.d.ts +81 -0
- package/dist/src/functions/commands/scenario-formatter.js +120 -0
- package/dist/src/functions/commands/scenario-ladder.d.ts +66 -0
- package/dist/src/functions/commands/scenario-ladder.js +132 -0
- package/dist/src/functions/commands/scenario-plan.d.ts +61 -0
- package/dist/src/functions/commands/scenario-plan.js +106 -0
- package/dist/src/functions/commands/scenario.d.ts +24 -0
- package/dist/src/functions/commands/scenario.js +322 -50
- package/dist/src/functions/commands/serve.js +2 -0
- 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/pikku-command-functions.js +26 -8
- package/dist/src/functions/wirings/functions/schemas.js +13 -1
- package/dist/src/functions/wirings/functions/serialize-function-types.js +3 -3
- 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 +42 -0
- package/dist/src/functions/wirings/scenarios/scenario-partition.js +71 -0
- 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/wirings/scenarios/serialize-feature-meta.d.ts +14 -0
- package/dist/src/functions/wirings/scenarios/serialize-feature-meta.js +29 -0
- package/dist/src/functions/wirings/scenarios/serialize-scenario-meta.d.ts +12 -0
- package/dist/src/functions/wirings/scenarios/serialize-scenario-meta.js +56 -0
- package/dist/src/functions/wirings/scenarios/serialize-scenario-registration.d.ts +7 -0
- package/dist/src/functions/wirings/scenarios/serialize-scenario-registration.js +40 -0
- package/dist/src/functions/wirings/workflow/pikku-command-workflow.js +43 -8
- package/dist/src/functions/wirings/workflow/serialize-scenario-actors.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/serialize-scenario-actors.js +13 -2
- package/dist/src/functions/wirings/workflow/serialize-scenario-step-map.d.ts +4 -0
- package/dist/src/functions/wirings/workflow/serialize-scenario-step-map.js +62 -0
- package/dist/src/functions/wirings/workflow/serialize-workflow-bootstrap-map.js +10 -3
- package/dist/src/functions/wirings/workflow/serialize-workflow-map.js +10 -3
- package/dist/src/functions/wirings/workflow/serialize-workflow-meta.js +4 -4
- package/dist/src/functions/wirings/workflow/serialize-workflow-types.d.ts +1 -1
- package/dist/src/functions/wirings/workflow/serialize-workflow-types.js +232 -3
- package/dist/src/functions/workflows/all.workflow.js +2 -7
- package/dist/src/server/server-ready.d.ts +12 -0
- package/dist/src/server/server-ready.js +12 -0
- package/dist/src/server/spawn-dev-server.d.ts +50 -0
- package/dist/src/server/spawn-dev-server.js +112 -0
- package/dist/src/services.js +12 -1
- package/dist/src/utils/file-writer.js +14 -2
- package/dist/src/utils/meta-diff.js +5 -2
- package/dist/src/utils/pikku-cli-config.d.ts +14 -0
- package/dist/src/utils/pikku-cli-config.js +60 -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/resolve-scenario-actors.d.ts +23 -0
- package/dist/src/utils/resolve-scenario-actors.js +74 -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 +18 -8
- 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 -215
- 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,104 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Generate the scenario instrumentation functions (`pikku scenario` coverage
|
|
3
|
-
* snapshots and stub-call inspection) into the project scaffold, so scenario
|
|
4
|
-
* runs work against any server without requiring the console addon.
|
|
5
|
-
*/
|
|
6
|
-
export const serializeScenarioFunctions = (pathToPikkuTypes, requireAuth = true) => {
|
|
7
|
-
const authFlag = requireAuth ? 'true' : 'false';
|
|
8
|
-
const schemas = `/**
|
|
9
|
-
* Auto-generated scenario instrumentation schemas
|
|
10
|
-
* Do not edit manually - regenerate with 'npx pikku'
|
|
11
|
-
*/
|
|
12
|
-
import { z } from 'zod'
|
|
13
|
-
|
|
14
|
-
export const StubCallsQuery = z.object({
|
|
15
|
-
service: z.string().optional(),
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
export const Enabled = z.object({ enabled: z.boolean() })
|
|
19
|
-
`;
|
|
20
|
-
const functions = `/**
|
|
21
|
-
* Auto-generated scenario instrumentation functions
|
|
22
|
-
* Do not edit manually - regenerate with 'npx pikku'
|
|
23
|
-
*/
|
|
24
|
-
import { readFile } from 'node:fs/promises'
|
|
25
|
-
import { join } from 'node:path'
|
|
26
|
-
import { pikkuFunc } from '${pathToPikkuTypes}'
|
|
27
|
-
import {
|
|
28
|
-
getStubTracker,
|
|
29
|
-
isTestRun,
|
|
30
|
-
type CoverageFunctionMeta,
|
|
31
|
-
} from '@pikku/core/services'
|
|
32
|
-
import { StubCallsQuery, Enabled } from './scenarios.schemas.gen.js'
|
|
33
|
-
|
|
34
|
-
export const pikkuScenarioTakeLiveCoverage = pikkuFunc({
|
|
35
|
-
tags: ['pikku'],
|
|
36
|
-
title: 'Take Live Coverage',
|
|
37
|
-
description:
|
|
38
|
-
'Snapshots the live coverage collected since the server started (or since the last reset) — V8 precise coverage on Node, istanbul instrumentation on Bun — and maps it onto function body spans. Returns null unless the server was started with coverage enabled (pikku dev --coverage).',
|
|
39
|
-
expose: true,
|
|
40
|
-
auth: ${authFlag},
|
|
41
|
-
func: async ({ coverageService, metaService }) => {
|
|
42
|
-
if (!coverageService?.takeReport || !metaService?.basePath) return null
|
|
43
|
-
let functionsMeta: Record<string, CoverageFunctionMeta>
|
|
44
|
-
try {
|
|
45
|
-
const content = await readFile(
|
|
46
|
-
join(
|
|
47
|
-
metaService.basePath,
|
|
48
|
-
'function',
|
|
49
|
-
'pikku-functions-meta-verbose.gen.json'
|
|
50
|
-
),
|
|
51
|
-
'utf-8'
|
|
52
|
-
)
|
|
53
|
-
functionsMeta = JSON.parse(content)
|
|
54
|
-
} catch {
|
|
55
|
-
return null
|
|
56
|
-
}
|
|
57
|
-
return await coverageService.takeReport(functionsMeta)
|
|
58
|
-
},
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
export const pikkuScenarioResetLiveCoverage = pikkuFunc({
|
|
62
|
-
tags: ['pikku'],
|
|
63
|
-
title: 'Reset Live Coverage',
|
|
64
|
-
description:
|
|
65
|
-
'Clears V8 precise-coverage call counts so the next takeLiveCoverage snapshot is attributable to a single scenario run. Reports enabled: false when the server was not started with coverage enabled.',
|
|
66
|
-
expose: true,
|
|
67
|
-
auth: ${authFlag},
|
|
68
|
-
output: Enabled,
|
|
69
|
-
func: async ({ coverageService }) => {
|
|
70
|
-
if (!coverageService) return { enabled: false }
|
|
71
|
-
await coverageService.reset()
|
|
72
|
-
return { enabled: true }
|
|
73
|
-
},
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
export const pikkuScenarioResetStubs = pikkuFunc({
|
|
77
|
-
tags: ['pikku'],
|
|
78
|
-
title: 'Reset Stubs',
|
|
79
|
-
description:
|
|
80
|
-
'Clears recorded stub calls so the next getStubCalls result is attributable to a single scenario run. Reports enabled: false when the server was not started in test mode.',
|
|
81
|
-
expose: true,
|
|
82
|
-
auth: ${authFlag},
|
|
83
|
-
output: Enabled,
|
|
84
|
-
func: async () => {
|
|
85
|
-
getStubTracker().reset()
|
|
86
|
-
return { enabled: isTestRun() }
|
|
87
|
-
},
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
export const pikkuScenarioGetStubCalls = pikkuFunc({
|
|
91
|
-
tags: ['pikku'],
|
|
92
|
-
title: 'Get Stub Calls',
|
|
93
|
-
description:
|
|
94
|
-
'Returns calls recorded against stubbed/spied services (via the stub()/spy() core utils). Empty unless the server records service calls (pikku dev --test).',
|
|
95
|
-
expose: true,
|
|
96
|
-
auth: ${authFlag},
|
|
97
|
-
input: StubCallsQuery,
|
|
98
|
-
func: async (_services, data) => {
|
|
99
|
-
return getStubTracker().getCalls(data?.service ?? undefined)
|
|
100
|
-
},
|
|
101
|
-
})
|
|
102
|
-
`;
|
|
103
|
-
return { schemas, functions };
|
|
104
|
-
};
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pikku-addon
|
|
3
|
-
description: >-
|
|
4
|
-
Use when creating or consuming reusable function packages (addons) in Pikku. Covers wireAddon,
|
|
5
|
-
addon(), pikkuAddonServices, pikkuAddonWireServices, addon package structure, and cross-project
|
|
6
|
-
function sharing. TRIGGER when: code uses wireAddon/addon()/pikkuAddonServices, user asks about
|
|
7
|
-
addons, reusable function packages, cross-project sharing, or addon package structure. DO NOT
|
|
8
|
-
TRIGGER when: user asks about internal function composition (use pikku-rpc) or general function
|
|
9
|
-
definitions (use pikku-concepts).
|
|
10
|
-
installGroups: [core]
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
# Pikku Addons
|
|
14
|
-
|
|
15
|
-
## Agent Operating Procedure
|
|
16
|
-
|
|
17
|
-
Use this skill as an execution checklist, not reference material.
|
|
18
|
-
|
|
19
|
-
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.
|
|
20
|
-
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.
|
|
21
|
-
3. Make the smallest source change that satisfies the task. Keep generated files generated, and avoid hand-editing SDKs, schema output, or typegen.
|
|
22
|
-
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.
|
|
23
|
-
5. If validation fails, fix the source cause and rerun validation. Do not paper over generated errors by editing generated files.
|
|
24
|
-
|
|
25
|
-
Addons are reusable Pikku function packages that can be shared across projects. They bundle functions, services, secrets, and variables into a self-contained NPM package.
|
|
26
|
-
|
|
27
|
-
## Before You Start
|
|
28
|
-
|
|
29
|
-
```bash
|
|
30
|
-
pikku info functions --verbose # See existing functions and addons
|
|
31
|
-
pikku info tags --verbose # Understand project organization
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
See `pikku-concepts` for the core mental model.
|
|
35
|
-
|
|
36
|
-
## API Reference
|
|
37
|
-
|
|
38
|
-
### `wireAddon(config)`
|
|
39
|
-
|
|
40
|
-
Register an addon in the consuming project:
|
|
41
|
-
|
|
42
|
-
```typescript
|
|
43
|
-
import { wireAddon } from '#pikku'
|
|
44
|
-
|
|
45
|
-
wireAddon({
|
|
46
|
-
name: string, // Namespace for addon functions (e.g. 'todos')
|
|
47
|
-
package: string, // NPM package name (e.g. '@pikku/addon-todos')
|
|
48
|
-
rpcEndpoint?: string, // Optional remote RPC endpoint for distributed execution
|
|
49
|
-
auth?: boolean, // Whether addon functions require authentication
|
|
50
|
-
tags?: string[], // Tags applied to all addon functions
|
|
51
|
-
secretOverrides?: Record<string, string>, // Remap secret names
|
|
52
|
-
variableOverrides?: Record<string, string>, // Remap variable names
|
|
53
|
-
})
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### `addon(name)`
|
|
57
|
-
|
|
58
|
-
Type-safe reference to an addon function — use when wiring to HTTP, agents, etc.:
|
|
59
|
-
|
|
60
|
-
```typescript
|
|
61
|
-
import { addon } from '#pikku'
|
|
62
|
-
|
|
63
|
-
addon('todos:addTodo') // Returns a typed function config
|
|
64
|
-
addon('emails:sendEmail') // Namespace:functionName format
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### `pikkuAddonServices(factory)`
|
|
68
|
-
|
|
69
|
-
Define singleton services for an addon package (created once at startup):
|
|
70
|
-
|
|
71
|
-
```typescript
|
|
72
|
-
import { pikkuAddonServices } from '#pikku'
|
|
73
|
-
|
|
74
|
-
export const createSingletonServices = pikkuAddonServices(
|
|
75
|
-
async (config, parentServices?) => {
|
|
76
|
-
// parentServices: logger, variables, secrets from the consuming app
|
|
77
|
-
return {
|
|
78
|
-
myStore: new MyStore(),
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
)
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
### `pikkuAddonWireServices(factory)`
|
|
85
|
-
|
|
86
|
-
Define per-request services for an addon package (created fresh per HTTP request, queue job, etc.):
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
import { pikkuAddonWireServices } from '#pikku'
|
|
90
|
-
|
|
91
|
-
export const createWireServices = pikkuAddonWireServices(
|
|
92
|
-
async (singletonServices, wire) => {
|
|
93
|
-
// wire: transport context (http, channel, session, etc.)
|
|
94
|
-
const authHeader = wire.http?.request?.header('authorization')
|
|
95
|
-
return {
|
|
96
|
-
myService: new MyService(authHeader),
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
)
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Creating an Addon
|
|
103
|
-
|
|
104
|
-
### Scaffold
|
|
105
|
-
|
|
106
|
-
```bash
|
|
107
|
-
npx pikku new addon
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
This generates `package.json` (exports `.pikku/*` + `dist/`), `pikku.config.json` (`addon: true`), `tsconfig.json` (`#pikku` path mapping), `src/services.ts`, `src/functions/`, and `types/application-types.d.ts`. For the full file contents/exports you rarely hand-edit, read `references/addon-package-manifest.md`.
|
|
111
|
-
|
|
112
|
-
### Services
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
// src/services.ts
|
|
116
|
-
import { pikkuAddonServices, pikkuAddonWireServices } from '#pikku'
|
|
117
|
-
import { TodoStore } from './todo-store.service.js'
|
|
118
|
-
|
|
119
|
-
export const createSingletonServices = pikkuAddonServices(async () => {
|
|
120
|
-
const todoStore = new TodoStore()
|
|
121
|
-
return { todoStore }
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
// Optional — only needed if addon functions require per-request services
|
|
125
|
-
export const createWireServices = pikkuAddonWireServices(
|
|
126
|
-
async (singletonServices, wire) => {
|
|
127
|
-
return {}
|
|
128
|
-
}
|
|
129
|
-
)
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
### Functions
|
|
133
|
-
|
|
134
|
-
```typescript
|
|
135
|
-
// src/functions/addTodo.function.ts
|
|
136
|
-
import { z } from 'zod'
|
|
137
|
-
import { pikkuSessionlessFunc } from '#pikku'
|
|
138
|
-
|
|
139
|
-
const AddTodoInput = z.object({ title: z.string() })
|
|
140
|
-
const AddTodoOutput = z.object({ id: z.string(), title: z.string() })
|
|
141
|
-
|
|
142
|
-
export const addTodo = pikkuSessionlessFunc({
|
|
143
|
-
description: 'Adds a new todo',
|
|
144
|
-
input: AddTodoInput,
|
|
145
|
-
output: AddTodoOutput,
|
|
146
|
-
func: async ({ todoStore }, { title }) => {
|
|
147
|
-
return todoStore.add(title)
|
|
148
|
-
},
|
|
149
|
-
})
|
|
150
|
-
```
|
|
151
|
-
|
|
152
|
-
Optional approval gating (e.g. for agent tools) — add `approvalRequired: true` plus an `approvalDescription` resolver:
|
|
153
|
-
|
|
154
|
-
```typescript
|
|
155
|
-
approvalRequired: true,
|
|
156
|
-
approvalDescription: async (_services, { title }) => `Add a todo called "${title}"`,
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
### Build
|
|
160
|
-
|
|
161
|
-
```bash
|
|
162
|
-
npx pikku all # Generate types
|
|
163
|
-
yarn tsc # Compile TypeScript
|
|
164
|
-
cp -r .pikku dist/ # Include generated files in dist
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
## Consuming an Addon
|
|
168
|
-
|
|
169
|
-
### Install & Register
|
|
170
|
-
|
|
171
|
-
```bash
|
|
172
|
-
yarn add @my-org/addon-todos
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
// wirings/todos.wirings.ts
|
|
177
|
-
import { wireAddon } from '#pikku'
|
|
178
|
-
|
|
179
|
-
wireAddon({ name: 'todos', package: '@my-org/addon-todos' })
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
After registration, run `npx pikku all` to generate types for the addon's functions.
|
|
183
|
-
|
|
184
|
-
### Call via RPC
|
|
185
|
-
|
|
186
|
-
```typescript
|
|
187
|
-
export const myFunc = pikkuFunc({
|
|
188
|
-
func: async (_services, data, { rpc }) => {
|
|
189
|
-
const todo = await rpc.invoke('todos:addTodo', { title: 'Buy milk' })
|
|
190
|
-
return todo
|
|
191
|
-
},
|
|
192
|
-
})
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
### Wire to HTTP
|
|
196
|
-
|
|
197
|
-
```typescript
|
|
198
|
-
import { wireHTTP, addon } from '#pikku'
|
|
199
|
-
|
|
200
|
-
wireHTTP({
|
|
201
|
-
method: 'get',
|
|
202
|
-
route: '/todos',
|
|
203
|
-
func: addon('todos:listTodos'),
|
|
204
|
-
auth: false,
|
|
205
|
-
})
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Or batch multiple addon routes with `defineHTTPRoutes` + `wireHTTPRoutes`:
|
|
209
|
-
|
|
210
|
-
```typescript
|
|
211
|
-
import { wireHTTPRoutes, defineHTTPRoutes, addon } from '#pikku'
|
|
212
|
-
|
|
213
|
-
const todoRoutes = defineHTTPRoutes({
|
|
214
|
-
tags: ['todos'],
|
|
215
|
-
auth: false,
|
|
216
|
-
routes: {
|
|
217
|
-
list: { method: 'get', route: '/todos', func: addon('todos:listTodos') },
|
|
218
|
-
add: { method: 'post', route: '/todos', func: addon('todos:addTodo') },
|
|
219
|
-
},
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
wireHTTPRoutes({ basePath: '/api', routes: { todos: todoRoutes } })
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### Use in AI Agents
|
|
226
|
-
|
|
227
|
-
```typescript
|
|
228
|
-
import { pikkuAIAgent } from '#pikku'
|
|
229
|
-
import { addon } from '#pikku'
|
|
230
|
-
|
|
231
|
-
export const todoAgent = pikkuAIAgent({
|
|
232
|
-
name: 'todo-agent',
|
|
233
|
-
description: 'Manages a todo list',
|
|
234
|
-
instructions: 'You help users manage their todos.',
|
|
235
|
-
model: 'openai/gpt-4o',
|
|
236
|
-
tools: [
|
|
237
|
-
addon('todos:listTodos'),
|
|
238
|
-
addon('todos:addTodo'),
|
|
239
|
-
addon('todos:deleteTodo'),
|
|
240
|
-
],
|
|
241
|
-
maxSteps: 5,
|
|
242
|
-
})
|
|
243
|
-
```
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# Addon Package Manifest Reference
|
|
2
|
-
|
|
3
|
-
`npx pikku new addon` scaffolds these files. You rarely hand-edit them — consult this when wiring exports or config by hand.
|
|
4
|
-
|
|
5
|
-
## Package Structure
|
|
6
|
-
|
|
7
|
-
```text
|
|
8
|
-
my-addon/
|
|
9
|
-
├── package.json # Exports .pikku/* and dist/
|
|
10
|
-
├── pikku.config.json # addon: true + metadata
|
|
11
|
-
├── tsconfig.json # #pikku path mapping
|
|
12
|
-
├── src/
|
|
13
|
-
│ ├── services.ts # createSingletonServices (required)
|
|
14
|
-
│ └── functions/
|
|
15
|
-
│ └── *.function.ts # Function definitions
|
|
16
|
-
├── types/
|
|
17
|
-
│ └── application-types.d.ts # SingletonServices interface
|
|
18
|
-
└── .pikku/ # Generated (gitignored)
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## pikku.config.json
|
|
22
|
-
|
|
23
|
-
```json
|
|
24
|
-
{
|
|
25
|
-
"tsconfig": "./tsconfig.json",
|
|
26
|
-
"srcDirectories": ["src", "types"],
|
|
27
|
-
"outDir": "./.pikku",
|
|
28
|
-
"addon": true,
|
|
29
|
-
"node": {
|
|
30
|
-
"displayName": "My Addon",
|
|
31
|
-
"description": "What this addon does",
|
|
32
|
-
"categories": ["General"]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
## package.json (key fields)
|
|
38
|
-
|
|
39
|
-
```json
|
|
40
|
-
{
|
|
41
|
-
"name": "@my-org/addon-todos",
|
|
42
|
-
"imports": {
|
|
43
|
-
"#pikku": "./.pikku/pikku-types.gen.ts",
|
|
44
|
-
"#pikku/*": "./.pikku/*"
|
|
45
|
-
},
|
|
46
|
-
"exports": {
|
|
47
|
-
".": { "types": "./dist/src/index.d.ts", "import": "./dist/src/index.js" },
|
|
48
|
-
"./.pikku/*": "./.pikku/*",
|
|
49
|
-
"./.pikku/pikku-metadata.gen.json": "./.pikku/pikku-metadata.gen.json",
|
|
50
|
-
"./.pikku/rpc/pikku-rpc-wirings-map.internal.gen.js": {
|
|
51
|
-
"types": "./.pikku/rpc/pikku-rpc-wirings-map.internal.gen.d.ts"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
"files": ["dist", ".pikku"],
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"@pikku/core": "*"
|
|
57
|
-
},
|
|
58
|
-
"scripts": {
|
|
59
|
-
"pikku": "pikku all",
|
|
60
|
-
"build": "tsc && cp -r .pikku dist/"
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
```
|
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: pikku-ai-agent
|
|
3
|
-
description: >-
|
|
4
|
-
Use when building AI agents, chatbots, or LLM-powered assistants with Pikku. Covers
|
|
5
|
-
pikkuAIAgent, tool registration, memory, streaming, and agent invocation. TRIGGER when: code
|
|
6
|
-
uses pikkuAIAgent/runAIAgent/streamAIAgent, user asks about AI agents, chatbots, LLM assistants,
|
|
7
|
-
tool-calling agents, or agent memory/streaming. DO NOT TRIGGER when: user asks about MCP tool
|
|
8
|
-
exposure (use pikku-mcp) or general function definitions (use pikku-concepts).
|
|
9
|
-
installGroups: [core]
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Pikku AI Agent 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
|
-
Build AI agents that use Pikku functions as tools. Agents support conversation memory, streaming, and multi-step tool execution.
|
|
25
|
-
|
|
26
|
-
## Before You Start
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
pikku info functions --verbose # See existing functions that can be used as agent tools
|
|
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
|
-
### `pikkuAIAgent(config)`
|
|
38
|
-
|
|
39
|
-
```typescript
|
|
40
|
-
import { pikkuAIAgent } from '#pikku'
|
|
41
|
-
|
|
42
|
-
pikkuAIAgent({
|
|
43
|
-
name: string, // Unique agent identifier
|
|
44
|
-
description: string, // What the agent does
|
|
45
|
-
instructions: string | string[], // System prompt / behavior instructions
|
|
46
|
-
model: string, // LLM model (e.g. 'openai/gpt-5-mini')
|
|
47
|
-
tools?: PikkuFunc[], // Pikku functions the agent can call
|
|
48
|
-
agents?: AIAgentConfig[], // Sub-agents this agent can delegate to
|
|
49
|
-
memory?: {
|
|
50
|
-
storage?: string, // Service name for persistence (e.g. 'aiStorage')
|
|
51
|
-
vector?: string, // Vector store service name
|
|
52
|
-
embedder?: string, // Embedding service name
|
|
53
|
-
lastMessages?: number, // How many messages to retain in context
|
|
54
|
-
workingMemory?: ZodSchema, // Schema for structured working memory
|
|
55
|
-
},
|
|
56
|
-
maxSteps?: number, // Max tool-call rounds per invocation
|
|
57
|
-
temperature?: number, // LLM temperature (0-1)
|
|
58
|
-
toolChoice?: 'auto' | 'required' | 'none',
|
|
59
|
-
input?: ZodSchema, // Input validation schema
|
|
60
|
-
output?: ZodSchema, // Output validation schema
|
|
61
|
-
tags?: string[], // For grouping and middleware targeting
|
|
62
|
-
aiMiddleware?: PikkuAIMiddlewareHooks[], // AI-specific middleware
|
|
63
|
-
middleware?: PikkuMiddleware[],
|
|
64
|
-
permissions?: PermissionGroup,
|
|
65
|
-
})
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### `runAIAgent(name, input, options)` — Non-streaming
|
|
69
|
-
|
|
70
|
-
```typescript
|
|
71
|
-
const result = await runAIAgent(
|
|
72
|
-
agentName,
|
|
73
|
-
{
|
|
74
|
-
message: string, // User message
|
|
75
|
-
threadId: string, // Conversation thread ID
|
|
76
|
-
resourceId: string, // User/resource identifier
|
|
77
|
-
},
|
|
78
|
-
{ singletonServices }
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
result.text // Agent's text response
|
|
82
|
-
result.steps // Array of tool calls made
|
|
83
|
-
result.usage // Token usage { inputTokens, outputTokens }
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### `streamAIAgent(name, input, channel, options)` — Streaming
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
await streamAIAgent(
|
|
90
|
-
agentName,
|
|
91
|
-
{
|
|
92
|
-
message: string,
|
|
93
|
-
threadId: string,
|
|
94
|
-
resourceId: string,
|
|
95
|
-
},
|
|
96
|
-
channel,
|
|
97
|
-
{ singletonServices }
|
|
98
|
-
)
|
|
99
|
-
|
|
100
|
-
// Channel receives events:
|
|
101
|
-
// { type: 'step-start', stepNumber: 1 }
|
|
102
|
-
// { type: 'text-delta', text: '...' }
|
|
103
|
-
// { type: 'reasoning-delta', text: '...' }
|
|
104
|
-
// { type: 'tool-call', toolCallId, toolName, args }
|
|
105
|
-
// { type: 'tool-result', toolCallId, toolName, result }
|
|
106
|
-
// { type: 'agent-call', agentName, session, input }
|
|
107
|
-
// { type: 'agent-result', agentName, session, result }
|
|
108
|
-
// { type: 'approval-request', toolCallId, toolName, args, reason? }
|
|
109
|
-
// { type: 'usage', tokens: { input, output }, model }
|
|
110
|
-
// { type: 'error', message }
|
|
111
|
-
// { type: 'done' }
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
## Usage Patterns
|
|
115
|
-
|
|
116
|
-
### Define an Agent
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
const todoAssistant = pikkuAIAgent({
|
|
120
|
-
name: 'todo-assistant',
|
|
121
|
-
description: 'A helpful assistant that manages todos',
|
|
122
|
-
instructions:
|
|
123
|
-
'You help users manage their todo lists. Be concise and helpful.',
|
|
124
|
-
model: 'openai/gpt-5-mini',
|
|
125
|
-
tools: [listTodos, createTodo, completeTodo],
|
|
126
|
-
memory: {
|
|
127
|
-
storage: 'aiStorage',
|
|
128
|
-
lastMessages: 20,
|
|
129
|
-
},
|
|
130
|
-
maxSteps: 5,
|
|
131
|
-
temperature: 0.7,
|
|
132
|
-
})
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
### Invoke Non-Streaming
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
const result = await runAIAgent(
|
|
139
|
-
'todo-assistant',
|
|
140
|
-
{
|
|
141
|
-
message: 'Create a task for tomorrow: buy groceries',
|
|
142
|
-
threadId: 'thread-123',
|
|
143
|
-
resourceId: 'user-456',
|
|
144
|
-
},
|
|
145
|
-
{ singletonServices }
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
console.log(result.text) // "I've created a task 'buy groceries' for tomorrow."
|
|
149
|
-
console.log(result.steps) // [{ tool: 'createTodo', args: {...}, result: {...} }]
|
|
150
|
-
console.log(result.usage) // { inputTokens: 150, outputTokens: 42 }
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### Stream Responses
|
|
154
|
-
|
|
155
|
-
```typescript
|
|
156
|
-
await streamAIAgent(
|
|
157
|
-
'todo-assistant',
|
|
158
|
-
{
|
|
159
|
-
message: 'Create a task for tomorrow',
|
|
160
|
-
threadId: 'thread-123',
|
|
161
|
-
resourceId: 'user-456',
|
|
162
|
-
},
|
|
163
|
-
channel,
|
|
164
|
-
{ singletonServices }
|
|
165
|
-
)
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## Complete Example
|
|
169
|
-
|
|
170
|
-
```typescript
|
|
171
|
-
// functions/todos.functions.ts
|
|
172
|
-
export const listTodos = pikkuSessionlessFunc({
|
|
173
|
-
description: 'List all todo items',
|
|
174
|
-
func: async ({ db }, { status }) => {
|
|
175
|
-
return { todos: await db.listTodos(status) }
|
|
176
|
-
},
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
export const createTodo = pikkuFunc({
|
|
180
|
-
description: 'Create a new todo item',
|
|
181
|
-
func: async ({ db }, { text, priority, dueDate }) => {
|
|
182
|
-
return await db.createTodo({ text, priority, dueDate })
|
|
183
|
-
},
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
export const completeTodo = pikkuFunc({
|
|
187
|
-
description: 'Mark a todo as complete',
|
|
188
|
-
func: async ({ db }, { todoId }) => {
|
|
189
|
-
return await db.completeTodo(todoId)
|
|
190
|
-
},
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
// agents/todo-assistant.ts
|
|
194
|
-
const todoAssistant = pikkuAIAgent({
|
|
195
|
-
name: 'todo-assistant',
|
|
196
|
-
description: 'A helpful assistant that manages todos',
|
|
197
|
-
instructions: `You help users manage their todo lists.
|
|
198
|
-
- Be concise and helpful
|
|
199
|
-
- When creating todos, infer priority if not specified
|
|
200
|
-
- When listing todos, summarize the results`,
|
|
201
|
-
model: 'openai/gpt-5-mini',
|
|
202
|
-
tools: [listTodos, createTodo, completeTodo],
|
|
203
|
-
memory: {
|
|
204
|
-
storage: 'aiStorage',
|
|
205
|
-
lastMessages: 20,
|
|
206
|
-
},
|
|
207
|
-
maxSteps: 5,
|
|
208
|
-
temperature: 0.7,
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
// Wire to HTTP for chat endpoint
|
|
212
|
-
wireHTTP({
|
|
213
|
-
method: 'post',
|
|
214
|
-
route: '/chat',
|
|
215
|
-
func: pikkuFunc({
|
|
216
|
-
title: 'Chat',
|
|
217
|
-
func: async (services, { message, threadId }, wire) => {
|
|
218
|
-
const { session } = wire
|
|
219
|
-
return await runAIAgent(
|
|
220
|
-
'todo-assistant',
|
|
221
|
-
{
|
|
222
|
-
message,
|
|
223
|
-
threadId,
|
|
224
|
-
resourceId: session.userId,
|
|
225
|
-
},
|
|
226
|
-
{ singletonServices: services }
|
|
227
|
-
)
|
|
228
|
-
},
|
|
229
|
-
}),
|
|
230
|
-
})
|
|
231
|
-
```
|