@kindgi/sdk 0.1.4 → 0.1.5-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +2 -0
- package/dist/client.js.map +1 -1
- package/package.json +10 -10
- package/skills/kindgi-authoring-agents/SKILL.md +25 -1
- package/skills/kindgi-authoring-guardrails/SKILL.md +46 -2
- package/skills/kindgi-authoring-mcp-servers/SKILL.md +6 -4
- package/skills/kindgi-authoring-providers/SKILL.md +39 -14
- package/skills/kindgi-authoring-tools/SKILL.md +26 -0
- package/skills/kindgi-framework-feedback/SKILL.md +4 -3
- package/skills/kindgi-java-authoring-agents/SKILL.md +220 -0
- package/skills/kindgi-java-authoring-flows/SKILL.md +390 -0
- package/skills/kindgi-java-authoring-guardrails/SKILL.md +209 -0
- package/skills/kindgi-java-authoring-tools/SKILL.md +334 -0
- package/skills/kindgi-java-getting-started/SKILL.md +270 -0
- package/skills/kindgi-python-authoring-agents/SKILL.md +20 -2
- package/skills/kindgi-python-authoring-guardrails/SKILL.md +9 -2
- package/skills/kindgi-python-authoring-tools/SKILL.md +35 -4
- package/skills/kindgi-python-getting-started/SKILL.md +1 -1
- package/skills/kindgi-scala-authoring-agents/SKILL.md +217 -0
- package/skills/kindgi-scala-authoring-flows/SKILL.md +357 -0
- package/skills/kindgi-scala-authoring-guardrails/SKILL.md +199 -0
- package/skills/kindgi-scala-authoring-tools/SKILL.md +302 -0
- package/skills/kindgi-scala-getting-started/SKILL.md +302 -0
- package/src/client.ts +9 -0
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: kindgi-scala-getting-started
|
|
3
|
+
description: >
|
|
4
|
+
Getting a Scala Kindgi pack running: what a pack is, scaffolding one
|
|
5
|
+
(`kindgi init <name> --template=scala`) or adding Kindgi to an existing
|
|
6
|
+
sbt app (`kindgi.config.json`, discovery under `kindgi` packages),
|
|
7
|
+
`./kindgiw dev` through sbt's server, the first agent run, connecting a
|
|
8
|
+
real model, flows, calling the Kindgi API from Scala, building an image,
|
|
9
|
+
and the Scala layer's known limits. Load this when an sbt project has no
|
|
10
|
+
`kindgi.config.json` yet and the user asks to "add Kindgi", "make an
|
|
11
|
+
agent", "set up a pack", or when you are orienting in a Scala pack
|
|
12
|
+
(`kindgi.config.json` with `"language": "scala"`) for the first time.
|
|
13
|
+
Authoring tools, guardrails, agents and flows is covered by
|
|
14
|
+
kindgi-scala-authoring-tools, kindgi-scala-authoring-guardrails,
|
|
15
|
+
kindgi-scala-authoring-agents and kindgi-scala-authoring-flows; models by
|
|
16
|
+
kindgi-authoring-providers.
|
|
17
|
+
type: core
|
|
18
|
+
library: "kindgi-pack-scala"
|
|
19
|
+
version: "0.1.0"
|
|
20
|
+
sdk_version: "0.0.0"
|
|
21
|
+
pack_languages: [scala]
|
|
22
|
+
sources:
|
|
23
|
+
- sdks/scala/README.md
|
|
24
|
+
- site/src/content/docs/start/quickstart-scala.md
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
# Getting started with Kindgi in Scala
|
|
28
|
+
|
|
29
|
+
> **Running `kindgi`:** the pack pins its CLI (`"cli"` in
|
|
30
|
+
> `kindgi.config.json`), and `./kindgiw` runs that version (`kindgiw.cmd` on
|
|
31
|
+
> Windows): through Node's `npx` when Node is installed, else `uvx`. So every
|
|
32
|
+
> `kindgi <command>` below runs as `./kindgiw <command>`. `./kindgiw upgrade`
|
|
33
|
+
> moves the pin, and kindgi-pack-scala's version in `build.sbt` with it.
|
|
34
|
+
>
|
|
35
|
+
> **Preview:** Java and Scala support is tested and supported, but its API
|
|
36
|
+
> may still change in 0.1.6 without the usual deprecation period.
|
|
37
|
+
|
|
38
|
+
## What a pack is
|
|
39
|
+
|
|
40
|
+
A **pack** is a project Kindgi indexes and runs. Its config is
|
|
41
|
+
`kindgi.config.json` (`"language": "scala"`). Its primitives are the `val`s
|
|
42
|
+
of an object named like its file (`Greet.scala` holds `object Greet`), in
|
|
43
|
+
four kinds of packages:
|
|
44
|
+
|
|
45
|
+
- **Tools** (`…/tools/…`, `Tool[Input, Output](id)`): your Scala code an
|
|
46
|
+
agent or flow calls.
|
|
47
|
+
- **Guardrails** (`…/guardrails/…`, `Guardrail[Config](id)`): checks over an
|
|
48
|
+
agent's turn.
|
|
49
|
+
- **Agents** (`…/agents/…`, `Agent(id)`): data. Instructions, tools,
|
|
50
|
+
capabilities. The model runs in Kindgi.
|
|
51
|
+
- **Flows** (`…/flows/…`, `Flow(id)`): data. Steps (tool or agent nodes) and
|
|
52
|
+
the edges between them.
|
|
53
|
+
|
|
54
|
+
The Scala layer (`com.kindgi %% kindgi-pack-scala`, package
|
|
55
|
+
`com.kindgi.pack.scaladsl`) is thin, over the Java SDK: kindgi-pack's
|
|
56
|
+
indexer reads the pack, and its pack service runs the tools and checks in
|
|
57
|
+
the pack's own JVM, called over HTTP. Everything else runs in the Kindgi
|
|
58
|
+
runtime. It's built for Scala 2.13 and 3.3. In those packages:
|
|
59
|
+
- An object with no primitives, or a file with no object (a case class, a
|
|
60
|
+
trait), is a helper.
|
|
61
|
+
- A primitive defined as a `def` or a `lazy val` is an error: make it a
|
|
62
|
+
`val`.
|
|
63
|
+
- Tests (`src/test/`) are never primitives.
|
|
64
|
+
|
|
65
|
+
## Scaffold a new pack
|
|
66
|
+
|
|
67
|
+
You need a JDK 17 or later (`JAVA_HOME`) and sbt.
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
npx --yes @kindgi/cli@0.1 init my-pack --template=scala # or: uvx --from "kindgi-cli>=0.1,<0.2" kindgi init …
|
|
71
|
+
cd my-pack
|
|
72
|
+
sbt test # the template's tests: the tools, called directly
|
|
73
|
+
./kindgiw dev # boots Kindgi locally and runs this pack, recompiling on save
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`kindgi dev` needs Docker and Postgres. It starts Postgres in Docker unless
|
|
77
|
+
`KINDGI_DATABASE_URL` points at yours. It compiles through sbt's server
|
|
78
|
+
(`sbt --client`), so a save compiles in about a second once it's warm.
|
|
79
|
+
- When no sbt server is running, it starts one, and stops it when it stops.
|
|
80
|
+
- A server you already run (your IDE's) is used and left running.
|
|
81
|
+
- A compile error is reported as `file:line:col`, and the last good code
|
|
82
|
+
keeps serving.
|
|
83
|
+
- It uses `JAVA_HOME`'s JDK (or `dev.javaHome` in `kindgi.config.json`) and
|
|
84
|
+
the `sbt` on your `PATH` (or `dev.sbt`, such as `["sbt", "-mem", "2048"]`).
|
|
85
|
+
- `SBT_OPTS` reaches sbt, never the pack.
|
|
86
|
+
|
|
87
|
+
## Add Kindgi to an existing sbt app
|
|
88
|
+
|
|
89
|
+
In the app's directory (where its `build.sbt` is):
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
npx --yes @kindgi/cli@0.1 init # --pack-id=<id> if the build's name doesn't make one
|
|
93
|
+
./kindgiw dev
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
`init` writes `kindgi.config.json`:
|
|
97
|
+
- the pack id, from the build's `name`, and its version;
|
|
98
|
+
- the CLI version it pins (`"cli"`, which `./kindgiw` runs, also written);
|
|
99
|
+
- discovery under `kindgi` packages (`src/main/scala/**/kindgi/tools/**/*.scala`
|
|
100
|
+
and so on), so the app's own `tools` packages are never taken for
|
|
101
|
+
Kindgi's.
|
|
102
|
+
|
|
103
|
+
It leaves `build.sbt` alone, and prints the dependency to add (from Maven
|
|
104
|
+
Central, at the CLI's version):
|
|
105
|
+
|
|
106
|
+
```scala
|
|
107
|
+
libraryDependencies += "com.kindgi" %% "kindgi-pack-scala" % "…"
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
It also adds these skills and `.gitignore` entries. An app with a
|
|
111
|
+
`build.sbt` next to a `package.json` or a `pom.xml` gets a TypeScript or Java
|
|
112
|
+
pack unless you pass `--template=scala`.
|
|
113
|
+
|
|
114
|
+
A tool there is a `val` of an object in a `kindgi.tools` package under the
|
|
115
|
+
app's own (`com.acme.app.kindgi.tools`), and calls the app's code directly. A
|
|
116
|
+
library a tool uses must be on the runtime classpath (not `% Test` or
|
|
117
|
+
`% Provided`): the image ships the runtime classpath only. `kindgi dev` reads
|
|
118
|
+
the app's `.env` and `.env.local`: keys already there reach the tools as
|
|
119
|
+
environment variables.
|
|
120
|
+
|
|
121
|
+
## Layout of the template
|
|
122
|
+
|
|
123
|
+
```
|
|
124
|
+
my-pack/
|
|
125
|
+
├── kindgi.config.json # "language": "scala", the pack's id and version, the CLI it pins
|
|
126
|
+
├── build.sbt # kindgi-pack-scala, Scala 3.3, Java 17
|
|
127
|
+
├── project/build.properties # the sbt version
|
|
128
|
+
├── kindgiw, kindgiw.cmd # the Kindgi CLI wrapper
|
|
129
|
+
├── src/main/scala/mypack/
|
|
130
|
+
│ ├── tools/Echo.scala, tools/Greet.scala # Tool[Input, Output](...)
|
|
131
|
+
│ ├── guardrails/ResponseNotEmpty.scala # Guardrail[Config](...)
|
|
132
|
+
│ ├── agents/EchoAgent.scala # Agent(...)
|
|
133
|
+
│ └── flows/EchoFlow.scala # Flow(...)
|
|
134
|
+
├── src/test/scala/mypack/ToolsSuite.scala # the tools, called directly (munit)
|
|
135
|
+
└── .claude/skills/ # these skills (`./kindgiw skills sync` refreshes them)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
The package comes from the pack's id, with Java's and Scala's keywords
|
|
139
|
+
escaped (`my-pack` becomes `mypack`). `kindgi.config.json` also takes
|
|
140
|
+
`discovery`, `dev`, `env`, `environments`, `image` and `providers`.
|
|
141
|
+
|
|
142
|
+
## First run
|
|
143
|
+
|
|
144
|
+
With `kindgi dev` running, from another terminal in the pack directory:
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
./kindgiw runs start --agent=my-pack.echo-agent --input='{"userMessage":"Ada"}'
|
|
148
|
+
./kindgiw runs start --flow=my-pack.echo-flow --input='{"message":"Ada"}'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
The agent's answer comes from `dev-echo`, a **fallback** provider a new pack
|
|
152
|
+
gets: no model, no key. It calls the agent's first tool with
|
|
153
|
+
`{"message": <userMessage>}` and replies "⚠ dev-echo isn't a real model: …",
|
|
154
|
+
then "Tool responded: …". The turn carries the `fallback-provider` and
|
|
155
|
+
`dev-echo-not-a-model` warnings. It can't fill in any other tool's input,
|
|
156
|
+
and it can't give a typed answer. For a real model, store an LLM provider's
|
|
157
|
+
key and register its preset (Anthropic below; `./kindgiw providers presets`
|
|
158
|
+
lists OpenAI, Gemini, Groq and OpenRouter too):
|
|
159
|
+
|
|
160
|
+
```sh
|
|
161
|
+
./kindgiw secrets set ANTHROPIC_API_KEY --env=local --scope=tenant # no-echo prompt; writes .env.local
|
|
162
|
+
./kindgiw providers register --preset=anthropic
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
It takes over at the next turn. That registration is in this project's dev
|
|
166
|
+
database only. To have `kindgi dev` register it on every boot, in every
|
|
167
|
+
worktree and after `--reset`, declare it in `kindgi.config.json`:
|
|
168
|
+
`"providers": [{"preset": "anthropic"}]` (its key, `ANTHROPIC_API_KEY`, comes
|
|
169
|
+
from the env files). Details and other providers: `kindgi-authoring-providers`.
|
|
170
|
+
|
|
171
|
+
To see what Kindgi sees (the index), with no runtime:
|
|
172
|
+
|
|
173
|
+
```sh
|
|
174
|
+
java -cp "$(sbt -batch -error 'export Runtime/fullClasspath')" com.kindgi.pack.Main index --pack-dir .
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## Flows
|
|
178
|
+
|
|
179
|
+
A flow is data: nodes and edges (`flow.schema.json`). A node's ref may be
|
|
180
|
+
the `Tool` itself:
|
|
181
|
+
|
|
182
|
+
```scala
|
|
183
|
+
val flow: Flow = Flow("acme.ledger.record-flow")
|
|
184
|
+
.version("0.1.0")
|
|
185
|
+
.toolNode("record", RecordExpense.tool)
|
|
186
|
+
.edge("e-start", "$start", "record")
|
|
187
|
+
.edge("e-end", "record", "$end")
|
|
188
|
+
.build()
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
A node gets the output of its single upstream node (the run input after
|
|
192
|
+
`$start`), or what its `inputMapping` says. Run one with
|
|
193
|
+
`./kindgiw runs start --flow=<id> --input='{…}'`. For branches, loops and
|
|
194
|
+
agent steps, see `kindgi-scala-authoring-flows`.
|
|
195
|
+
|
|
196
|
+
## Calling Kindgi from Scala
|
|
197
|
+
|
|
198
|
+
The Java client, `com.kindgi:kindgi-client` (on Maven Central, at the same
|
|
199
|
+
version as the CLI), covers the whole API, with typed models and errors,
|
|
200
|
+
and works from Scala as it is:
|
|
201
|
+
|
|
202
|
+
```scala
|
|
203
|
+
import com.kindgi.client.Kindgi
|
|
204
|
+
import com.kindgi.client.models.StartRunBody
|
|
205
|
+
import scala.jdk.CollectionConverters._
|
|
206
|
+
|
|
207
|
+
val client = Kindgi.create() // KINDGI_API_URL + KINDGI_API_TOKEN; in dev, the running kindgi dev
|
|
208
|
+
val run = client.runs().start(StartRunBody.WithAgent.builder()
|
|
209
|
+
.agent("my-pack.echo-agent")
|
|
210
|
+
.input(Map[String, AnyRef]("userMessage" -> "Ada").asJava)
|
|
211
|
+
.build())
|
|
212
|
+
val events = client.runs().follow(run.id())
|
|
213
|
+
try events.asScala.foreach(event => println(event.kind()))
|
|
214
|
+
finally events.close()
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
The methods follow the API's operations: `approvals.reviewers.list` is
|
|
218
|
+
`client.approvals().reviewers().list()`. `client.async()` has the same ones,
|
|
219
|
+
answering `CompletableFuture`s (`scala.jdk.FutureConverters` turns them into
|
|
220
|
+
`Future`s). A refused call throws a typed `KindgiApiException`. The client
|
|
221
|
+
shades its own Jackson, so the app's Jackson is left alone. In production it
|
|
222
|
+
never reads `.kindgirc.json`: set `KINDGI_API_URL` and `KINDGI_API_TOKEN`.
|
|
223
|
+
|
|
224
|
+
## Your app and Kindgi's data
|
|
225
|
+
|
|
226
|
+
When the app keeps something a run did (a ticket a flow triaged, an answer
|
|
227
|
+
an agent gave), its own row stores the run's id, in a column such as
|
|
228
|
+
`kindgi_run_id`. The app reads the rest through the API, server side:
|
|
229
|
+
|
|
230
|
+
- **Status, output, timing:** `client.runs().get(runId)`.
|
|
231
|
+
- **The audit, step by step:** `client.runs().journal(runId)`.
|
|
232
|
+
- **What it cost:** `client.cost().records().list(…)`, filtered by the run.
|
|
233
|
+
- **When a run finished:** the `run.finished` webhook, not polling.
|
|
234
|
+
|
|
235
|
+
Show it in the app's own UI. **Never:**
|
|
236
|
+
|
|
237
|
+
- **query Kindgi's database**, even on the app's own Postgres server, or map
|
|
238
|
+
its tables in Slick, Doobie or Quill. Its schema is private and changes
|
|
239
|
+
with every release, row-level security guards every tenant query, and a
|
|
240
|
+
runtime Kindgi hosts gives no database access.
|
|
241
|
+
- **link users to Kindgi's console**, or any Kindgi UI, for this data.
|
|
242
|
+
|
|
243
|
+
Docs: https://docs.kindgi.com/v0.1/guides/runs/show-runs-in-your-app/
|
|
244
|
+
|
|
245
|
+
## Build an image
|
|
246
|
+
|
|
247
|
+
`./kindgiw build --env=<name>` builds the pack's image for an
|
|
248
|
+
`environments.<name>` block of `kindgi.config.json`; `--local` builds it with
|
|
249
|
+
this machine's Docker. sbt builds it in a pinned sbt + JDK 17 image, fetching
|
|
250
|
+
kindgi-pack-scala and kindgi-pack from Maven Central, and copies the runtime
|
|
251
|
+
classpath as jars. The index is built in the image, and the pack service
|
|
252
|
+
runs on a JRE 17 as its entrypoint, as user 65532.
|
|
253
|
+
|
|
254
|
+
Debian packages the code needs are declared in `kindgi.config.json`, and the
|
|
255
|
+
image installs them: `"image": {"systemPackages": ["tesseract-ocr"]}`
|
|
256
|
+
(names, or `name=version`). So are the variables the code reads, names only:
|
|
257
|
+
`"env": {"required": ["DATABASE_URL"], "optional": ["SENTRY_DSN"]}`. A
|
|
258
|
+
deployed pack service missing a required one isn't ready, and its `/readyz`
|
|
259
|
+
names it.
|
|
260
|
+
|
|
261
|
+
## Known limits
|
|
262
|
+
|
|
263
|
+
- **Scala's primitives inside a type parameter** (`Seq[Int]`,
|
|
264
|
+
`Option[Long]`) are `Object` on the JVM, so the schema allows any JSON
|
|
265
|
+
value there. Use a case class (`Seq[Item]`), or give the schema with
|
|
266
|
+
`Tool.json`.
|
|
267
|
+
- **In Scala 3, name a Java annotation's arguments:** `@Min(value = 0)`, not
|
|
268
|
+
`@Min(0)`.
|
|
269
|
+
- **A Scala 3 enum whose cases take parameters** is a sealed hierarchy, not
|
|
270
|
+
a string: describe it with `@JsonTypeInfo` and `@JsonSubTypes`. A simple
|
|
271
|
+
enum is a string of its case names.
|
|
272
|
+
- **jackson-module-scala must match your app's `jackson-databind` minor
|
|
273
|
+
version.** If your app uses a newer Jackson, depend on the matching
|
|
274
|
+
`jackson-module-scala` yourself.
|
|
275
|
+
|
|
276
|
+
## Two things need the human
|
|
277
|
+
|
|
278
|
+
- **The pack id and version** in `kindgi.config.json`. The id prefixes every
|
|
279
|
+
primitive (`<pack-id>.<name>`): pick it once.
|
|
280
|
+
- **Model credentials.** Ask for the key; never invent or hard-code one.
|
|
281
|
+
|
|
282
|
+
## Next
|
|
283
|
+
|
|
284
|
+
- A tool: `kindgi-scala-authoring-tools`.
|
|
285
|
+
- A guardrail: `kindgi-scala-authoring-guardrails`.
|
|
286
|
+
- An agent: `kindgi-scala-authoring-agents`.
|
|
287
|
+
- A flow: `kindgi-scala-authoring-flows`.
|
|
288
|
+
- A real model: `kindgi-authoring-providers`.
|
|
289
|
+
- An external resource (a database) for the coding agent:
|
|
290
|
+
`kindgi-authoring-mcp-servers`.
|
|
291
|
+
|
|
292
|
+
## Keeping skills up to date
|
|
293
|
+
|
|
294
|
+
`./kindgiw skills sync` refreshes `.claude/skills/` from the CLI's copy
|
|
295
|
+
(local edits are kept unless `--force`). `kindgi dev` says when they are out
|
|
296
|
+
of date.
|
|
297
|
+
|
|
298
|
+
## When the framework itself is the problem
|
|
299
|
+
|
|
300
|
+
If the bug is in Kindgi, kindgi-pack or the Scala layer and not in the
|
|
301
|
+
pack's code, load `kindgi-framework-feedback` and file it with
|
|
302
|
+
`./kindgiw feedback write`.
|
package/src/client.ts
CHANGED
|
@@ -167,6 +167,15 @@ export type {
|
|
|
167
167
|
export { readSse, unwrapSseData } from '@kindgi/client';
|
|
168
168
|
export type { SseEvent, SseReadOptions } from '@kindgi/client';
|
|
169
169
|
|
|
170
|
+
// ---- Signed exports: check one where it's read ----
|
|
171
|
+
export { verifySignedExport } from '@kindgi/client';
|
|
172
|
+
export type {
|
|
173
|
+
ExportSigningKey,
|
|
174
|
+
SignedExportEnvelope,
|
|
175
|
+
SignedExportVerification,
|
|
176
|
+
VerifySignedExportOptions,
|
|
177
|
+
} from '@kindgi/client';
|
|
178
|
+
|
|
170
179
|
// ---- Following a run (browser-safe: a page follows a run with a public token) ----
|
|
171
180
|
export { followRun, subscribeToRun } from '@kindgi/client';
|
|
172
181
|
export type {
|