@vivix-labs/studio-chat-mcp 0.1.16 → 0.1.18
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/chat-ui/index.html +20 -20
- package/dist/server.js +458 -115
- package/dist/setup.js +57 -25
- package/dist/shared.d.ts +6 -0
- package/docs/mcp-instructions.md +8 -0
- package/package.json +1 -1
package/dist/setup.js
CHANGED
|
@@ -1,13 +1,61 @@
|
|
|
1
1
|
// scripts/setup.mjs
|
|
2
|
-
import { execFileSync } from "node:child_process";
|
|
3
2
|
import { randomUUID } from "node:crypto";
|
|
4
3
|
import { homedir } from "node:os";
|
|
5
4
|
import { join } from "node:path";
|
|
6
5
|
import { lstat, mkdir, readFile, realpath, rename, rm, writeFile } from "node:fs/promises";
|
|
7
6
|
import { setTimeout as delay } from "node:timers/promises";
|
|
8
7
|
|
|
9
|
-
// scripts/
|
|
8
|
+
// scripts/cli-launch.mjs
|
|
9
|
+
import { execFileSync } from "node:child_process";
|
|
10
10
|
import { resolve } from "node:path";
|
|
11
|
+
function resolveCliInvocation(cli2, args, { platform = process.platform, execPath = process.execPath } = {}) {
|
|
12
|
+
if (!cli2) throw Error("Missing Vivix Studio CLI entry path.");
|
|
13
|
+
if (/\.[cm]?js$/i.test(cli2)) {
|
|
14
|
+
return { command: execPath, args: [resolve(cli2), ...args] };
|
|
15
|
+
}
|
|
16
|
+
if (platform === "win32") {
|
|
17
|
+
throw Error(
|
|
18
|
+
`Studio Chat setup on Windows requires a JavaScript CLI entry (dist/cli.js), got: ${cli2}`
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
return { command: cli2, args: [...args] };
|
|
22
|
+
}
|
|
23
|
+
function invokeCliJson(cli2, args, { exec = execFileSync, platform = process.platform, execPath = process.execPath } = {}) {
|
|
24
|
+
const invocation = resolveCliInvocation(cli2, [...args, "--json"], { platform, execPath });
|
|
25
|
+
let stdout;
|
|
26
|
+
let spawnError;
|
|
27
|
+
try {
|
|
28
|
+
stdout = exec(invocation.command, invocation.args, {
|
|
29
|
+
encoding: "utf8",
|
|
30
|
+
maxBuffer: 16 * 1024 * 1024,
|
|
31
|
+
stdio: ["ignore", "pipe", "inherit"],
|
|
32
|
+
windowsHide: true
|
|
33
|
+
});
|
|
34
|
+
} catch (error) {
|
|
35
|
+
spawnError = error;
|
|
36
|
+
stdout = error?.stdout;
|
|
37
|
+
}
|
|
38
|
+
if (typeof stdout !== "string" || !stdout.trim()) {
|
|
39
|
+
if (spawnError) throw spawnError;
|
|
40
|
+
throw Error("Studio CLI returned empty output.");
|
|
41
|
+
}
|
|
42
|
+
let reply;
|
|
43
|
+
try {
|
|
44
|
+
reply = JSON.parse(stdout);
|
|
45
|
+
} catch (parseError) {
|
|
46
|
+
if (spawnError) throw spawnError;
|
|
47
|
+
throw parseError;
|
|
48
|
+
}
|
|
49
|
+
if (!reply?.ok)
|
|
50
|
+
throw Object.assign(
|
|
51
|
+
Error((reply?.error?.code ?? "CLI_ERROR") + ": " + (reply?.error?.message ?? "CLI failed.")),
|
|
52
|
+
{ code: reply?.error?.code }
|
|
53
|
+
);
|
|
54
|
+
return reply.data;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// scripts/codex-config.mjs
|
|
58
|
+
import { resolve as resolve2 } from "node:path";
|
|
11
59
|
|
|
12
60
|
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
13
61
|
function getLineColFromPtr(string, ptr) {
|
|
@@ -772,9 +820,9 @@ var LEGACY_KEY_PATTERN = /^vivix-studio-chat-[0-9a-f]{10}$/;
|
|
|
772
820
|
var TABLE_HEADER_PATTERN = /^\s*(\[\[?)\s*([^\[\]]+?)\s*\]\]?\s*(?:#.*)?$/;
|
|
773
821
|
function resolveBridgeLaunch(cli2) {
|
|
774
822
|
if (/\.[cm]?js$/i.test(cli2)) {
|
|
775
|
-
return { command: process.execPath, args: [
|
|
823
|
+
return { command: process.execPath, args: [resolve2(cli2), "agent", "mcp"] };
|
|
776
824
|
}
|
|
777
|
-
const command = cli2.includes("/") || cli2.includes("\\") ?
|
|
825
|
+
const command = cli2.includes("/") || cli2.includes("\\") ? resolve2(cli2) : cli2;
|
|
778
826
|
return { command, args: ["agent", "mcp"] };
|
|
779
827
|
}
|
|
780
828
|
function parseTableSegments(header) {
|
|
@@ -870,24 +918,7 @@ var read = async (path2) => JSON.parse(await readFile(path2, "utf8"));
|
|
|
870
918
|
var present = (path2) => lstat(path2).catch((error) => {
|
|
871
919
|
if (error.code !== "ENOENT") throw error;
|
|
872
920
|
});
|
|
873
|
-
var cliCall = (...args) =>
|
|
874
|
-
let stdout;
|
|
875
|
-
try {
|
|
876
|
-
stdout = execFileSync(cli, [...args, "--json"], {
|
|
877
|
-
encoding: "utf8",
|
|
878
|
-
maxBuffer: 16 * 1024 * 1024,
|
|
879
|
-
stdio: ["ignore", "pipe", "inherit"]
|
|
880
|
-
});
|
|
881
|
-
} catch (error) {
|
|
882
|
-
stdout = error.stdout;
|
|
883
|
-
}
|
|
884
|
-
const reply = JSON.parse(stdout);
|
|
885
|
-
if (!reply.ok)
|
|
886
|
-
throw Object.assign(Error(reply.error.code + ": " + reply.error.message), {
|
|
887
|
-
code: reply.error.code
|
|
888
|
-
});
|
|
889
|
-
return reply.data;
|
|
890
|
-
};
|
|
921
|
+
var cliCall = (...args) => invokeCliJson(cli, args);
|
|
891
922
|
var user = ["--scope", "user"];
|
|
892
923
|
var pins = await read(join(scratch, "chat-pins.json"));
|
|
893
924
|
var packages = {
|
|
@@ -945,8 +976,9 @@ async function enable(id, scope, options = [], additions) {
|
|
|
945
976
|
try {
|
|
946
977
|
activate();
|
|
947
978
|
} catch (error) {
|
|
948
|
-
|
|
949
|
-
|
|
979
|
+
const canRestart = error.code === "USER_SCOPE_IN_USE" && scope === user && !restarted || error.code === "INSTANCE_UNAVAILABLE" && scope !== user;
|
|
980
|
+
if (!canRestart) throw error;
|
|
981
|
+
if (scope === user) restarted = true;
|
|
950
982
|
cliCall("host", "stop");
|
|
951
983
|
for (let i = 0; cliCall("host", "status").pid; i++) {
|
|
952
984
|
if (i === 60) throw Error("Studio Host is still stopping. Rerun setup after it exits.");
|
|
@@ -966,7 +998,7 @@ for (const project of cliCall("project", "list").projects) {
|
|
|
966
998
|
const scope = ["--project", project.id];
|
|
967
999
|
const author = cliCall("plugin", "list", ...scope).instances.find((i) => i.id === "authoring");
|
|
968
1000
|
if (author?.package === packages.authoring) {
|
|
969
|
-
await enable("authoring", scope);
|
|
1001
|
+
await enable("authoring", scope, ["--allow-access", "events.publish"]);
|
|
970
1002
|
await enable("chat-components", scope, [], {
|
|
971
1003
|
character: { instanceId: "authoring", operationId: "characters.receiveCard" }
|
|
972
1004
|
});
|
package/dist/shared.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface ChatView {
|
|
|
25
25
|
scope?: ScopeRef;
|
|
26
26
|
target: OperationTarget;
|
|
27
27
|
component: string;
|
|
28
|
+
cardInstanceId?: string;
|
|
29
|
+
componentId?: string;
|
|
28
30
|
props: Record<string, unknown>;
|
|
29
31
|
mediaOrigins?: readonly string[];
|
|
30
32
|
ui: { format: 'iife'; javascript: string; sha256: string };
|
|
@@ -37,6 +39,7 @@ export interface HostChatResult extends Omit<ChatResult, 'view' | 'bindingContex
|
|
|
37
39
|
export interface ChatRunRequest extends InvokeOptions {
|
|
38
40
|
target: OperationTarget;
|
|
39
41
|
input: unknown;
|
|
42
|
+
fromInteractionId?: string;
|
|
40
43
|
}
|
|
41
44
|
export interface ChatActionRequest extends InvokeOptions {
|
|
42
45
|
/** Host-issued operation binding for this declared action. */
|
|
@@ -45,6 +48,8 @@ export interface ChatActionRequest extends InvokeOptions {
|
|
|
45
48
|
target: OperationTarget;
|
|
46
49
|
action: string;
|
|
47
50
|
input?: Record<string, unknown>;
|
|
51
|
+
cardInstanceId?: string;
|
|
52
|
+
fromInteractionId?: string;
|
|
48
53
|
}
|
|
49
54
|
export interface ChatProjectionContext {
|
|
50
55
|
/** Authenticated context of the original card when projecting an action response. */
|
|
@@ -52,6 +57,7 @@ export interface ChatProjectionContext {
|
|
|
52
57
|
projectId: string;
|
|
53
58
|
target: OperationTarget;
|
|
54
59
|
action?: string;
|
|
60
|
+
interactionId?: string;
|
|
55
61
|
}
|
|
56
62
|
export interface ChatActionContext extends ChatProjectionContext {
|
|
57
63
|
action: string;
|
package/docs/mcp-instructions.md
CHANGED
|
@@ -20,6 +20,14 @@ The adapter projects the installed component through
|
|
|
20
20
|
`studio_card_action` route. The adapter authenticates the original source,
|
|
21
21
|
component, action and target before dispatching a Host operation.
|
|
22
22
|
|
|
23
|
+
When a prompt button prepares a `chat-component-action` follow-up, the adapter
|
|
24
|
+
attaches a server-minted `interactionId` to the returned `data` object. On the
|
|
25
|
+
immediate continuation turn triggered by that callback, pass `data.interactionId`
|
|
26
|
+
verbatim via optional `fromInteractionId` on `run_studio_action` (or
|
|
27
|
+
`--from-interaction` / `VIVIX_INTERACTION_ID` on Studio CLI invocations) so
|
|
28
|
+
downstream operations retain concurrent-safe attribution. Never fabricate an
|
|
29
|
+
`interactionId` or carry it across later turns.
|
|
30
|
+
|
|
23
31
|
## Media transport
|
|
24
32
|
|
|
25
33
|
Query saved media through the discovered `query_studio_media` route and resolve
|