@cavelon/cli 0.2.12 → 0.2.13

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.
@@ -12,7 +12,7 @@ import { cavelonCommand, fill } from "../printed.js";
12
12
  import { MCP_MAX_WAIT_MS } from "./async.js";
13
13
  import { accessFor, activationStep, mayActivate } from "../access.js";
14
14
  import { AS_CHAT_USER_OPTION, chatUserReader, chatUserReaderError } from "../chat-reader.js";
15
- import { deref, jsonBodySchema } from "../openapi.js";
15
+ import { deref, jsonBodySchema, schemaErrors } from "../openapi.js";
16
16
  import { confinedPath } from "../paths.js";
17
17
  function harnessRef(session, input) {
18
18
  const option = stringOption(input, "harness");
@@ -42,13 +42,30 @@ const CHAT_FILES_ROUTE = "/api/v1/chat/files";
42
42
  const CONVERSATIONS_ROUTE = "/api/v1/conversations";
43
43
  const LOOKUP_MS = 5_000;
44
44
  const unavailable = (message, hint) => new CavelonError(ExitCode.failure, { code: "operation_unavailable", message, hint, details: { sent: false } });
45
- async function bodyFields(ctx, method, route, what, multipart = false) {
45
+ async function bodySchema(ctx, method, route, what, multipart = false) {
46
46
  const { doc, op } = await workflowOperation(ctx, method, route, what);
47
47
  if (!doc)
48
48
  return undefined;
49
49
  const schema = multipart ? op.requestBody?.content?.["multipart/form-data"]?.schema : jsonBodySchema(op);
50
50
  const body = schema ? deref(doc, schema) : undefined;
51
- return body?.properties ?? {};
51
+ return { doc, fields: body?.properties ?? {} };
52
+ }
53
+ async function bodyFields(ctx, method, route, what, multipart = false) {
54
+ return (await bodySchema(ctx, method, route, what, multipart))?.fields;
55
+ }
56
+ function takesApiSource(body) {
57
+ if (!body)
58
+ return true;
59
+ const field = body.fields.source;
60
+ if (!field || typeof field !== "object")
61
+ return false;
62
+ return schemaErrors(body.doc, field, "api").length === 0;
63
+ }
64
+ async function answeringStatus(ctx, harness) {
65
+ if (harness)
66
+ return harness.status;
67
+ const route = await readDefaultRoute(ctx).catch(() => undefined);
68
+ return route?.current?.status;
52
69
  }
53
70
  async function checkDraft(ctx, fields) {
54
71
  if (fields && !fields.preview_draft) {
@@ -177,10 +194,13 @@ export const chat = {
177
194
  "Choose an id with `cavelon api list_chat_users -p tenant_id=<tenant_id>`; email_verified says whether an email-bound\n" +
178
195
  "query can bind that address. Without the option, keeps the usual reader.\n" +
179
196
  "--file uploads a file to the turn's conversation first (POST /api/v1/chat/files) and names it in file_ids, so the\n" +
180
- "solution's wait for a file still being read (settings.attached_documents) can be tried. A personal access token whose\n" +
181
- "role holds playground.use chats as the Playground does: an active solution answers with its unpublished draft where\n" +
182
- "one is pending, with or without --draft. --draft (preview_draft) says so explicitly and is refused before sending where\n" +
183
- "the draft cannot be reached. A tenant API key, and a token without playground.use, chat with the published version.\n" +
197
+ "solution's wait for a file still being read (settings.attached_documents) can be tried. An active solution answers\n" +
198
+ "with its published version, as visitors get it: the kit sends source api, so the turn counts as API traffic (the\n" +
199
+ "tenant's API limits and processing-step cap apply), with a personal access token too. --draft (preview_draft) answers\n" +
200
+ "with the active solution's pending draft as a Playground run instead (counted as testing; needs playground.use, never\n" +
201
+ "a tenant API key) and is refused before sending where the draft cannot be reached. A solution that is not active has no\n" +
202
+ "published version and answers a person's token as a Playground run. An instance that does not publish source on chat\n" +
203
+ "takes a person's chat as a Playground run, which answers with a pending draft; the kit warns about that.\n" +
184
204
  "The first turn carries a session_id the kit chose. A turn that is not answered in time goes on on the instance, which\n" +
185
205
  "stores its answer: the error says how to read the conversation; sending the message again would run it twice. A\n" +
186
206
  "status the instance reports (cancelled, waiting, blocked) is shown. A cancelled turn, and one a recent instance reports\n" +
@@ -196,7 +216,7 @@ export const chat = {
196
216
  session: { type: "string", value: "<session_id>", description: "Continue this conversation (the session_id a previous chat printed)." },
197
217
  "as-chat-user": AS_CHAT_USER_OPTION,
198
218
  file: { type: "string", multiple: true, value: "<path>", description: "Attach this file to the message (uploaded to the conversation first)." },
199
- draft: { type: "boolean", description: "Answer with the active solution's draft, as the Playground does; refused where it cannot (needs playground.use)." },
219
+ draft: { type: "boolean", description: "Answer with the active solution's pending draft as a Playground run, not the published version; needs playground.use." },
200
220
  timeout: { type: "string", value: "<duration>", description: `Wait at most this long for the answer (90s, 5m; default ${DEFAULT_CHAT_TIMEOUT}).` },
201
221
  },
202
222
  examples: [
@@ -219,9 +239,16 @@ export const chat = {
219
239
  const harness = ref ? await findHarness(ctx, ref, source, (slug) => cavelonCommand("chat", fill("message"), "--harness", slug)) : undefined;
220
240
  const draft = boolOption(input, "draft");
221
241
  const files = listOption(input, "file");
222
- const chatFields = draft || files.length ? await bodyFields(ctx, "POST", CHAT_ROUTE, "chatting with a solution") : undefined;
242
+ const chatBody = await bodySchema(ctx, "POST", CHAT_ROUTE, "chatting with a solution");
243
+ const chatFields = chatBody?.fields;
223
244
  if (draft)
224
245
  await checkDraft(ctx, chatFields);
246
+ const status = draft ? undefined : await answeringStatus(ctx, harness);
247
+ const published = !draft && (status === undefined || status === "active");
248
+ const apiSource = published && takesApiSource(chatBody);
249
+ if (published && !apiSource && session.tokenKind !== "api_key" && (await accessFor(await ctx.client()))?.kind !== "api_key") {
250
+ ctx.warn("This instance does not publish source on chat, so it takes a personal access token's chat as a Playground run: an active solution answers with its pending draft where there is one. A tenant API key chats with the published version.");
251
+ }
225
252
  const sessionId = stringOption(input, "session") ?? randomUUID();
226
253
  const attached = await uploadFiles(ctx, files, sessionId, chatFields, deadline);
227
254
  const body = { message, stream: false, ...reader, session_id: sessionId };
@@ -231,6 +258,8 @@ export const chat = {
231
258
  body.file_ids = attached.map((f) => f.file_id);
232
259
  if (draft)
233
260
  body.preview_draft = true;
261
+ if (apiSource)
262
+ body.source = "api";
234
263
  let answer;
235
264
  try {
236
265
  answer = await callStable(ctx, "POST", CHAT_ROUTE, "chatting with a solution", { body, timeoutMs: Math.max(1_000, deadline - Date.now()) });
@@ -255,7 +284,7 @@ export const chat = {
255
284
  const incomplete = "status" in answer && answer.status === null;
256
285
  const said = cancelled ? (answer.response ? [answer.response] : []) : [`${answer.response || (incomplete ? "(no message)" : "(no text)")}${directives}${limit}`];
257
286
  return {
258
- data: { harness: target, ...answer, ...reader, ...(attached.length ? { files: attached } : {}), ...(draft ? { draft: true } : {}), next },
287
+ data: { harness: target, ...answer, ...reader, ...(attached.length ? { files: attached } : {}), ...(draft ? { draft: true } : {}), ...(apiSource ? { source: "api" } : {}), next },
259
288
  text: [
260
289
  ...(reader ? [`Reading as Chat User ${reader.reader_chat_user_id}.`] : []),
261
290
  ...attached.map((f) => `Attached ${f.filename} (${f.file_id}${f.processing_status ? `, ${f.processing_status}` : ""}).`),
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "format": 1,
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "entries": {
5
5
  "omp": [
6
6
  "omp-extension.mjs"
@@ -272,8 +272,8 @@ and never refuses it, so `cavelon validate` warns instead
272
272
  not the tenant's `attached_documents` context-source limit, which bounds how
273
273
  much of the files reaches the model. On an active solution the change goes to
274
274
  the draft; try it with `cavelon chat "<message>" --file <path> --draft` (a
275
- personal access token holding `playground.use` reaches the draft; an API key
276
- gets the published version).
275
+ personal access token holding `playground.use` reaches the draft; without
276
+ `--draft` every credential gets the published version).
277
277
 
278
278
  ## Rules that keep a package portable
279
279
 
@@ -334,7 +334,8 @@ preview too.
334
334
  `cavelon chat "<message>" --harness <solution>` (the `chat` tool over MCP)
335
335
  prints its answer, the session to continue with `--session`, and the
336
336
  conversation to trace. A draft answers only a person's token, as a
337
- Playground run; `--draft` tries an active solution's unpublished draft. On
337
+ Playground run. An active solution answers with its published version, as
338
+ visitors get it; `--draft` tries its unpublished draft instead. On
338
339
  `chat_turn_timeout` the turn goes on and its answer is stored: read the
339
340
  conversation the error names instead of sending the message again.
340
341
  - `cavelon deactivate --harness <solution>` takes an active solution out of
@@ -399,10 +399,11 @@ trace. It reaches an active solution that is not the tenant's default route,
399
399
  which the tenant's chat and widget never answer with; a draft answers only a
400
400
  person's token, as a Playground run. `--file <path>` attaches a file (the
401
401
  solution's wait for a file still being read is `settings.attached_documents`
402
- in `harnesses.yaml`). With a personal access token holding `playground.use`
403
- the chat is a Playground run, so an active solution answers with its pending
404
- draft; `--draft` asks for it explicitly, and an API key gets the published
405
- version. A `chat_turn_timeout` means the turn goes on and its answer is stored:
402
+ in `harnesses.yaml`). An active solution answers with its published version,
403
+ as visitors get it, and the turn counts as API traffic (its limits and the
404
+ processing-step cap apply); `--draft` answers with its pending draft as a
405
+ Playground run instead (a personal access token holding `playground.use`;
406
+ never an API key). A `chat_turn_timeout` means the turn goes on and its answer is stored:
406
407
  never send the message again (it would run twice); read the conversation the
407
408
  error names. A `cancelled` status is a turn stored without an answer. `cavelon api chat` with `harness_id` in
408
409
  the body does the same, but needs the id and a confirm. `cavelon deactivate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cavelon/cli",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
4
4
  "description": "The cavelon binary: CLI and local MCP server for building Cavelon solutions with a coding agent.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/goodguys-gmbh/cavelon-dev-kit",