@flytedesk/app-kit 7.4.1 → 7.5.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/README.md CHANGED
@@ -373,6 +373,42 @@ the consuming app's danxbot config: sms-app uses `audience-chat`, media-planner
373
373
  `planner-chat`. The name must match a configured entry; danxbot rejects an unknown
374
374
  profile with a 4xx.
375
375
 
376
+ ### One-shot danxbot jobs
377
+
378
+ A launcher also starts a job with no conversation, whose end danxbot reports to a URL
379
+ of the app's choosing. Use a launcher whose `profile` is the job's own
380
+ `top_level_agents` entry (sms-app's import repair uses `import-repair`):
381
+
382
+ ```ts
383
+ const { jobId } = await launcher.launchJob({
384
+ task: prompt,
385
+ overlay: { MY_APP_JOB_ID: job.id, MY_APP_JOB_TOKEN: token },
386
+ statusUrl: `${publicApiUrl}/jobs/${job.id}/status`,
387
+ apiToken: token, // sent back to statusUrl as `Authorization: Bearer <token>`
388
+ maxRuntimeMs: 40 * 60_000, // danxbot stops the job after this; a positive integer
389
+ title: "Import repair · UWW.xlsx", // the job's name on danxbot's dashboard
390
+ // model: "opus", effort: "high", // optional, and only together
391
+ });
392
+ ```
393
+
394
+ `launchJob` sends exactly the body danxbot's `POST /api/launch` documents and throws a
395
+ `DanxbotError` (with `httpStatus`) when danxbot refuses it.
396
+
397
+ danxbot then PUTs `{ status, message?, data? }` to `statusUrl`: `running` at once and
398
+ every 10 seconds, then one terminal status (retried 3 times; a lost terminal PUT is
399
+ never re-sent, so an app still needs a sweeper that asks `getJobStatus`). In the status
400
+ route, `parseJobStatusReport(request.body)` validates the body, `isTerminalJobStatus`
401
+ says whether the job is over, and `isFailedJobStatus` whether it ended without doing
402
+ its work. The terminal statuses are `complete`, `completed`, `failed`, `critical_failure`,
403
+ `cancelled`, `canceled`, `timeout`, `checkpointed`, `checkpoint_failed`,
404
+ `waiting_on_dependency`, `api_error_recover`, `api_error_failed`, `api_error_escalated`,
405
+ `rate_limited` and `system_failure`; only `complete` and `completed` succeed. A status
406
+ danxbot adds later reads as still running.
407
+
408
+ The job's MCP tools module (`app-kit-chat-mcp --tools <path>`) need not register a reply
409
+ tool: a module that builds `kit.createChatMcpProtocol({ serverName, tools })` with only
410
+ its own tools is served as it is.
411
+
376
412
  ## Tests
377
413
 
378
414
  `npm run check` is the full gate: lint, typecheck, build, unit tests, integration tests
@@ -7,7 +7,9 @@
7
7
  *
8
8
  * Four pieces, usable independently or together:
9
9
  *
10
- * - `createDanxbotLauncher` — dispatch (and resume) a danxbot chat turn.
10
+ * - `createDanxbotLauncher` — dispatch (and resume) a danxbot chat turn, or launch a
11
+ * one-shot job (`launchJob`) whose end danxbot reports to a URL
12
+ * (`parseJobStatusReport`, `isTerminalJobStatus`, `isFailedJobStatus`).
11
13
  * - `createChatMcpProtocol` + `createReplyTool` — the MCP server the dispatched
12
14
  * agent talks to the user through, with an extension point for app-registered
13
15
  * tools (see AppRegisteredTool).
@@ -92,12 +94,14 @@
92
94
  * for the full contract, why it stays dependency-free, and how a consumer (e.g.
93
95
  * media-planner's MP-169 `loggedProtocol`) wraps `handleMessage` before returning.
94
96
  */
95
- export { createDanxbotLauncher, DanxbotError, isFailedJobStatus, isTerminalJobStatus, } from "./launcher.js";
97
+ export { createDanxbotLauncher, DanxbotError } from "./launcher.js";
98
+ export { isFailedJobStatus, isTerminalJobStatus, parseJobStatusReport, } from "./job-status.js";
96
99
  export { callbackSecretMatches, requireCallbackSecret, } from "./callback-secret.js";
97
100
  export { createChatMcpProtocol, createReplyTool, parseReplyArguments, FALLBACK_PROTOCOL_VERSION, JSON_RPC, } from "./mcp-protocol.js";
98
101
  export { createChatMcpStdioServer } from "./mcp-server.js";
99
102
  export { parseChatEnv, ChatEnvError } from "./env.js";
100
- export type { AppRegisteredTool, ChatEnv, ChatToolCallResult, ChatToolContent, DanxbotDispatchResult, DanxbotJobStatus, DanxbotLauncher, DanxbotLauncherOptions, } from "./types.js";
103
+ export type { AppRegisteredTool, ChatEnv, ChatToolCallResult, ChatToolContent, DanxbotDispatchResult, DanxbotJobStatus, DanxbotLauncher, DanxbotLauncherOptions, LaunchJobInput, } from "./types.js";
104
+ export type { JobStatusReport } from "./job-status.js";
101
105
  export type { ChatMcpProtocol, ChatMcpProtocolOptions, ChatReplyPayload, ParseReplyArgumentsOptions, ReplyDeliverResult, ReplyToolOptions, } from "./mcp-protocol.js";
102
106
  export type { ChatMcpStdioServer, ChatMcpStdioServerOptions, } from "./mcp-server.js";
103
107
  export type { BuildChatServer, ChatMcpKit } from "./mcp/entry.js";
@@ -7,7 +7,9 @@
7
7
  *
8
8
  * Four pieces, usable independently or together:
9
9
  *
10
- * - `createDanxbotLauncher` — dispatch (and resume) a danxbot chat turn.
10
+ * - `createDanxbotLauncher` — dispatch (and resume) a danxbot chat turn, or launch a
11
+ * one-shot job (`launchJob`) whose end danxbot reports to a URL
12
+ * (`parseJobStatusReport`, `isTerminalJobStatus`, `isFailedJobStatus`).
11
13
  * - `createChatMcpProtocol` + `createReplyTool` — the MCP server the dispatched
12
14
  * agent talks to the user through, with an extension point for app-registered
13
15
  * tools (see AppRegisteredTool).
@@ -92,7 +94,8 @@
92
94
  * for the full contract, why it stays dependency-free, and how a consumer (e.g.
93
95
  * media-planner's MP-169 `loggedProtocol`) wraps `handleMessage` before returning.
94
96
  */
95
- export { createDanxbotLauncher, DanxbotError, isFailedJobStatus, isTerminalJobStatus, } from "./launcher.js";
97
+ export { createDanxbotLauncher, DanxbotError } from "./launcher.js";
98
+ export { isFailedJobStatus, isTerminalJobStatus, parseJobStatusReport, } from "./job-status.js";
96
99
  export { callbackSecretMatches, requireCallbackSecret, } from "./callback-secret.js";
97
100
  export { createChatMcpProtocol, createReplyTool, parseReplyArguments, FALLBACK_PROTOCOL_VERSION, JSON_RPC, } from "./mcp-protocol.js";
98
101
  export { createChatMcpStdioServer } from "./mcp-server.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6FG;AACH,OAAO,EACL,qBAAqB,EACrB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/chat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+FG;AACH,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,oBAAoB,GACrB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,yBAAyB,EACzB,QAAQ,GACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,wBAAwB,EAAE,MAAM,iBAAiB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * danxbot's job status vocabulary, as a job's end is reported to a consuming app.
3
+ *
4
+ * danxbot PUTs `{status, message?, data?}` to the `status_url` given at launch:
5
+ * `running` at once and every 10 s while the job lives, then ONE terminal status, which
6
+ * its `putStatus` (`src/agent/agent-status.ts`) retries 3 times. It treats every status
7
+ * other than `running` as terminal. The terminal strings come from three places and are
8
+ * not one tidy enum, which is why this module spells them out:
9
+ *
10
+ * - the agent's own `danxbot_complete` call: `complete`, `cancelled`, `failed`,
11
+ * `critical_failure`, `waiting_on_dependency` (`complete-status.ts`);
12
+ * - the worker's internal complete statuses: `api_error_recover`, `api_error_failed`,
13
+ * `api_error_escalated`, `rate_limited`, `system_failure` (`complete-status.ts`);
14
+ * - the in-memory job statuses the worker PUTs when it ends a job itself: `completed`
15
+ * and `failed` (the exit handler, `spawn-docker-mode.ts`), `canceled` (`/api/cancel`,
16
+ * `launcher.ts`), `timeout` (the inactivity and max-runtime timers,
17
+ * `attach-monitoring-stack.ts`), `checkpointed` and `checkpoint_failed` (the token
18
+ * ceiling, `attach-monitoring-stack.ts`).
19
+ *
20
+ * `cancelled` (two l) and `canceled` (one l) are two different strings from two
21
+ * different producers; both are real.
22
+ */
23
+ /**
24
+ * True when danxbot will report nothing more for this job. Anything else, including a
25
+ * status danxbot adds later, is treated as still in flight, so a new status can never
26
+ * make a consumer declare a live job dead.
27
+ */
28
+ export declare function isTerminalJobStatus(status: string): boolean;
29
+ /** A terminal status that is terminal because the job did NOT finish its work. */
30
+ export declare function isFailedJobStatus(status: string): boolean;
31
+ /** The body danxbot PUTs to a job's `status_url`. */
32
+ export interface JobStatusReport {
33
+ status: string;
34
+ message?: string;
35
+ data?: Record<string, unknown>;
36
+ }
37
+ /**
38
+ * Validate the body of a danxbot status PUT. The status route is the app's own HTTP
39
+ * endpoint, so a malformed body is the app's to reject; this is the shared parser it
40
+ * calls first. Returns a result rather than throwing, like `parseReplyArguments`.
41
+ */
42
+ export declare function parseJobStatusReport(body: unknown): {
43
+ ok: true;
44
+ value: JobStatusReport;
45
+ } | {
46
+ ok: false;
47
+ message: string;
48
+ };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * danxbot's job status vocabulary, as a job's end is reported to a consuming app.
3
+ *
4
+ * danxbot PUTs `{status, message?, data?}` to the `status_url` given at launch:
5
+ * `running` at once and every 10 s while the job lives, then ONE terminal status, which
6
+ * its `putStatus` (`src/agent/agent-status.ts`) retries 3 times. It treats every status
7
+ * other than `running` as terminal. The terminal strings come from three places and are
8
+ * not one tidy enum, which is why this module spells them out:
9
+ *
10
+ * - the agent's own `danxbot_complete` call: `complete`, `cancelled`, `failed`,
11
+ * `critical_failure`, `waiting_on_dependency` (`complete-status.ts`);
12
+ * - the worker's internal complete statuses: `api_error_recover`, `api_error_failed`,
13
+ * `api_error_escalated`, `rate_limited`, `system_failure` (`complete-status.ts`);
14
+ * - the in-memory job statuses the worker PUTs when it ends a job itself: `completed`
15
+ * and `failed` (the exit handler, `spawn-docker-mode.ts`), `canceled` (`/api/cancel`,
16
+ * `launcher.ts`), `timeout` (the inactivity and max-runtime timers,
17
+ * `attach-monitoring-stack.ts`), `checkpointed` and `checkpoint_failed` (the token
18
+ * ceiling, `attach-monitoring-stack.ts`).
19
+ *
20
+ * `cancelled` (two l) and `canceled` (one l) are two different strings from two
21
+ * different producers; both are real.
22
+ */
23
+ /** The statuses that mean the job did its work. Every other terminal status is a job
24
+ * that did NOT finish, even when danxbot does not count it as a fault (a checkpoint
25
+ * or a dependency wait ends the session without a result). */
26
+ const SUCCEEDED_JOB_STATUSES = new Set(["complete", "completed"]);
27
+ const TERMINAL_JOB_STATUSES = new Set([
28
+ ...SUCCEEDED_JOB_STATUSES,
29
+ "failed",
30
+ "critical_failure",
31
+ "cancelled",
32
+ "canceled",
33
+ "timeout",
34
+ "checkpointed",
35
+ "checkpoint_failed",
36
+ "waiting_on_dependency",
37
+ "api_error_recover",
38
+ "api_error_failed",
39
+ "api_error_escalated",
40
+ "rate_limited",
41
+ "system_failure",
42
+ ]);
43
+ /**
44
+ * True when danxbot will report nothing more for this job. Anything else, including a
45
+ * status danxbot adds later, is treated as still in flight, so a new status can never
46
+ * make a consumer declare a live job dead.
47
+ */
48
+ export function isTerminalJobStatus(status) {
49
+ return TERMINAL_JOB_STATUSES.has(status);
50
+ }
51
+ /** A terminal status that is terminal because the job did NOT finish its work. */
52
+ export function isFailedJobStatus(status) {
53
+ return isTerminalJobStatus(status) && !SUCCEEDED_JOB_STATUSES.has(status);
54
+ }
55
+ /**
56
+ * Validate the body of a danxbot status PUT. The status route is the app's own HTTP
57
+ * endpoint, so a malformed body is the app's to reject; this is the shared parser it
58
+ * calls first. Returns a result rather than throwing, like `parseReplyArguments`.
59
+ */
60
+ export function parseJobStatusReport(body) {
61
+ if (body === null || typeof body !== "object" || Array.isArray(body)) {
62
+ return { ok: false, message: "The body must be an object with a `status`." };
63
+ }
64
+ const { status, message, data } = body;
65
+ if (typeof status !== "string" || status.trim() === "") {
66
+ return { ok: false, message: "`status` must be a non-empty string." };
67
+ }
68
+ if (message !== undefined && message !== null && typeof message !== "string") {
69
+ return { ok: false, message: "`message` must be a string." };
70
+ }
71
+ if (data !== undefined && data !== null && (typeof data !== "object" || Array.isArray(data))) {
72
+ return { ok: false, message: "`data` must be an object." };
73
+ }
74
+ const value = { status };
75
+ if (typeof message === "string")
76
+ value.message = message;
77
+ if (data !== undefined && data !== null)
78
+ value.data = data;
79
+ return { ok: true, value };
80
+ }
81
+ //# sourceMappingURL=job-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"job-status.js","sourceRoot":"","sources":["../../src/chat/job-status.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;+DAE+D;AAC/D,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAC;AAElE,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC;IACpC,GAAG,sBAAsB;IACzB,QAAQ;IACR,kBAAkB;IAClB,WAAW;IACX,UAAU;IACV,SAAS;IACT,cAAc;IACd,mBAAmB;IACnB,uBAAuB;IACv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,EAAE,KAAK,EAAE,OAAO,EAAE,2BAA2B,EAAE,CAAC;IAC7D,CAAC;IAED,MAAM,KAAK,GAAoB,EAAE,MAAM,EAAE,CAAC;IAC1C,IAAI,OAAO,OAAO,KAAK,QAAQ;QAAE,KAAK,CAAC,OAAO,GAAG,OAAO,CAAC;IACzD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI;QAAE,KAAK,CAAC,IAAI,GAAG,IAA+B,CAAC;IACtF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AAC7B,CAAC"}
@@ -15,6 +15,11 @@
15
15
  * "input_tokens":…,"output_tokens":…,"cache_read_input_tokens":…,
16
16
  * "cache_creation_input_tokens":…}
17
17
  *
18
+ * POST /api/launch {board, profile, task, overlay, status_url, api_token,
19
+ * max_runtime_ms, title, model?, effort?}
20
+ * -> a one-shot job (launchJob): danxbot PUTs {status, message?, data?} to
21
+ * `status_url` as the job runs and ends — see job-status.ts.
22
+ *
18
23
  * `resume` is what makes a thread a thread: passing the previous turn's `job_id`
19
24
  * resumes the underlying Claude session (`claude --resume`), so a later turn
20
25
  * remembers an earlier one. `overlay` is danxbot's per-dispatch substitution map:
@@ -38,6 +43,3 @@ export declare class DanxbotError extends Error {
38
43
  * mutable state of its own.
39
44
  */
40
45
  export declare function createDanxbotLauncher(options: DanxbotLauncherOptions): DanxbotLauncher;
41
- export declare function isTerminalJobStatus(status: string): boolean;
42
- /** A terminal status that is terminal because something went WRONG. */
43
- export declare function isFailedJobStatus(status: string): boolean;
@@ -41,6 +41,26 @@ async function danxbotFetch(options, path, init) {
41
41
  throw new DanxbotError(`danxbot ${init.method} ${path} returned unparseable body: ${text}`, response.status);
42
42
  }
43
43
  }
44
+ /** POST a launch or resume body and read the job id off danxbot's answer. A 200
45
+ * without a `job_id` is a broken worker, not a job: it is refused here so no caller
46
+ * holds an undefined id it would later poll or wait on. */
47
+ async function postDispatch(options, path, body) {
48
+ const result = await danxbotFetch(options, path, { method: "POST", body });
49
+ if (typeof result.job_id !== "string" || result.job_id === "") {
50
+ throw new DanxbotError(`danxbot POST ${path} answered without a job_id`, 200);
51
+ }
52
+ return { job_id: result.job_id, parent_job_id: result.parent_job_id };
53
+ }
54
+ /** danxbot ignores a `max_runtime_ms` that is not a number and runs the job with no
55
+ * cap, so a bad value is refused here rather than launching an unbounded job. */
56
+ function assertValidLaunchJobInput(input) {
57
+ if (!Number.isInteger(input.maxRuntimeMs) || input.maxRuntimeMs <= 0) {
58
+ throw new RangeError(`maxRuntimeMs must be a positive integer; got ${input.maxRuntimeMs}`);
59
+ }
60
+ if ((input.model === undefined) !== (input.effort === undefined)) {
61
+ throw new TypeError("model and effort must be given together: danxbot refuses a partial override.");
62
+ }
63
+ }
44
64
  /**
45
65
  * Create a launcher bound to one board/profile pair. One instance per consumer app
46
66
  * (or per board, for an app dispatching onto more than one) — cheap, holds no
@@ -62,9 +82,31 @@ export function createDanxbotLauncher(options) {
62
82
  overlay: input.overlay,
63
83
  ...(input.parentJobId ? { job_id: input.parentJobId } : {}),
64
84
  };
65
- const result = await danxbotFetch(options, input.parentJobId ? "/api/resume" : "/api/launch", { method: "POST", body });
85
+ const result = await postDispatch(options, input.parentJobId ? "/api/resume" : "/api/launch", body);
66
86
  return { jobId: result.job_id, parentJobId: result.parent_job_id };
67
87
  },
88
+ /**
89
+ * Launch a one-shot job: a session with no conversation, whose end danxbot
90
+ * reports to `statusUrl` (sending `apiToken` back as the `Authorization: Bearer`
91
+ * of every status PUT) and which danxbot stops after `maxRuntimeMs`. `title`
92
+ * names the job on danxbot's dashboard. Sends exactly danxbot's documented
93
+ * `/api/launch` body.
94
+ */
95
+ async launchJob(input) {
96
+ assertValidLaunchJobInput(input);
97
+ const result = await postDispatch(options, "/api/launch", {
98
+ board: options.board,
99
+ profile: options.profile,
100
+ task: input.task,
101
+ overlay: input.overlay,
102
+ status_url: input.statusUrl,
103
+ api_token: input.apiToken,
104
+ max_runtime_ms: input.maxRuntimeMs,
105
+ title: input.title,
106
+ ...(input.model !== undefined ? { model: input.model, effort: input.effort } : {}),
107
+ });
108
+ return { jobId: result.job_id };
109
+ },
68
110
  async getJobStatus(jobId) {
69
111
  const result = await danxbotFetch(options, `/api/status/${encodeURIComponent(jobId)}`, { method: "GET" });
70
112
  return {
@@ -80,24 +122,4 @@ export function createDanxbotLauncher(options) {
80
122
  },
81
123
  };
82
124
  }
83
- /**
84
- * danxbot job statuses that mean "this job will never produce anything more".
85
- * Anything else (including an unknown one — danxbot owns this vocabulary and may
86
- * grow it) is treated as still in flight, so a status danxbot adds later can never
87
- * make a consumer declare a live turn dead.
88
- */
89
- const TERMINAL_JOB_STATUSES = new Set([
90
- "completed",
91
- "failed",
92
- "critical_failure",
93
- "cancelled",
94
- "aborted",
95
- ]);
96
- export function isTerminalJobStatus(status) {
97
- return TERMINAL_JOB_STATUSES.has(status);
98
- }
99
- /** A terminal status that is terminal because something went WRONG. */
100
- export function isFailedJobStatus(status) {
101
- return isTerminalJobStatus(status) && status !== "completed";
102
- }
103
125
  //# sourceMappingURL=launcher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"launcher.js","sourceRoot":"","sources":["../../src/chat/launcher.ts"],"names":[],"mappings":"AA8BA;;;;;GAKG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IAG1B;IAFX,YACE,OAAe,EACN,UAAyB;QAElC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFN,eAAU,GAAV,UAAU,CAAe;QAGlC,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AAED,KAAK,UAAU,YAAY,CACzB,OAA+B,EAC/B,IAAY,EACZ,IAAgD;IAEhD,IAAI,QAAkB,CAAC;IACvB,IAAI,CAAC;QACH,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,EAAE,EAAE;YACjD,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE;gBACP,aAAa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atus {
10
10
  jobId: string;
11
- /** danxbot's own vocabulary — "running", "completed", "failed", "critical_failure", … */
11
+ /** danxbot's own vocabulary — "running", "complete", "failed", "timeout", … (the
12
+ * terminal ones are listed in job-status.ts). */
12
13
  status: string;
13
14
  summary: string;
14
15
  elapsedSeconds: number;
@@ -33,6 +34,27 @@ export interface DanxbotLauncherOptions {
33
34
  * (see the README "Chat" section). */
34
35
  profile: string;
35
36
  }
37
+ /** What a one-shot job needs on top of the launcher's board and profile. */
38
+ export type LaunchJobInput = {
39
+ task: string;
40
+ overlay: Record<string, string>;
41
+ /** Where danxbot PUTs `{status, message?, data?}` as the job runs and ends
42
+ * (see job-status.ts). */
43
+ statusUrl: string;
44
+ /** Sent back to `statusUrl` as its `Authorization: Bearer`: the app's own per-job
45
+ * credential, not the launcher's `apiToken`. */
46
+ apiToken: string;
47
+ /** danxbot stops the job after this many milliseconds. A positive integer. */
48
+ maxRuntimeMs: number;
49
+ /** The job's name on danxbot's dashboard. */
50
+ title: string;
51
+ } & ({
52
+ model?: undefined;
53
+ effort?: undefined;
54
+ } | {
55
+ model: string;
56
+ effort: string;
57
+ });
36
58
  export interface DanxbotLauncher {
37
59
  /** Dispatch one chat turn — see dispatchChatTurn's own doc comment for the
38
60
  * launch-vs-resume branching. */
@@ -41,6 +63,9 @@ export interface DanxbotLauncher {
41
63
  overlay: Record<string, string>;
42
64
  parentJobId?: string | null;
43
65
  }): Promise<DanxbotDispatchResult>;
66
+ /** Launch a one-shot job that reports its end to a URL — see launchJob's own doc
67
+ * comment in launcher.ts. */
68
+ launchJob(input: LaunchJobInput): Promise<DanxbotDispatchResult>;
44
69
  getJobStatus(jobId: string): Promise<DanxbotJobStatus>;
45
70
  }
46
71
  /** One MCP tool-result content block — the two kinds this module's tools ever return. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flytedesk/app-kit",
3
- "version": "7.4.1",
3
+ "version": "7.5.0",
4
4
  "description": "Shared platform kit for flytedesk apps: flytedesk-id auth (BFF/OIDC client) and a Postgres-native trace/audit layer.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",