@seriousgaming/sdk-tools 1.5.0 → 1.6.1
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/agent/guidance.md +350 -0
- package/dist/bundling/ui-bundler.d.ts +12 -0
- package/dist/cli-25RWY5BQ.js +41 -0
- package/dist/cli-2BH7FX27.js +52 -0
- package/dist/cli-2GZYGRVL.js +36 -0
- package/dist/cli-2NU2LPEE.js +97 -0
- package/dist/cli-3BRC32CP.js +132 -0
- package/dist/cli-3D3ZXWOV.js +111 -0
- package/dist/cli-3ZKWV3PN.js +96 -0
- package/dist/cli-45OCBG53.js +60 -0
- package/dist/cli-4LKXZQ2B.js +48 -0
- package/dist/cli-4PXNOJQX.js +81 -0
- package/dist/cli-4SIWLHQO.js +717 -0
- package/dist/cli-4UWFQNGF.js +54 -0
- package/dist/cli-4VFZHLDG.js +202 -0
- package/dist/cli-4YB3ROVR.js +78 -0
- package/dist/cli-5ACDPCXI.js +21 -0
- package/dist/cli-5IAW3LIF.js +38 -0
- package/dist/cli-5SM367K7.js +30 -0
- package/dist/cli-64AB62PM.js +25 -0
- package/dist/cli-6K3VQQUS.js +307 -0
- package/dist/cli-6QB2VFPY.js +80 -0
- package/dist/cli-6SGCYEEC.js +649 -0
- package/dist/cli-6UTPHWRQ.js +207 -0
- package/dist/cli-6VNKQ3OX.js +391 -0
- package/dist/cli-72XDEFU3.js +61 -0
- package/dist/cli-7A6MKCUJ.js +463 -0
- package/dist/cli-7XLHO2FE.js +226 -0
- package/dist/cli-AV2FYC5G.js +225 -0
- package/dist/cli-B6YHEKIJ.js +248 -0
- package/dist/cli-BJMS3VX3.js +1837 -0
- package/dist/cli-BUQI5UU4.js +43 -0
- package/dist/cli-BWX5E7TQ.js +23 -0
- package/dist/cli-BYCHKSSH.js +1331 -0
- package/dist/cli-C3CMJSNL.js +89 -0
- package/dist/cli-C47GJATR.js +42 -0
- package/dist/cli-C5QOJJWX.js +46 -0
- package/dist/cli-C6ZLPK2U.js +124 -0
- package/dist/cli-CD5CIJZI.js +72 -0
- package/dist/cli-DDJYUKQG.js +36 -0
- package/dist/cli-DFBTZEBX.js +167 -0
- package/dist/cli-DOXRQ3S5.js +60 -0
- package/dist/cli-EVI36HEM.js +79 -0
- package/dist/cli-F2D4GGUA.js +549 -0
- package/dist/cli-FQRVFGN6.js +0 -0
- package/dist/cli-FWFRKQNE.js +11 -0
- package/dist/cli-G6CANSPL.js +88 -0
- package/dist/cli-GFNDW2DL.js +124 -0
- package/dist/cli-HCRTYQQS.js +16 -0
- package/dist/cli-HFX3YPUL.js +76 -0
- package/dist/cli-HKORECAG.js +53 -0
- package/dist/cli-HOE3WLFH.js +73 -0
- package/dist/cli-HSIHDN6K.js +187 -0
- package/dist/cli-HW53ICZC.js +89 -0
- package/dist/cli-IDVUHGKG.js +218 -0
- package/dist/cli-IEMKI7J7.js +1387 -0
- package/dist/cli-ILFDANBR.js +101 -0
- package/dist/cli-ILKCQNM6.js +8 -0
- package/dist/cli-IP4RXGHM.js +2847 -0
- package/dist/cli-IUS2YCD3.js +31 -0
- package/dist/cli-J4DKUUTK.js +138 -0
- package/dist/cli-J4UBELKF.js +37 -0
- package/dist/cli-JJSWBW4H.js +89 -0
- package/dist/cli-JVI24FI6.js +68 -0
- package/dist/cli-JZCLIT3O.js +135 -0
- package/dist/cli-JZOZOEZM.js +131 -0
- package/dist/cli-KGM6RRQW.js +185 -0
- package/dist/cli-KGT5L7VZ.js +13641 -0
- package/dist/cli-KOGRWFN7.js +89 -0
- package/dist/cli-KSGB2ZLK.js +101 -0
- package/dist/cli-L7VYSXQK.js +243 -0
- package/dist/cli-LK3V4RI5.js +36 -0
- package/dist/cli-LQOHATY2.js +126 -0
- package/dist/cli-MJUYJIEP.js +13 -0
- package/dist/cli-MJV47HKI.js +143 -0
- package/dist/cli-MMN4BPO4.js +145 -0
- package/dist/cli-MOPSZ3CS.js +88 -0
- package/dist/cli-MU5LB43S.js +136 -0
- package/dist/cli-MYJGMA6U.js +40 -0
- package/dist/cli-N24OHSAN.js +36 -0
- package/dist/cli-N45DREM4.js +99 -0
- package/dist/cli-N6H6T2E2.js +616 -0
- package/dist/cli-NROTDF5Y.js +182 -0
- package/dist/cli-O5ABH2WK.js +226 -0
- package/dist/cli-OMWC75CC.js +256 -0
- package/dist/cli-OXAUOWCN.js +50 -0
- package/dist/cli-PGCIHPU7.js +143 -0
- package/dist/cli-Q6ZBZYK2.js +35 -0
- package/dist/cli-QUNIRH7A.js +57 -0
- package/dist/cli-QUSCIUOM.js +142 -0
- package/dist/cli-QVASWX2A.js +187 -0
- package/dist/cli-QWQMPCL6.js +253 -0
- package/dist/cli-QY5NZAR7.js +97 -0
- package/dist/cli-R2MUZQE2.js +62 -0
- package/dist/cli-RCIWBCXD.js +36 -0
- package/dist/cli-RLEGRWFM.js +81 -0
- package/dist/cli-RSW6EBBD.js +89 -0
- package/dist/cli-RZITKPJX.js +367 -0
- package/dist/cli-S5IVGDDD.js +32 -0
- package/dist/cli-SRHBXZCN.js +159 -0
- package/dist/cli-TDSQSCX4.js +131 -0
- package/dist/cli-TIDQ4WUE.js +257 -0
- package/dist/cli-TT36JCU5.js +370 -0
- package/dist/cli-TTKICM5P.js +100 -0
- package/dist/cli-TTMBBEJC.js +131 -0
- package/dist/cli-UMEBPAZQ.js +16 -0
- package/dist/cli-UNAJ2OTE.js +15 -0
- package/dist/cli-UZZFNXRX.js +226 -0
- package/dist/cli-VDBW23SS.js +81 -0
- package/dist/cli-VL2P354N.js +46 -0
- package/dist/cli-VPRRICZA.js +304 -0
- package/dist/cli-VQ6HVQW4.js +4010 -0
- package/dist/cli-WR3NOY74.js +36 -0
- package/dist/cli-WU43JT4T.js +52 -0
- package/dist/cli-XAT25PRU.js +117 -0
- package/dist/cli-XOTNXEJA.js +124 -0
- package/dist/cli-XSLNH5PR.js +6417 -0
- package/dist/cli-XSVGKI3R.js +39 -0
- package/dist/cli-XZCJIKIV.js +124 -0
- package/dist/cli-Y3DDNMPX.js +97 -0
- package/dist/cli-Y3O5F4JN.js +90 -0
- package/dist/cli-YOTGR3NB.js +82 -0
- package/dist/cli-Z56ZIVA6.js +97 -0
- package/dist/cli-ZBN5KAIB.js +59 -0
- package/dist/cli-ZDOTXEKL.js +31 -0
- package/dist/cli-ZDUADFBY.js +88 -0
- package/dist/cli-ZJFQ7EEA.js +131 -0
- package/dist/cli-ZTWOE3ZT.js +65 -0
- package/dist/cli.js +148 -43093
- package/dist/client/build-surfaces.d.ts +33 -0
- package/dist/client/dev-server.d.ts +6 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/playwright.d.ts +62 -0
- package/dist/client.js +228 -48
- package/dist/core/session.d.ts +15 -1
- package/dist/dev/console/assets/{index-BVF8exas.js → index-CuMOOH9m.js} +1 -1
- package/dist/dev/console/index.html +1 -1
- package/dist/dev/shell.d.ts +19 -0
- package/dist/dev/surfaces.d.ts +7 -0
- package/dist/docs/ai-agents.md +1 -1
- package/dist/docs/api/index.md +14 -12
- package/dist/docs/api/sdk-tools-client.md +29 -0
- package/dist/docs/api/sdk-tools-playwright.md +104 -0
- package/dist/docs/changelog.md +34 -0
- package/dist/docs/cli-and-dev-server.md +21 -0
- package/dist/docs/cli-reference.md +45 -31
- package/dist/docs/environment-variables.md +6 -0
- package/dist/docs/getting-started.md +1 -1
- package/dist/docs/guides/designing-a-game.md +29 -4
- package/dist/docs/guides/starter-game.md +3 -3
- package/dist/docs/guides/testing.md +33 -18
- package/dist/docs/guides/upgrading.md +19 -2
- package/dist/docs/page-index.md +10 -9
- package/dist/docs/recipes/e2e-testing.md +19 -20
- package/dist/playwright.js +32232 -0
- package/dist/templates/package/CLAUDE.md.template +7 -346
- package/dist/templates/package/claude/rules/workflow-create-engine.md +2 -2
- package/dist/templates/package/claude/rules/workflow-create-guide.md +2 -2
- package/dist/templates/package/claude/rules/workflow-create-user-interface.md +1 -1
- package/dist/templates/package/claude/rules/workflow-test-engine-or-ui.md +1 -1
- package/dist/templates/package/claude/rules/workflow-update-sdk-version.md +3 -3
- package/dist/templates/package/global-setup.ts.template +7 -18
- package/dist/templates/package/playwright.config.ts.liquid +8 -11
- package/dist/templates/starter-game/playwright.config.ts +8 -11
- package/dist/templates/starter-game/testing/e2e/game.spec.ts +1 -1
- package/dist/templates/starter-game/testing/e2e/global-setup.ts +7 -18
- package/dist/utils/prompt.d.ts +5 -5
- package/dist/utils/resource-scan.d.ts +39 -0
- package/package.json +7 -3
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
promptForSchemaProperties
|
|
4
|
+
} from "./cli-RZITKPJX.js";
|
|
5
|
+
import {
|
|
6
|
+
readAuthoredBundle
|
|
7
|
+
} from "./cli-4VFZHLDG.js";
|
|
8
|
+
import {
|
|
9
|
+
resolveInputSource
|
|
10
|
+
} from "./cli-4UWFQNGF.js";
|
|
11
|
+
import {
|
|
12
|
+
createEndpointFiles
|
|
13
|
+
} from "./cli-4SIWLHQO.js";
|
|
14
|
+
import "./cli-IUS2YCD3.js";
|
|
15
|
+
import "./cli-QUNIRH7A.js";
|
|
16
|
+
import "./cli-J4UBELKF.js";
|
|
17
|
+
import {
|
|
18
|
+
loadPackageContext
|
|
19
|
+
} from "./cli-XSVGKI3R.js";
|
|
20
|
+
import {
|
|
21
|
+
presentFields
|
|
22
|
+
} from "./cli-TT36JCU5.js";
|
|
23
|
+
import "./cli-OXAUOWCN.js";
|
|
24
|
+
import {
|
|
25
|
+
operationError,
|
|
26
|
+
printOperationResult
|
|
27
|
+
} from "./cli-KSGB2ZLK.js";
|
|
28
|
+
import {
|
|
29
|
+
confirm,
|
|
30
|
+
input
|
|
31
|
+
} from "./cli-ZTWOE3ZT.js";
|
|
32
|
+
import {
|
|
33
|
+
generateCommand
|
|
34
|
+
} from "./cli-LQOHATY2.js";
|
|
35
|
+
import "./cli-IEMKI7J7.js";
|
|
36
|
+
import "./cli-OMWC75CC.js";
|
|
37
|
+
import "./cli-BYCHKSSH.js";
|
|
38
|
+
import "./cli-25RWY5BQ.js";
|
|
39
|
+
import "./cli-QWQMPCL6.js";
|
|
40
|
+
import {
|
|
41
|
+
validateSDKEndpoint
|
|
42
|
+
} from "./cli-VQ6HVQW4.js";
|
|
43
|
+
import "./cli-F2D4GGUA.js";
|
|
44
|
+
import {
|
|
45
|
+
logger
|
|
46
|
+
} from "./cli-4YB3ROVR.js";
|
|
47
|
+
import "./cli-N6H6T2E2.js";
|
|
48
|
+
|
|
49
|
+
// cli/commands/resources/endpoint/new.ts
|
|
50
|
+
function emptyObjectSchema() {
|
|
51
|
+
return {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {},
|
|
54
|
+
required: [],
|
|
55
|
+
additionalProperties: false
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
function schemaFromProperties(properties) {
|
|
59
|
+
return {
|
|
60
|
+
type: "object",
|
|
61
|
+
properties,
|
|
62
|
+
required: Object.keys(properties),
|
|
63
|
+
additionalProperties: false
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async function createEndpoint(definitionInput, options) {
|
|
67
|
+
logger.info("\nCreating new endpoint...\n");
|
|
68
|
+
loadPackageContext(options.workingDir);
|
|
69
|
+
const inputSource = await resolveInputSource(definitionInput, options.file);
|
|
70
|
+
const jsonDefinition = inputSource.kind === "json" ? inputSource.json : null;
|
|
71
|
+
if (jsonDefinition) {
|
|
72
|
+
const endpointInput = readAuthoredBundle({
|
|
73
|
+
json: jsonDefinition,
|
|
74
|
+
type: "endpoint",
|
|
75
|
+
command: "new",
|
|
76
|
+
validate: validateSDKEndpoint
|
|
77
|
+
});
|
|
78
|
+
const def = endpointInput.definition;
|
|
79
|
+
logger.info("Creating endpoint files...\n");
|
|
80
|
+
const result2 = await createEndpointFiles({
|
|
81
|
+
packagePath: options.workingDir,
|
|
82
|
+
identifier: def.identifier,
|
|
83
|
+
definition: def
|
|
84
|
+
});
|
|
85
|
+
if (!result2.success) {
|
|
86
|
+
throw operationError(result2, "Failed to create endpoint files");
|
|
87
|
+
}
|
|
88
|
+
logger.success("Endpoint created successfully!");
|
|
89
|
+
printOperationResult(result2);
|
|
90
|
+
logger.info("\nGenerating TypeScript types...\n");
|
|
91
|
+
try {
|
|
92
|
+
await generateCommand({ workingDir: options.workingDir });
|
|
93
|
+
logger.success("TypeScript types generated successfully!");
|
|
94
|
+
} catch (error) {
|
|
95
|
+
logger.warn("Failed to generate TypeScript types:");
|
|
96
|
+
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
logger.info("No JSON definition provided. Starting interactive mode...\n");
|
|
101
|
+
const shortIdentifier = await input({
|
|
102
|
+
message: 'Endpoint identifier (short name, e.g., "summarise"):',
|
|
103
|
+
validate: (value) => {
|
|
104
|
+
if (!value.trim()) return "Identifier is required";
|
|
105
|
+
if (value.includes(".")) {
|
|
106
|
+
return 'In interactive mode, use short identifier (e.g., "summarise" instead of "com.example.summarise")';
|
|
107
|
+
}
|
|
108
|
+
if (!/^[a-z][a-z0-9_]*$/.test(value)) {
|
|
109
|
+
return "Identifier must start with lowercase letter and contain only lowercase letters, numbers, and underscores";
|
|
110
|
+
}
|
|
111
|
+
return true;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
const identifier = shortIdentifier.trim();
|
|
115
|
+
const displayName = await input({
|
|
116
|
+
message: "Display name (optional):",
|
|
117
|
+
default: ""
|
|
118
|
+
});
|
|
119
|
+
const description = await input({
|
|
120
|
+
message: "Short description (optional):",
|
|
121
|
+
default: ""
|
|
122
|
+
});
|
|
123
|
+
let requestSchema = emptyObjectSchema();
|
|
124
|
+
logger.info("\nDefine the request properties this endpoint accepts:");
|
|
125
|
+
const wantsRequest = await confirm({
|
|
126
|
+
message: "Add request properties?",
|
|
127
|
+
default: true
|
|
128
|
+
});
|
|
129
|
+
if (wantsRequest) {
|
|
130
|
+
const props = await promptForSchemaProperties({
|
|
131
|
+
context: "property",
|
|
132
|
+
minProperties: 0
|
|
133
|
+
});
|
|
134
|
+
if (Object.keys(props).length > 0) requestSchema = schemaFromProperties(props);
|
|
135
|
+
}
|
|
136
|
+
let responseSchema = emptyObjectSchema();
|
|
137
|
+
logger.info("\nDefine the response properties this endpoint returns:");
|
|
138
|
+
const wantsResponse = await confirm({
|
|
139
|
+
message: "Add response properties?",
|
|
140
|
+
default: true
|
|
141
|
+
});
|
|
142
|
+
if (wantsResponse) {
|
|
143
|
+
const props = await promptForSchemaProperties({
|
|
144
|
+
context: "property",
|
|
145
|
+
minProperties: 0
|
|
146
|
+
});
|
|
147
|
+
if (Object.keys(props).length > 0) responseSchema = schemaFromProperties(props);
|
|
148
|
+
}
|
|
149
|
+
logger.info("Creating endpoint files...\n");
|
|
150
|
+
const result = await createEndpointFiles({
|
|
151
|
+
packagePath: options.workingDir,
|
|
152
|
+
identifier,
|
|
153
|
+
definition: {
|
|
154
|
+
...presentFields({
|
|
155
|
+
displayName: displayName.trim(),
|
|
156
|
+
description: description.trim()
|
|
157
|
+
}),
|
|
158
|
+
requestSchema,
|
|
159
|
+
responseSchema
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
if (!result.success) {
|
|
163
|
+
throw operationError(result, "Failed to create endpoint files");
|
|
164
|
+
}
|
|
165
|
+
logger.success("Endpoint created successfully!");
|
|
166
|
+
printOperationResult(result);
|
|
167
|
+
logger.info("\nGenerating TypeScript types...\n");
|
|
168
|
+
try {
|
|
169
|
+
await generateCommand({ workingDir: options.workingDir });
|
|
170
|
+
logger.success("TypeScript types generated successfully!");
|
|
171
|
+
} catch (error) {
|
|
172
|
+
logger.warn("Failed to generate TypeScript types:");
|
|
173
|
+
logger.warn(error instanceof Error ? error.message : "Unknown error");
|
|
174
|
+
}
|
|
175
|
+
logger.info("Next steps:");
|
|
176
|
+
logger.info(` 1. Edit the endpoint handler: endpoints/${identifier}/logic/logic.ts`);
|
|
177
|
+
logger.info(` 2. Declare the endpoint in a UI bundle: "endpoints": ["${identifier}"]`);
|
|
178
|
+
logger.info(' 3. Call it from the UI: callbacks.endpoints["' + identifier + '"]({ ... })');
|
|
179
|
+
}
|
|
180
|
+
export {
|
|
181
|
+
createEndpoint
|
|
182
|
+
};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DevShell
|
|
4
|
+
} from "./cli-IP4RXGHM.js";
|
|
5
|
+
import "./cli-BWX5E7TQ.js";
|
|
6
|
+
import "./cli-BJMS3VX3.js";
|
|
7
|
+
import "./cli-ILKCQNM6.js";
|
|
8
|
+
import "./cli-7XLHO2FE.js";
|
|
9
|
+
import {
|
|
10
|
+
participantsFromArgument,
|
|
11
|
+
requireScenario,
|
|
12
|
+
teamCountFromFlag
|
|
13
|
+
} from "./cli-L7VYSXQK.js";
|
|
14
|
+
import "./cli-FQRVFGN6.js";
|
|
15
|
+
import {
|
|
16
|
+
FakeClock
|
|
17
|
+
} from "./cli-XSLNH5PR.js";
|
|
18
|
+
import {
|
|
19
|
+
loadEnvironmentConfig
|
|
20
|
+
} from "./cli-TDSQSCX4.js";
|
|
21
|
+
import {
|
|
22
|
+
readLockFile
|
|
23
|
+
} from "./cli-SRHBXZCN.js";
|
|
24
|
+
import "./cli-KGT5L7VZ.js";
|
|
25
|
+
import "./cli-4LKXZQ2B.js";
|
|
26
|
+
import "./cli-MMN4BPO4.js";
|
|
27
|
+
import {
|
|
28
|
+
parseDevPort,
|
|
29
|
+
parseDevPortOrAuto,
|
|
30
|
+
resolveErrorOverlay
|
|
31
|
+
} from "./cli-C5QOJJWX.js";
|
|
32
|
+
import {
|
|
33
|
+
resolvePublicOrigins
|
|
34
|
+
} from "./cli-YOTGR3NB.js";
|
|
35
|
+
import "./cli-QUNIRH7A.js";
|
|
36
|
+
import "./cli-OMWC75CC.js";
|
|
37
|
+
import "./cli-BYCHKSSH.js";
|
|
38
|
+
import "./cli-25RWY5BQ.js";
|
|
39
|
+
import "./cli-QWQMPCL6.js";
|
|
40
|
+
import {
|
|
41
|
+
errorMessage
|
|
42
|
+
} from "./cli-VQ6HVQW4.js";
|
|
43
|
+
import "./cli-F2D4GGUA.js";
|
|
44
|
+
import "./cli-4YB3ROVR.js";
|
|
45
|
+
import {
|
|
46
|
+
CliError,
|
|
47
|
+
reportResult,
|
|
48
|
+
requestProcessExit
|
|
49
|
+
} from "./cli-N6H6T2E2.js";
|
|
50
|
+
|
|
51
|
+
// cli/commands/dev.ts
|
|
52
|
+
import { existsSync, statSync } from "fs";
|
|
53
|
+
import { resolve } from "path";
|
|
54
|
+
import dotenv from "dotenv";
|
|
55
|
+
import open from "open";
|
|
56
|
+
|
|
57
|
+
// cli/dev/network-addresses.ts
|
|
58
|
+
import { networkInterfaces } from "os";
|
|
59
|
+
function networkAddresses(interfaces = networkInterfaces()) {
|
|
60
|
+
return Object.values(interfaces).flatMap((entries) => entries ?? []).filter((entry) => entry.family === "IPv4" && !entry.internal).map((entry) => entry.address);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// cli/commands/dev.ts
|
|
64
|
+
dotenv.config({ path: ".env", debug: false, quiet: true });
|
|
65
|
+
async function devCommand(options) {
|
|
66
|
+
const packagePath = options.workingDir;
|
|
67
|
+
const port = parseDevPortOrAuto(options.port);
|
|
68
|
+
const vitePort = options.vitePort === void 0 ? void 0 : parseDevPort(options.vitePort);
|
|
69
|
+
const assetPort = options.assetPort === void 0 ? void 0 : parseDevPort(options.assetPort);
|
|
70
|
+
const teams = options.teams === void 0 ? void 0 : teamCountFromFlag(options.teams);
|
|
71
|
+
const scenarioId = options.scenario === void 0 ? void 0 : requireScenario(packagePath, options.scenario);
|
|
72
|
+
const publicOrigins = resolvePublicOrigins(options);
|
|
73
|
+
const errorOverlay = resolveErrorOverlay(options.errorOverlay);
|
|
74
|
+
const builtSurfaces = options.builtSurfaces === void 0 ? void 0 : requireBuiltSurfaces(resolve(packagePath, options.builtSurfaces));
|
|
75
|
+
const envConfig = loadEnvironmentConfig(packagePath, {
|
|
76
|
+
seriousGamingApiKey: options.apiKey,
|
|
77
|
+
seriousGamingApiHost: options.host
|
|
78
|
+
});
|
|
79
|
+
const running = options.isolated ? null : await readLockFile(packagePath);
|
|
80
|
+
if (running) {
|
|
81
|
+
throw new CliError(
|
|
82
|
+
"LOCK_HELD",
|
|
83
|
+
`A dev server for this package is already running at http://localhost:${running.port} (pid ${running.pid}).
|
|
84
|
+
|
|
85
|
+
A package holds one session, so this is it, whichever port you asked for.
|
|
86
|
+
|
|
87
|
+
Open it: http://localhost:${running.port}
|
|
88
|
+
Stop it: pnpm run sdk dev stop`,
|
|
89
|
+
{ hint: "To run it somewhere else, stop this one and start again with --port." }
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
requestProcessExit();
|
|
93
|
+
for (const stream of [process.stdout, process.stderr]) {
|
|
94
|
+
stream.on("error", (error) => {
|
|
95
|
+
if (error.code !== "EPIPE") throw error;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
console.log("Starting Serious Gaming Dev Server...");
|
|
99
|
+
const server = new DevShell({
|
|
100
|
+
packagePath,
|
|
101
|
+
port,
|
|
102
|
+
...vitePort === void 0 ? {} : { vitePort },
|
|
103
|
+
...assetPort === void 0 ? {} : { assetPort },
|
|
104
|
+
...publicOrigins,
|
|
105
|
+
...scenarioId === void 0 ? {} : { scenarioId },
|
|
106
|
+
...envConfig.seriousGamingApiKey === void 0 ? {} : { seriousGamingApiKey: envConfig.seriousGamingApiKey },
|
|
107
|
+
...envConfig.seriousGamingApiHost === void 0 ? {} : { seriousGamingApiHost: envConfig.seriousGamingApiHost },
|
|
108
|
+
...envConfig.elevenLabsApiKey === void 0 ? {} : { elevenLabsApiKey: envConfig.elevenLabsApiKey },
|
|
109
|
+
...options.lan ? { lan: true } : {},
|
|
110
|
+
// Started at the real time, so a `nextTickAt` reads as a plausible
|
|
111
|
+
// moment rather than as 1970.
|
|
112
|
+
...options.fakeClock ? { clock: new FakeClock(Date.now()) } : {},
|
|
113
|
+
...options.reinitOnChange ? { reinitOnChange: true } : {},
|
|
114
|
+
...errorOverlay ? {} : { errorOverlay: false },
|
|
115
|
+
...builtSurfaces === void 0 ? {} : { builtSurfaces },
|
|
116
|
+
...options.isolated ? { isolated: true } : {},
|
|
117
|
+
...options.background ? { background: true } : {},
|
|
118
|
+
...options.brand?.length ? { brandFiles: options.brand.map((file) => resolve(file)) } : {},
|
|
119
|
+
...teams === void 0 ? {} : { teams },
|
|
120
|
+
...options.participants === void 0 ? {} : { participants: participantsFromArgument(options.participants) }
|
|
121
|
+
});
|
|
122
|
+
let isShuttingDown = false;
|
|
123
|
+
let stopped = () => {
|
|
124
|
+
};
|
|
125
|
+
const untilStopped = new Promise((resolve2) => {
|
|
126
|
+
stopped = resolve2;
|
|
127
|
+
});
|
|
128
|
+
const shutdown = async () => {
|
|
129
|
+
if (isShuttingDown) return;
|
|
130
|
+
isShuttingDown = true;
|
|
131
|
+
console.log("\n\nShutting down dev server...");
|
|
132
|
+
try {
|
|
133
|
+
await server.stop();
|
|
134
|
+
console.log("Dev server stopped");
|
|
135
|
+
} catch (error) {
|
|
136
|
+
console.error("Error during shutdown:", error);
|
|
137
|
+
}
|
|
138
|
+
stopped();
|
|
139
|
+
};
|
|
140
|
+
try {
|
|
141
|
+
await server.start();
|
|
142
|
+
const moved = port !== 0 && server.url !== `http://localhost:${port}`;
|
|
143
|
+
console.log(`
|
|
144
|
+
\u2713 Dev server running at ${server.url}`);
|
|
145
|
+
console.log(` Game surfaces are served from ${server.assetUrl}`);
|
|
146
|
+
if (server.publicUrl) console.log(` People reach it at ${server.publicUrl}`);
|
|
147
|
+
if (server.publicAssetUrl) {
|
|
148
|
+
console.log(` Their browsers load game surfaces from ${server.publicAssetUrl}`);
|
|
149
|
+
}
|
|
150
|
+
if (options.isolated) {
|
|
151
|
+
console.log(
|
|
152
|
+
` Isolated: no lock file, so CLI commands reach it only through SERIOUSGAMING_DEV_URL=${server.url}. Configuration comes from the package alone, and uploads go to a temporary directory removed on stop.`
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
if (moved) {
|
|
156
|
+
console.log(
|
|
157
|
+
` (port ${port} was in use, so this one is on ${server.url.split(":").pop()})`
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
console.log(reachability(server.url, server.reachableFromNetwork));
|
|
161
|
+
console.log("\nPress Ctrl+C to stop the server\n");
|
|
162
|
+
if (options.open !== false) {
|
|
163
|
+
await open(server.publicUrl ?? server.url);
|
|
164
|
+
}
|
|
165
|
+
process.on("SIGINT", shutdown);
|
|
166
|
+
process.on("SIGTERM", shutdown);
|
|
167
|
+
if (options.background) {
|
|
168
|
+
const packageWatch = setInterval(() => {
|
|
169
|
+
if (existsSync(packagePath)) return;
|
|
170
|
+
clearInterval(packageWatch);
|
|
171
|
+
console.log(`
|
|
172
|
+
The package at ${packagePath} has been removed.`);
|
|
173
|
+
void shutdown();
|
|
174
|
+
}, 1e3);
|
|
175
|
+
packageWatch.unref();
|
|
176
|
+
}
|
|
177
|
+
} catch (error) {
|
|
178
|
+
if (error instanceof CliError) throw error;
|
|
179
|
+
throw new CliError(
|
|
180
|
+
"DEV_SERVER_START_FAILED",
|
|
181
|
+
`Failed to start dev server: ${errorMessage(error)}`,
|
|
182
|
+
{ cause: error }
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
await untilStopped;
|
|
186
|
+
reportResult({
|
|
187
|
+
url: server.url,
|
|
188
|
+
assetUrl: server.assetUrl,
|
|
189
|
+
port: Number(new URL(server.url).port),
|
|
190
|
+
assetPort: Number(new URL(server.assetUrl).port),
|
|
191
|
+
...server.publicUrl ? { publicUrl: server.publicUrl } : {},
|
|
192
|
+
...server.publicAssetUrl ? { publicAssetUrl: server.publicAssetUrl } : {},
|
|
193
|
+
isolated: options.isolated === true,
|
|
194
|
+
stopped: true
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
function reachability(url, reachableFromNetwork, addresses = networkAddresses()) {
|
|
198
|
+
if (!reachableFromNetwork) {
|
|
199
|
+
return " Only this machine can reach it. To test on a phone or tablet, restart with --lan.";
|
|
200
|
+
}
|
|
201
|
+
const port = new URL(url).port;
|
|
202
|
+
const lines = [
|
|
203
|
+
"",
|
|
204
|
+
"\u26A0 Listening on your network (--lan). Anyone on the same network can open this",
|
|
205
|
+
" session, use its API and read your package files. Use it only on a network you trust."
|
|
206
|
+
];
|
|
207
|
+
if (addresses.length === 0) {
|
|
208
|
+
lines.push(" No network address was found, so no other device can reach it yet.");
|
|
209
|
+
} else {
|
|
210
|
+
lines.push(" On another device, open:");
|
|
211
|
+
lines.push(...addresses.map((address) => ` http://${address}:${port}`));
|
|
212
|
+
}
|
|
213
|
+
return lines.join("\n");
|
|
214
|
+
}
|
|
215
|
+
function requireBuiltSurfaces(directory) {
|
|
216
|
+
if (!statSync(directory, { throwIfNoEntry: false })?.isDirectory()) {
|
|
217
|
+
throw new CliError("BUILD_NOT_FOUND", `No built surfaces at ${directory}.`, {
|
|
218
|
+
hint: "Run `pnpm run sdk build` first, which writes them to dist/."
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return directory;
|
|
222
|
+
}
|
|
223
|
+
export {
|
|
224
|
+
devCommand,
|
|
225
|
+
reachability
|
|
226
|
+
};
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_LOGIC_EXECUTION_BOUND_MS,
|
|
4
|
+
LogicLoader,
|
|
5
|
+
resolveSettingsLayers
|
|
6
|
+
} from "./cli-BYCHKSSH.js";
|
|
7
|
+
import {
|
|
8
|
+
describeAssetByReference,
|
|
9
|
+
describeBlob,
|
|
10
|
+
readAssetByReference
|
|
11
|
+
} from "./cli-QWQMPCL6.js";
|
|
12
|
+
import {
|
|
13
|
+
SCENARIO_GATE_READ_LIMIT_BYTES,
|
|
14
|
+
ScenarioAssetTooLargeError,
|
|
15
|
+
Transpile,
|
|
16
|
+
errorMessage,
|
|
17
|
+
getPluralResourceMeta
|
|
18
|
+
} from "./cli-VQ6HVQW4.js";
|
|
19
|
+
|
|
20
|
+
// cli/execution/scenario-gates.ts
|
|
21
|
+
import { existsSync } from "fs";
|
|
22
|
+
import { readFile } from "fs/promises";
|
|
23
|
+
var SCENARIO_VALIDATION = "scenario-validation";
|
|
24
|
+
var SCENARIO_FILES = "scenario-files";
|
|
25
|
+
function hasScenarioGate(config) {
|
|
26
|
+
return (config.validators ?? []).some((v) => v.definition.gates?.includes("scenario"));
|
|
27
|
+
}
|
|
28
|
+
async function runScenarioGates(options) {
|
|
29
|
+
const { config } = options;
|
|
30
|
+
if (!hasScenarioGate(config)) return [];
|
|
31
|
+
const loader = options.loader ?? new LogicLoader(options.packagePath, {
|
|
32
|
+
transpile: Transpile,
|
|
33
|
+
fs: { existsSync, readFile }
|
|
34
|
+
});
|
|
35
|
+
const resolved = resolveSettingsLayers(config, options.scenarioSettings, null);
|
|
36
|
+
const locale = options.locale ?? config.game?.definition.supportedLocales?.[0] ?? "en";
|
|
37
|
+
const readsFiles = (config.requires ?? []).includes(SCENARIO_FILES);
|
|
38
|
+
const problems = [];
|
|
39
|
+
for (const validator of config.validators ?? []) {
|
|
40
|
+
if (!validator.definition.gates?.includes("scenario")) continue;
|
|
41
|
+
const identifier = validator.definition.identifier;
|
|
42
|
+
const declared = validator.definition.settings ?? [];
|
|
43
|
+
const pick = (values) => Object.fromEntries(
|
|
44
|
+
declared.filter((id) => values[id] !== void 0).map((id) => [id, values[id]])
|
|
45
|
+
);
|
|
46
|
+
try {
|
|
47
|
+
const exports = await loader.load(
|
|
48
|
+
"validator",
|
|
49
|
+
identifier,
|
|
50
|
+
validator,
|
|
51
|
+
`Validator ${identifier} not found in configuration`
|
|
52
|
+
);
|
|
53
|
+
const gate = exports.Scenario;
|
|
54
|
+
if (!gate) {
|
|
55
|
+
problems.push({
|
|
56
|
+
validatorIdentifier: identifier,
|
|
57
|
+
message: `Validator ${identifier} does not export Scenario`
|
|
58
|
+
});
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const found = await withBound(
|
|
62
|
+
gate({
|
|
63
|
+
settings: structuredClone(pick(resolved)),
|
|
64
|
+
locale,
|
|
65
|
+
callbacks: readsFiles ? scenarioCallbacks(
|
|
66
|
+
options.packagePath,
|
|
67
|
+
options.files ?? { scenarioRoot: null, blobs: "none" }
|
|
68
|
+
) : withoutScenarioFiles(identifier)
|
|
69
|
+
}),
|
|
70
|
+
options.boundMs ?? DEFAULT_LOGIC_EXECUTION_BOUND_MS
|
|
71
|
+
);
|
|
72
|
+
if (!Array.isArray(found)) {
|
|
73
|
+
problems.push({
|
|
74
|
+
validatorIdentifier: identifier,
|
|
75
|
+
message: `Validator ${identifier}'s Scenario returned ${JSON.stringify(found)}, not an array of problems (an empty array passes)`
|
|
76
|
+
});
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
for (const problem of found) {
|
|
80
|
+
problems.push({ validatorIdentifier: identifier, ...problem });
|
|
81
|
+
}
|
|
82
|
+
} catch (error) {
|
|
83
|
+
problems.push({
|
|
84
|
+
validatorIdentifier: identifier,
|
|
85
|
+
message: `Validator ${identifier} threw: ${errorMessage(error, String(error))}`
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return problems;
|
|
90
|
+
}
|
|
91
|
+
function scenarioCallbacks(packagePath, files) {
|
|
92
|
+
const unreadable = async (reference) => {
|
|
93
|
+
if (!reference.startsWith("blob:") || files.blobs === "all") return false;
|
|
94
|
+
if (files.blobs === "none") return true;
|
|
95
|
+
const blob = await describeBlob(packagePath, reference.slice("blob:".length));
|
|
96
|
+
return blob !== void 0 && blob.retention !== "scenario";
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
readAsset: async (reference) => {
|
|
100
|
+
if (await unreadable(reference)) {
|
|
101
|
+
throw new Error(`Cannot read "${reference}": the scenario cannot name that file`);
|
|
102
|
+
}
|
|
103
|
+
const described = await describeAssetByReference(
|
|
104
|
+
packagePath,
|
|
105
|
+
files.scenarioRoot,
|
|
106
|
+
reference
|
|
107
|
+
);
|
|
108
|
+
if (described && described.size > SCENARIO_GATE_READ_LIMIT_BYTES) {
|
|
109
|
+
throw new ScenarioAssetTooLargeError(reference, described.size);
|
|
110
|
+
}
|
|
111
|
+
const asset = await readAssetByReference(packagePath, files.scenarioRoot, reference);
|
|
112
|
+
return { data: new Uint8Array(asset.data), mimeType: asset.mimeType, name: asset.name };
|
|
113
|
+
},
|
|
114
|
+
describeAsset: async (reference) => await unreadable(reference) ? void 0 : describeAssetByReference(packagePath, files.scenarioRoot, reference)
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function withoutScenarioFiles(identifier) {
|
|
118
|
+
const refuse = (callback) => async () => {
|
|
119
|
+
throw new Error(
|
|
120
|
+
`Validator "${identifier}" called ${callback} in its Scenario gate, which needs the "${SCENARIO_FILES}" feature, but requires does not list it. Add "${SCENARIO_FILES}" to requires in seriousgaming.sdk.json.`
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
return { readAsset: refuse("readAsset"), describeAsset: refuse("describeAsset") };
|
|
124
|
+
}
|
|
125
|
+
async function withBound(run, boundMs) {
|
|
126
|
+
let timer;
|
|
127
|
+
try {
|
|
128
|
+
return await Promise.race([
|
|
129
|
+
run,
|
|
130
|
+
new Promise((_, reject) => {
|
|
131
|
+
timer = setTimeout(
|
|
132
|
+
() => reject(new Error(`did not finish within ${boundMs}ms`)),
|
|
133
|
+
boundMs
|
|
134
|
+
);
|
|
135
|
+
})
|
|
136
|
+
]);
|
|
137
|
+
} finally {
|
|
138
|
+
if (timer) clearTimeout(timer);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function describeScenarioProblems(problems) {
|
|
142
|
+
return problems.map(
|
|
143
|
+
(p) => `${p.path ? `${p.path}: ` : ""}${p.message} (validator "${p.validatorIdentifier}")`
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// cli/generation/ts-type.ts
|
|
148
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
149
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "path";
|
|
150
|
+
var RELATIVE_IMPORT = /import\((['"])(\.{1,2}\/[^'"]+)\1\)/g;
|
|
151
|
+
var ABSOLUTE_IMPORT = /import\((['"])(\/[^'"]+|[A-Za-z]:[\\/][^'"]+)\1\)/g;
|
|
152
|
+
var NAMED_IMPORT = /import\((['"])([^'"]+)\1\)\.([A-Za-z_$][\w$]*)/g;
|
|
153
|
+
var MODULE_EXTENSIONS = [".ts", ".tsx", ".d.ts", "/index.ts", "/index.tsx"];
|
|
154
|
+
function capabilityDirectory(workingDir, identifier) {
|
|
155
|
+
return join(workingDir, getPluralResourceMeta("capability").pluralDir, identifier);
|
|
156
|
+
}
|
|
157
|
+
function mapTsTypes(schema, rewrite) {
|
|
158
|
+
if (Array.isArray(schema)) return schema.map((item) => mapTsTypes(item, rewrite));
|
|
159
|
+
if (schema === null || typeof schema !== "object") return schema;
|
|
160
|
+
return Object.fromEntries(
|
|
161
|
+
Object.entries(schema).map(([key, value]) => [
|
|
162
|
+
key,
|
|
163
|
+
key === "tsType" && typeof value === "string" ? rewrite(value) : mapTsTypes(value, rewrite)
|
|
164
|
+
])
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
function collectTsTypes(schema, into = []) {
|
|
168
|
+
if (Array.isArray(schema)) {
|
|
169
|
+
for (const item of schema) collectTsTypes(item, into);
|
|
170
|
+
} else if (schema !== null && typeof schema === "object") {
|
|
171
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
172
|
+
if (key === "tsType" && typeof value === "string") into.push(value);
|
|
173
|
+
else collectTsTypes(value, into);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return into;
|
|
177
|
+
}
|
|
178
|
+
function absolutiseTsTypes(capabilities, workingDir) {
|
|
179
|
+
return capabilities.map((capability) => {
|
|
180
|
+
const schema = capability.definition.variablesSchema;
|
|
181
|
+
if (collectTsTypes(schema).length === 0) return capability;
|
|
182
|
+
const base = capabilityDirectory(workingDir, capability.definition.identifier);
|
|
183
|
+
return {
|
|
184
|
+
...capability,
|
|
185
|
+
definition: {
|
|
186
|
+
...capability.definition,
|
|
187
|
+
variablesSchema: mapTsTypes(
|
|
188
|
+
schema,
|
|
189
|
+
(tsType) => tsType.replace(
|
|
190
|
+
RELATIVE_IMPORT,
|
|
191
|
+
(_match, quote, path) => `import(${quote}${resolve(base, path)}${quote})`
|
|
192
|
+
)
|
|
193
|
+
)
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function relativiseTsTypes(schema, outputPath) {
|
|
199
|
+
const from = dirname(outputPath);
|
|
200
|
+
return mapTsTypes(
|
|
201
|
+
schema,
|
|
202
|
+
(tsType) => tsType.replace(ABSOLUTE_IMPORT, (_match, quote, path) => {
|
|
203
|
+
let rel = relative(from, path).split(sep).join("/");
|
|
204
|
+
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
205
|
+
return `import(${quote}${rel}${quote})`;
|
|
206
|
+
})
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
function validateTsTypes(capabilities, workingDir) {
|
|
210
|
+
const errors = [];
|
|
211
|
+
for (const capability of capabilities) {
|
|
212
|
+
const { identifier } = capability.definition;
|
|
213
|
+
const base = capabilityDirectory(workingDir, identifier);
|
|
214
|
+
for (const tsType of collectTsTypes(capability.definition.variablesSchema)) {
|
|
215
|
+
for (const match of tsType.matchAll(NAMED_IMPORT)) {
|
|
216
|
+
const [, , specifier, name] = match;
|
|
217
|
+
if (!specifier.startsWith(".") && !isAbsolute(specifier)) continue;
|
|
218
|
+
const target = resolve(base, specifier);
|
|
219
|
+
const file = [target, ...MODULE_EXTENSIONS.map((ext) => `${target}${ext}`)].find(
|
|
220
|
+
(candidate) => existsSync2(candidate) && statSync(candidate).isFile()
|
|
221
|
+
);
|
|
222
|
+
if (!file) {
|
|
223
|
+
errors.push(
|
|
224
|
+
`Capability "${identifier}" has tsType "${tsType}", but "${specifier}" resolves to no module from ${relative(workingDir, base) || "."}. A tsType path is relative to the capability's own directory.`
|
|
225
|
+
);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
if (!exportsName(readFileSync(file, "utf-8"), name)) {
|
|
229
|
+
errors.push(
|
|
230
|
+
`Capability "${identifier}" has tsType "${tsType}", but ${relative(workingDir, file)} does not export "${name}".`
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return errors;
|
|
237
|
+
}
|
|
238
|
+
function exportsName(source, name) {
|
|
239
|
+
const escaped = name.replace(/[$]/g, "\\$");
|
|
240
|
+
const declared = new RegExp(
|
|
241
|
+
`export\\s+(?:declare\\s+)?(?:interface|type|class|enum|const|let|var|function|abstract\\s+class)\\s+${escaped}\\b`
|
|
242
|
+
);
|
|
243
|
+
const listed = new RegExp(`export\\s+(?:type\\s+)?\\{[^}]*\\b${escaped}\\b[^}]*\\}`);
|
|
244
|
+
return declared.test(source) || listed.test(source) || /export\s+\*\s+from/.test(source);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export {
|
|
248
|
+
SCENARIO_VALIDATION,
|
|
249
|
+
SCENARIO_FILES,
|
|
250
|
+
hasScenarioGate,
|
|
251
|
+
runScenarioGates,
|
|
252
|
+
describeScenarioProblems,
|
|
253
|
+
absolutiseTsTypes,
|
|
254
|
+
relativiseTsTypes,
|
|
255
|
+
validateTsTypes
|
|
256
|
+
};
|