@s2script/sdk 0.26.0 → 0.27.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/events.d.ts CHANGED
@@ -67,7 +67,7 @@ export declare const Events: {
67
67
  * re-firing a rebuilt copy per viewer does not.
68
68
  *
69
69
  * @example
70
- * ctx.events.onPre("player_death", () => {
70
+ * hook.onPre("player_death", () => {
71
71
  * Events.setRecipients(traitorSlots); // only Traitors see the kill
72
72
  * return HookResult.Handled;
73
73
  * });
package/http.d.ts CHANGED
@@ -34,7 +34,9 @@ export interface Response {
34
34
  * @param url - Absolute `http(s)://` URL.
35
35
  * @param options - Method, headers, body, and timeout (see {@link FetchOptions}).
36
36
  * @returns Resolves for ANY HTTP response — a 4xx/5xx resolves with `ok=false`, it does not reject.
37
- * @throws Rejects only on a network error or timeout.
37
+ * @throws Rejects on a network error or timeout, or with `AsyncQueueFull` / `AsyncPayloadTooLarge`
38
+ * before acceptance. `HttpResponseTooLarge` when the retained UTF-8 body plus headers exceed the
39
+ * configured limit.
38
40
  * @example
39
41
  * import { fetch } from "@s2script/sdk/http";
40
42
  * const r = await fetch("https://httpbin.org/get", { timeoutMs: 15000 });
package/interfaces.d.ts CHANGED
@@ -5,7 +5,7 @@ import type { HookResultValue } from "./events";
5
5
  */
6
6
 
7
7
  /**
8
- * Handle returned by `ctx.publish(name, impl)`: lets the producer emit forwarded
8
+ * Handle returned by `publish(name, impl)`: lets the producer emit forwarded
9
9
  * events to every plugin subscribed to this interface via its `on(event, …)`.
10
10
  */
11
11
  export interface PublishHandle {
@@ -133,8 +133,10 @@ export type TypedInterfaceHandle<C> = ContractMethods<C> & {
133
133
  };
134
134
 
135
135
  /** A consumer-owned registration. Repeated disposal is a no-op. */
136
- export interface Subscription { dispose(): void; }
136
+ export interface Subscription { /** Remove this exact registration. Idempotent. */
137
+ dispose(): void; }
137
138
  /** Resources owned by one synchronous optional-provider attachment. */
138
139
  export interface AttachmentScope {
140
+ /** Return the resource and retain its disposer for this attachment. */
139
141
  own<T extends { dispose(): void }>(resource: T): T;
140
142
  }
package/menu.d.ts CHANGED
@@ -51,7 +51,6 @@ export interface MenuCancelEvent {
51
51
  * import { Menu, MenuStyle } from "@s2script/sdk/menu";
52
52
  * const m = new Menu("s2script Menu Demo");
53
53
  * m.style = MenuStyle.Center;
54
- * m.freezePlayer = true; // freeze movement while the HUD menu is open
55
54
  * m.addItem("hp", "Heal to 100");
56
55
  * m.addItem("noclip", "Toggle Noclip");
57
56
  * m.onSelect(e => { console.log(`picked ${e.info} (slot ${e.slot})`); });
@@ -65,8 +64,12 @@ export declare class Menu {
65
64
  style: MenuStyle;
66
65
  /** Append an auto Exit control (default true). */
67
66
  exitButton: boolean;
68
- /** When true, a renderer that supports it (the CS2 HUD renderer) freezes the player's movement
69
- * while the menu is open and restores it on close. Default false. */
67
+ /**
68
+ * When true, a renderer that supports it may freeze the player's movement while the menu is open
69
+ * and restore it on close. Default false. The CS2 center renderer currently ignores this and
70
+ * does not freeze movement — freezing is disabled until the menu surface can guarantee it is
71
+ * interactive. The chat renderer also ignores it.
72
+ */
70
73
  freezePlayer: boolean;
71
74
  /** `"immediate"` (default) arms cursor on open. `"tab"` paints first and waits for Tab. */
72
75
  activation: MenuActivation;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@s2script/sdk",
3
- "version": "0.26.0",
3
+ "version": "0.27.1",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "description": "s2script SDK — the builtin capability types (imported as @s2script/sdk/entity, …) plus the `s2s` CLI for building Source 2 / CS2 plugins.",
6
6
  "type": "module",
package/plugin.d.ts CHANGED
@@ -32,7 +32,7 @@ export interface CtxEvents {
32
32
  * Subscribe to a fired game event (post-phase). The {@link GameEvent} is valid only synchronously.
33
33
  * @example
34
34
  * // plugins/disabled/nextmap/src/plugin.ts:133
35
- * ctx.events.on("round_end", () => console.log("round ended"));
35
+ * hook.on("round_end", () => console.log("round ended"));
36
36
  */
37
37
  on(name: string, handler: (ev: GameEvent) => void): void;
38
38
  /** Pre-hook a game event: return a {@link HookResultValue} (`Handled`/`Stop` suppress the client broadcast). */
@@ -158,7 +158,7 @@ export interface CtxTranslations {
158
158
  * client's language, then English), so list your own set before any shared one if you want to be
159
159
  * able to override a shared phrase.
160
160
  *
161
- * @example ctx.translations.load("basecomm", "common");
161
+ * @example translations.load("basecomm", "common");
162
162
  */
163
163
  load(...names: string[]): void;
164
164
  }
@@ -250,7 +250,11 @@ export interface PluginContext {
250
250
  use<T extends object>(
251
251
  name: keyof InterfaceContracts extends never ? string : never
252
252
  ): InterfaceHandle<T>;
253
- /** Resolve an OPTIONAL dep (must be in `optionalPluginDependencies`); null while unpublished. */
253
+ /**
254
+ * Resolve an OPTIONAL dep (must be in `optionalPluginDependencies`); null while unpublished.
255
+ * One-shot lookup — does not track later availability. Prefer watchOptional to follow a provider
256
+ * across load and reload.
257
+ */
254
258
  tryUse<N extends keyof InterfaceContracts>(
255
259
  name: N
256
260
  ): TypedInterfaceHandle<InterfaceContracts[N]> | null;
@@ -305,10 +309,10 @@ export interface PluginHooks {
305
309
  * The {@link GameEvent} is valid only synchronously.
306
310
  */
307
311
  export declare const hook: {
308
- /** Post-phase (`ctx.events.on`). */
312
+ /** Post-phase game-event subscribe. The GameEvent is valid only synchronously. */
309
313
  on(name: string, handler: (ev: GameEvent) => void): void;
310
314
  /**
311
- * Pre-phase (`ctx.events.onPre`). Return {@link HookResultValue} `Handled`/`Stop` to suppress
315
+ * Pre-phase game-event subscribe. Return {@link HookResultValue} `Handled`/`Stop` to suppress
312
316
  * the client broadcast.
313
317
  */
314
318
  onPre(name: string, handler: (ev: GameEvent) => HookResultValue | void): void;
@@ -365,7 +369,8 @@ export declare function use<T extends object>(
365
369
  ): InterfaceHandle<T>;
366
370
  /**
367
371
  * Resolve an OPTIONAL dep (must be in `optionalPluginDependencies`); null while unpublished.
368
- * Load-window only. Same contract as {@link PluginContext.tryUse}.
372
+ * Load-window only. One-shot lookup — does not track later availability. Same contract as
373
+ * {@link PluginContext.tryUse}.
369
374
  */
370
375
  export declare function tryUse<N extends keyof InterfaceContracts>(
371
376
  name: N
@@ -383,7 +388,7 @@ export declare const topmenu: CtxTopMenu;
383
388
  /**
384
389
  * Load-window phrase-file declaration. Same contract as {@link PluginContext.translations}.
385
390
  * Throws after settle. `s2s build` / `sync-phrase-types.mjs` collect `translations.load(...)`
386
- * the same way they collect `ctx.translations.load(...)`.
391
+ * the same way they collect `translations.load(...)`.
387
392
  */
388
393
  export declare const translations: CtxTranslations;
389
394
 
package/sdkhooks.d.ts CHANGED
@@ -55,7 +55,11 @@ export declare const UseType: {
55
55
  * that is not a member here throws.
56
56
  */
57
57
  export declare const SDKHookType: {
58
- /** Pre-apply damage (`DispatchTraceAttack`). Mutate {@link DamageInfo.damage} in place. */
58
+ /**
59
+ * Pre-apply damage, provided by the selected game package (CS2: `CBaseEntity::TakeDamageOld`).
60
+ * Mutate {@link DamageInfo.damage} in place. {@link SDKHook} returns `false` when no game package
61
+ * provides damage hooks.
62
+ */
59
63
  readonly OnTakeDamage: "OnTakeDamage";
60
64
  /**
61
65
  * CheckTransmit mux (wiki `SDKHook_SetTransmit`). `Handled` / `Stop` hide this entity from this
@@ -112,8 +116,8 @@ export declare const SDKHookType: {
112
116
  /** `CanBeAutobalanced`. Return a boolean (not {@link HookResultValue}); last defined wins. */
113
117
  readonly CanBeAutobalanced: "CanBeAutobalanced";
114
118
  /**
115
- * Post-apply damage (`DispatchTraceAttack` after the original). {@link DamageInfo} is read-only
116
- * for effect; mutations are not written back. Return is ignored.
119
+ * Post-apply damage (after the original ran), provided by the selected game package.
120
+ * {@link DamageInfo} is read-only for effect; `damage` assignment is ignored. Return is ignored.
117
121
  */
118
122
  readonly OnTakeDamagePost: "OnTakeDamagePost";
119
123
  /**
@@ -126,7 +130,7 @@ export declare const SDKHookType: {
126
130
  readonly OnTakeDamageAlivePost: "OnTakeDamageAlivePost";
127
131
  /**
128
132
  * `TraceAttack` pre ({@link TraceAttackInfo}). No distinct CS2 virtual yet — {@link SDKHook}
129
- * returns `false` (OnTakeDamage remains the DTA mux).
133
+ * returns `false` (use OnTakeDamage).
130
134
  */
131
135
  readonly TraceAttack: "TraceAttack";
132
136
  /**
@@ -220,8 +224,9 @@ export declare function SDKHook(
220
224
  callback: (info: DamageInfo) => HookResultValue | void,
221
225
  ): boolean;
222
226
  /**
223
- * Post-apply damage. {@link DamageInfo} is a read of the live info after the original ran.
224
- * Return is ignored; Handled does not zero the hit (that is the pre-hook).
227
+ * Post-apply damage. {@link DamageInfo} reads the info after the original ran; it is valid only
228
+ * during the synchronous callback. Return is ignored; Handled does not zero the hit (that is the
229
+ * pre-hook).
225
230
  */
226
231
  export declare function SDKHook(
227
232
  entity: EntityRef | null,
package/topmenu.d.ts CHANGED
@@ -37,7 +37,7 @@ export interface TopMenuSnapshot {
37
37
  }
38
38
  /**
39
39
  * The shared admin/top-menu registry — renderers read {@link TopMenu.snapshot} and dispatch picks
40
- * through {@link TopMenu.select}; items are contributed by plugins via their own ctx.topmenu.
40
+ * through {@link TopMenu.select}; items are contributed by plugins via `topmenu`.
41
41
  * @example
42
42
  * import { TopMenu } from "@s2script/sdk/topmenu";
43
43
  * const snap = TopMenu.snapshot();
package/unsafe.d.ts CHANGED
@@ -22,6 +22,32 @@ export interface EngineCalls {}
22
22
  */
23
23
  export interface EngineHooks {}
24
24
 
25
+ /** Generated bindings augment this map from gamedata/functions.jsonc. */
26
+ export interface EngineFunctions {}
27
+
28
+ export interface FunctionStatus {
29
+ readonly canonicalId: string;
30
+ readonly availability: 'available' | 'unavailable';
31
+ readonly reason: string | null;
32
+ readonly hookObservation: 'not-requested' | 'pending' | 'active' | 'failed';
33
+ readonly provenance: {
34
+ readonly archiveHash: string;
35
+ readonly baseContractHash: string;
36
+ readonly appliedOverrides: readonly { readonly path: string; readonly sha256: string }[];
37
+ readonly finalTargetHash: string;
38
+ readonly resolverReceipt: string;
39
+ readonly required: boolean;
40
+ };
41
+ }
42
+
43
+ export interface Disposable { dispose(): boolean; }
44
+
45
+ export interface FunctionSubscription extends Disposable {
46
+ readonly status: 'pending' | 'active' | 'failed' | 'disposed';
47
+ readonly reason: string | null;
48
+ dispose(): boolean;
49
+ }
50
+
25
51
  /**
26
52
  * Plugin-declared engine calls and inbound hooks, resolved from this plugin's own gamedata.
27
53
  *
@@ -34,6 +60,7 @@ export interface EngineHooks {}
34
60
  * if (onFoo) onFoo((view) => { view.reason = 0; });
35
61
  */
36
62
  export declare const Engine: {
63
+ function<K extends keyof EngineFunctions>(name: K): EngineFunctions[K];
37
64
  /**
38
65
  * The declared call, or `null` when its descriptor failed a load-time gate (signature miss,
39
66
  * validator rejection, slot outside `.text`, missing platform entry, or the plugin is not
@@ -47,7 +74,7 @@ export declare const Engine: {
47
74
  * gate (same class of reasons as {@link Engine.call}, plus a missing `validate` or an unknown
48
75
  * thunk shape). Guard once at load; the returned function records the handler and lazily
49
76
  * installs the detour. The owner is always the calling plugin — you cannot subscribe to
50
- * another plugin's hook through this factory (game-package hooks hang off `ctx.*`).
77
+ * another plugin's hook through this factory (game-package hooks are the `@s2script/cs2` exports such as `players` and `gameRules`).
51
78
  */
52
79
  hook<K extends keyof EngineHooks>(name: K): EngineHooks[K] | null;
53
80
  /** Why a hook descriptor is unavailable; `"available"` when it resolved. */
package/usercmd.d.ts CHANGED
@@ -7,16 +7,16 @@
7
7
  import type { QAngle } from "./math";
8
8
 
9
9
  /**
10
- * A block-scoped view of the CURRENT tick's usercmd (valid only during a `ctx.clients.onRunCmd`
10
+ * A block-scoped view of the CURRENT tick's usercmd (valid only during an `OnPlayerRunCmd`
11
11
  * handler — a stashed `UserCmdView` used after the handler returns, or across an `await`,
12
12
  * reads/writes nothing). There is exactly ONE `UserCmdView` instance for the whole process; every
13
13
  * handler call operates on it.
14
14
  * @example
15
15
  * import type { UserCmdView } from "@s2script/sdk/usercmd";
16
- * // examples/cookbook/src/recipes/usercmd.ts:27 — read this tick's input
17
- * ctx.clients.onRunCmd((cmd: UserCmdView, info: { slot: number }) => {
16
+ * // read this tick's input
17
+ * export function OnPlayerRunCmd(cmd: UserCmdView, info: { slot: number }): void {
18
18
  * console.log(`slot=${info.slot} fwd=${cmd.forwardMove} btn=${cmd.buttons}`);
19
- * });
19
+ * }
20
20
  */
21
21
  export interface UserCmdView {
22
22
  /** +forward / -back. Normalized to roughly [-1, 1] (not the legacy ±450 units). */
package/ws.d.ts CHANGED
@@ -9,7 +9,10 @@ export interface WebSocket {
9
9
  /** Register a handler for a transport error; `err` is the error text. */
10
10
  onError(handler: (err: string) => void): void;
11
11
  /** Send a text frame. */
12
- /** Returns false if closed, oversized, or the connection/global outbound budget is full. */
12
+ /**
13
+ * Send a text frame. Returns false if closed, oversized, or the connection/global outbound
14
+ * budget is full.
15
+ */
13
16
  send(data: string): boolean;
14
17
  /** Close the connection. */
15
18
  close(): void;