@kubb/studio 5.2.5 → 5.2.6
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/index.cjs +20 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/dist/protocol.cjs +4 -0
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.d.ts +584 -2
- package/dist/protocol.js +4 -1
- package/dist/protocol.js.map +1 -1
- package/package.json +4 -4
- package/dist/index-Dq2uq38g.d.ts +0 -579
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AgentPermissions, ClientInfo, createJobId } from "./protocol.js";
|
|
3
3
|
import { Storage } from "unstorage";
|
|
4
4
|
import { Config, Hookable, KubbHooks } from "@kubb/core";
|
|
5
5
|
//#region src/api.d.ts
|
|
@@ -377,5 +377,5 @@ type PollOptions = {
|
|
|
377
377
|
*/
|
|
378
378
|
export declare function pollForPairingToken({ studioUrl, session, signal }: PollOptions): Promise<PairingResult>;
|
|
379
379
|
//#endregion
|
|
380
|
-
export type
|
|
380
|
+
export { type Client, type ClientOptions, type ConnectionOptions, type StudioConnectedContext, createJobId };
|
|
381
381
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-CRm0XQPb.js";
|
|
2
|
-
import { isCommandMessage, isDisconnectMessage, isStudioPingMessage, isStudioReadyMessage } from "./protocol.js";
|
|
2
|
+
import { createJobId, isCommandMessage, isDisconnectMessage, isStudioPingMessage, isStudioReadyMessage } from "./protocol.js";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { styleText } from "node:util";
|
|
5
5
|
import { readFile, writeFile } from "node:fs/promises";
|
|
6
|
-
import path from "node:path";
|
|
6
|
+
import path, { isAbsolute, relative, resolve } from "node:path";
|
|
7
7
|
import { spawn } from "node:child_process";
|
|
8
8
|
import { FetchError, ofetch } from "ofetch";
|
|
9
9
|
import { hash, randomBytes } from "node:crypto";
|
|
@@ -559,12 +559,14 @@ async function disconnect({ sessionId, token, studioUrl, slug }) {
|
|
|
559
559
|
});
|
|
560
560
|
console.log(styleText("green", `[${tag}] Disconnected from Studio`));
|
|
561
561
|
} catch (error) {
|
|
562
|
+
const statusCode = error?.statusCode;
|
|
563
|
+
if (statusCode !== void 0 && statusCode >= 400 && statusCode < 500) return;
|
|
562
564
|
console.warn(styleText("yellow", `[${tag}] Failed to notify Studio of disconnection: ${getErrorMessage(error)}`));
|
|
563
565
|
}
|
|
564
566
|
}
|
|
565
567
|
//#endregion
|
|
566
568
|
//#region package.json
|
|
567
|
-
var version = "5.2.
|
|
569
|
+
var version = "5.2.6";
|
|
568
570
|
//#endregion
|
|
569
571
|
//#region src/hooks.ts
|
|
570
572
|
/**
|
|
@@ -1517,6 +1519,9 @@ const CONNECT_TIMEOUT_MS = 5e3;
|
|
|
1517
1519
|
*/
|
|
1518
1520
|
const eventSeqCounters = /* @__PURE__ */ new WeakMap();
|
|
1519
1521
|
const require = createRequire(import.meta.url);
|
|
1522
|
+
function relativeStoragePath(root, filePath) {
|
|
1523
|
+
return (isAbsolute(filePath) ? relative(resolve(root), filePath) : filePath).replaceAll("\\", "/");
|
|
1524
|
+
}
|
|
1520
1525
|
async function resolvePeerDependencies(names) {
|
|
1521
1526
|
const uniqueNames = [...new Set(names.map(toPackageName))];
|
|
1522
1527
|
const peerDependencies = {};
|
|
@@ -1571,9 +1576,10 @@ function sendAgentMessage(ws, message) {
|
|
|
1571
1576
|
* Sends a single `kubb:error` payload to Studio, stamped from the same per-socket counter the event stream
|
|
1572
1577
|
* uses so Studio can still order it against the generation events around it.
|
|
1573
1578
|
*/
|
|
1574
|
-
function sendErrorMessage(ws, error) {
|
|
1579
|
+
function sendErrorMessage(ws, error, jobId) {
|
|
1575
1580
|
sendAgentMessage(ws, {
|
|
1576
1581
|
type: "agent:data",
|
|
1582
|
+
jobId,
|
|
1577
1583
|
payload: {
|
|
1578
1584
|
type: "kubb:error",
|
|
1579
1585
|
data: [{
|
|
@@ -1588,7 +1594,7 @@ function sendErrorMessage(ws, error) {
|
|
|
1588
1594
|
/**
|
|
1589
1595
|
* Forwards selected Kubb lifecycle events to Studio as data messages for the active session.
|
|
1590
1596
|
*/
|
|
1591
|
-
function setupEventsStream(ws, hooks) {
|
|
1597
|
+
function setupEventsStream(ws, hooks, jobId) {
|
|
1592
1598
|
const unhooks = [];
|
|
1593
1599
|
/**
|
|
1594
1600
|
* Registers a listener and keeps its remover, so one generation's listeners come off the session
|
|
@@ -1600,6 +1606,7 @@ function setupEventsStream(ws, hooks) {
|
|
|
1600
1606
|
function sendDataMessage(payload) {
|
|
1601
1607
|
sendAgentMessage(ws, {
|
|
1602
1608
|
type: "agent:data",
|
|
1609
|
+
jobId,
|
|
1603
1610
|
payload: {
|
|
1604
1611
|
...payload,
|
|
1605
1612
|
timestamp: Date.now(),
|
|
@@ -1698,7 +1705,7 @@ function setupEventsStream(ws, hooks) {
|
|
|
1698
1705
|
limit: FILE_READ_CONCURRENCY,
|
|
1699
1706
|
run: async (path) => {
|
|
1700
1707
|
const content = await storage.readItem(path);
|
|
1701
|
-
if (content !== null) files[path] = content;
|
|
1708
|
+
if (content !== null) files[relativeStoragePath(config.root, path)] = content;
|
|
1702
1709
|
}
|
|
1703
1710
|
});
|
|
1704
1711
|
sendDataMessage({
|
|
@@ -1859,6 +1866,7 @@ var StudioSession = class {
|
|
|
1859
1866
|
#session;
|
|
1860
1867
|
#ws;
|
|
1861
1868
|
#studioVersion;
|
|
1869
|
+
#activeJobId = null;
|
|
1862
1870
|
#disposed = false;
|
|
1863
1871
|
#isGenerating = false;
|
|
1864
1872
|
#heartbeatTimer;
|
|
@@ -1906,7 +1914,7 @@ var StudioSession = class {
|
|
|
1906
1914
|
signal?.addEventListener("abort", this.#onAbort, { once: true });
|
|
1907
1915
|
this.#unhooks.push(() => signal?.removeEventListener("abort", this.#onAbort));
|
|
1908
1916
|
this.#heartbeatTimer = setInterval(() => this.#sendHeartbeat(), heartbeatInterval);
|
|
1909
|
-
this.#unhooks.push(this.#hooks.hook("kubb:error", ({ error }) => sendErrorMessage(ws, error)));
|
|
1917
|
+
this.#unhooks.push(this.#hooks.hook("kubb:error", ({ error }) => sendErrorMessage(ws, error, this.#activeJobId ?? "connection")));
|
|
1910
1918
|
} catch (error) {
|
|
1911
1919
|
await this.#hooks.callHook("studio:error", { error: toError(error) });
|
|
1912
1920
|
if (error instanceof InvalidAgentTokenError) throw error;
|
|
@@ -2127,6 +2135,7 @@ var StudioSession = class {
|
|
|
2127
2135
|
return;
|
|
2128
2136
|
}
|
|
2129
2137
|
this.#isGenerating = true;
|
|
2138
|
+
this.#activeJobId = data.jobId;
|
|
2130
2139
|
try {
|
|
2131
2140
|
const config = await loadConfig();
|
|
2132
2141
|
const patch = data.payload;
|
|
@@ -2139,7 +2148,7 @@ var StudioSession = class {
|
|
|
2139
2148
|
await this.#warn(`Ignored the spec from Studio; set ${remedy} to generate from it`);
|
|
2140
2149
|
}
|
|
2141
2150
|
const resolvedPlugins = plugins ?? config.plugins;
|
|
2142
|
-
const detach = [setupHookListener(this.#hooks, root), setupEventsStream(ws, this.#hooks)];
|
|
2151
|
+
const detach = [setupHookListener(this.#hooks, root), setupEventsStream(ws, this.#hooks, data.jobId)];
|
|
2143
2152
|
try {
|
|
2144
2153
|
await generate({
|
|
2145
2154
|
config: {
|
|
@@ -2167,6 +2176,7 @@ var StudioSession = class {
|
|
|
2167
2176
|
});
|
|
2168
2177
|
} finally {
|
|
2169
2178
|
this.#isGenerating = false;
|
|
2179
|
+
this.#activeJobId = null;
|
|
2170
2180
|
}
|
|
2171
2181
|
}
|
|
2172
2182
|
async #handleSave(ws, data, command) {
|
|
@@ -2175,6 +2185,7 @@ var StudioSession = class {
|
|
|
2175
2185
|
await this.#warn("Ignored save: the message carried no edits");
|
|
2176
2186
|
sendAgentMessage(ws, {
|
|
2177
2187
|
type: "agent:save",
|
|
2188
|
+
jobId: data.jobId,
|
|
2178
2189
|
payload: {
|
|
2179
2190
|
outcomes: [],
|
|
2180
2191
|
changed: false
|
|
@@ -2185,6 +2196,7 @@ var StudioSession = class {
|
|
|
2185
2196
|
const edits = data.edits;
|
|
2186
2197
|
const refuse = (reason) => sendAgentMessage(ws, {
|
|
2187
2198
|
type: "agent:save",
|
|
2199
|
+
jobId: data.jobId,
|
|
2188
2200
|
payload: {
|
|
2189
2201
|
outcomes: edits.map((edit) => ({
|
|
2190
2202
|
edit,
|
|
@@ -2208,6 +2220,7 @@ var StudioSession = class {
|
|
|
2208
2220
|
if (changed) await writeFile(configFile, patched, "utf-8");
|
|
2209
2221
|
sendAgentMessage(ws, {
|
|
2210
2222
|
type: "agent:save",
|
|
2223
|
+
jobId: data.jobId,
|
|
2211
2224
|
payload: {
|
|
2212
2225
|
outcomes,
|
|
2213
2226
|
changed,
|
|
@@ -2429,6 +2442,6 @@ async function pollForPairingToken({ studioUrl = agentDefaults.studioUrl, sessio
|
|
|
2429
2442
|
throw new Error("The pairing code expired, pair again");
|
|
2430
2443
|
}
|
|
2431
2444
|
//#endregion
|
|
2432
|
-
export { InvalidAgentTokenError, PairingCanceledError, createClient, createFileStorage, defaultStudioUrl, pollForPairingToken, runConnection, setStorage, startPairing };
|
|
2445
|
+
export { InvalidAgentTokenError, PairingCanceledError, createClient, createFileStorage, createJobId, defaultStudioUrl, pollForPairingToken, runConnection, setStorage, startPairing };
|
|
2433
2446
|
|
|
2434
2447
|
//# sourceMappingURL=index.js.map
|