@i2analyze/notebook-sdk 1.10.0-dev.15 → 1.10.0-dev.16
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/AGENTS.md +179 -0
- package/package.json +6 -4
package/AGENTS.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# AGENTS.md — i2 Notebook Web SDK
|
|
2
|
+
|
|
3
|
+
Guidance for AI coding assistants (Claude Code, Cursor, Copilot, etc.) writing i2 Analyst's
|
|
4
|
+
Notebook **web client plug-ins** with `@i2analyze/notebook-sdk`. Follow this over habits learned
|
|
5
|
+
from other SDKs. If a rule here conflicts with a code sample you found online, this file wins.
|
|
6
|
+
|
|
7
|
+
Docs: https://i2group.github.io/notebook-sdk/ · API reference: https://i2group.github.io/notebook-sdk/api/ · Machine-readable: https://i2group.github.io/notebook-sdk/llms.txt
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## 0. The one rule that matters most: how to start a plug-in
|
|
12
|
+
|
|
13
|
+
**To create a NEW plug-in project, ALWAYS scaffold with the tool. Never hand-write a project
|
|
14
|
+
skeleton, and never copy a sample or tutorial as the starting boilerplate.**
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm create @i2analyze/notebook-plugin # or: npx @i2analyze/create-notebook-plugin
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Templates (pass `--template=`):
|
|
21
|
+
|
|
22
|
+
- `plugin` (default) — headless plug-in with an `entrypoint.ts`, no UI.
|
|
23
|
+
- `plugin-with-toolview` — adds a React tool view (`ToolView` component + `index.html`).
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm create @i2analyze/notebook-plugin -- --template=plugin-with-toolview
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The scaffold wires up TypeScript, ESLint, Prettier, webpack production bundling, the dev proxy
|
|
30
|
+
(`devproxy.json`), and a correct `plugin.json` manifest. Reproducing this by hand gets the manifest,
|
|
31
|
+
CSP, version pinning, and build config subtly wrong.
|
|
32
|
+
|
|
33
|
+
> ❌ **Do NOT** treat `samples/basic-plugin` or the guide page **"Creating a basic plug-in for the
|
|
34
|
+
> i2 Web Client"** (`tutorials/basic-plugin.md`) as the recommended boilerplate. Those exist to
|
|
35
|
+
> *explain concepts from first principles*. The recommended path for real plug-ins is the
|
|
36
|
+
> **`create-notebook-plugin` tool** and its tutorial (`tutorials/create-notebook-plugin.md`).
|
|
37
|
+
> When a user asks you to "make a plug-in", scaffold with the tool, then edit `src/entrypoint.ts`.
|
|
38
|
+
|
|
39
|
+
If you cannot run the scaffolder (e.g. offline), say so explicitly and reproduce the generated
|
|
40
|
+
`plugin/` template structure faithfully rather than inventing a layout.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## 1. Mental model
|
|
45
|
+
|
|
46
|
+
A plug-in is static assets (JS + a `plugin.json` manifest) served to the i2 Web Client. Three parts:
|
|
47
|
+
|
|
48
|
+
1. **Manifest** (`public/plugin.json`) — identity (`pluginId`, `name`, `pluginVersion`), the
|
|
49
|
+
`entryPointUrl`, and CSP. Schema:
|
|
50
|
+
`https://i2group.github.io/notebook-sdk/schemas/plugin-manifest.json` (keep the `$schema` line —
|
|
51
|
+
it gives editors and agents live validation).
|
|
52
|
+
2. **Entry point** (`src/entrypoint.ts`) — runs on load. Acquires the versioned API, registers
|
|
53
|
+
capabilities (commands, tool views), then calls `api.initializationComplete()`.
|
|
54
|
+
3. **Tool views** (optional) — iframed HTML/JS UIs (React in the template) for richer interaction.
|
|
55
|
+
|
|
56
|
+
## 2. Acquiring the API — the version you request is a minimum, not "your SDK version"
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { NotebookStatic } from '@i2analyze/notebook-sdk';
|
|
60
|
+
declare const notebook: NotebookStatic;
|
|
61
|
+
|
|
62
|
+
async function main() {
|
|
63
|
+
const api = await notebook.getEntryPointApi('<your-plugin-id>', '1.3'); // minimum API version required
|
|
64
|
+
// ...register capabilities...
|
|
65
|
+
api.initializationComplete();
|
|
66
|
+
}
|
|
67
|
+
main();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- The `major.minor` you pass is the **minimum API version your plug-in needs from the deployed
|
|
71
|
+
i2 Notebook backend** — *not* the version of the SDK you happened to install. The call asks the
|
|
72
|
+
running server "do you serve a client that supports at least this API version?" and **rejects** if
|
|
73
|
+
the server is older than requested (or if `pluginId` is absent from the manifest).
|
|
74
|
+
- **Choose the lowest version that includes every API you actually use.** A lower number runs on a
|
|
75
|
+
wider range of i2 Analyze servers; a higher number requires a newer server but unlocks newer APIs.
|
|
76
|
+
See the SDK ↔ i2 Analyze compatibility table in the *SDK and API versioning* guide.
|
|
77
|
+
- Ceiling: it can't exceed the API version of the installed `@i2analyze/notebook-sdk` (you can only
|
|
78
|
+
call types the SDK ships). Within that ceiling, prefer the floor. The `create-notebook-plugin`
|
|
79
|
+
scaffold sets a deliberately low default (currently `1.3`) for broad compatibility — only raise it
|
|
80
|
+
when you adopt an API introduced in a later version. **Do not "upgrade" it to match the SDK.**
|
|
81
|
+
- (The templates use the unbundled global `notebook`, so you choose the version explicitly. If you
|
|
82
|
+
instead `import { getEntryPointApi }` from the SDK and bundle it, that entry point uses the SDK's
|
|
83
|
+
own version automatically.)
|
|
84
|
+
- Keep the `pluginId` identical in code and manifest.
|
|
85
|
+
- You **must** call `api.initializationComplete()` once setup is done, or the plug-in never finishes loading.
|
|
86
|
+
|
|
87
|
+
## 3. Commands (the primary way to add behaviour)
|
|
88
|
+
|
|
89
|
+
Create with `api.commands.createCommand({...})`, then *surface* it into one or more UI locations.
|
|
90
|
+
Command `type` scopes the execution context: `'unscoped'`, `'records'`, etc. The scaffold uses
|
|
91
|
+
`'unscoped'`; switch to `'records'` when you act on the current selection.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const cmd = api.commands.createCommand({
|
|
95
|
+
id: 'view-on-map',
|
|
96
|
+
name: 'View on map',
|
|
97
|
+
icon: { type: 'inlineSvg', svg: commandSvg },
|
|
98
|
+
type: 'records',
|
|
99
|
+
onExecute(payload: commands.IRecordsContext) { /* ... */ },
|
|
100
|
+
onSurface(action, eventApi, signal) {
|
|
101
|
+
// Control enablement per surfacing. dispatchNow runs the callback immediately;
|
|
102
|
+
// forwarding `signal` auto-unsubscribes when this surfacing is removed.
|
|
103
|
+
eventApi.addEventListener('recordscontextchange',
|
|
104
|
+
(ctx) => action.setEnabled(/* predicate over ctx.records */ true),
|
|
105
|
+
{ dispatchNow: true, signal });
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
api.commands.applicationRibbon.homeTab.surfaceCommands(cmd);
|
|
110
|
+
api.commands.chartPopupMenu.surfaceCommands(cmd); // same command, multiple places
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Best practice:** gate enablement in `onSurface` via events rather than leaving buttons always-on;
|
|
114
|
+
always forward `signal` to listeners so they clean up on unsurface.
|
|
115
|
+
|
|
116
|
+
## 4. Reading data
|
|
117
|
+
|
|
118
|
+
Access via the versioned `data` / `records` / `chart` namespaces. Records expose typed properties
|
|
119
|
+
through their `itemType`.
|
|
120
|
+
|
|
121
|
+
- Iterate `record.itemType.propertyTypes`; read with `record.getProperty(propertyType)`.
|
|
122
|
+
- **Check `record.isValueUnfetched(property)` before use** — the client lazily loads values, and an
|
|
123
|
+
unfetched value is not the same as an empty one. See guide: *Unfetched property values*.
|
|
124
|
+
- Collections are `data.IReadOnlyCollection<T>` (use `.size`, `.firstOrDefault(undefined)`), not JS arrays.
|
|
125
|
+
|
|
126
|
+
## 5. Changing data — tracked vs untracked mutations
|
|
127
|
+
|
|
128
|
+
All writes go through a mutation callback; never mutate model objects directly.
|
|
129
|
+
|
|
130
|
+
- **`runTrackedMutations`** — for changes that modify data (add/edit/delete records, notes, etc.).
|
|
131
|
+
These are undoable and validated. Return `{ type: 'commit' }` or `{ type: 'rollback' }`.
|
|
132
|
+
- **`runUntrackedMutations`** — for view-only changes that don't touch data, e.g. selection or
|
|
133
|
+
untracked element style. Lighter weight; not part of undo history.
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
await api.runTrackedMutations(async (application, mutations, cancelation) => {
|
|
137
|
+
if (application.chart.selection.records.size === 0) return { type: 'rollback' }; // no-op, not an error
|
|
138
|
+
const id = mutations.addEntityRecord({ itemType, properties: {}, notes: [], security, sourceReferences: [] });
|
|
139
|
+
return { type: 'commit' };
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Guides: *Changing data from a plug-in*, *Supported mutation operations*, *Untracked element style editing*.
|
|
144
|
+
|
|
145
|
+
## 6. Dev loop, build, deploy
|
|
146
|
+
|
|
147
|
+
- `npm run dev` — dev server + `notebook-sdk-plugin-proxy` (proxies to your i2 Analyze server; edit
|
|
148
|
+
`devproxy.json` to change the target). Open the Web Client and look for your ribbon button /
|
|
149
|
+
console message.
|
|
150
|
+
- `npm run build` — production webpack bundle into `dist/`.
|
|
151
|
+
- **Deploy:** copy `dist/` into the server's
|
|
152
|
+
`toolkit/configuration/fragments/opal-services/plugins/<your-plugin>/`, then
|
|
153
|
+
`setup -t stopLiberty && setup -t deployLiberty && setup -t startLiberty` (repeat on every Liberty
|
|
154
|
+
node in HA). Guide: *Deploying to an i2 Analyze server*.
|
|
155
|
+
|
|
156
|
+
## 7. Versioned API namespaces
|
|
157
|
+
|
|
158
|
+
Import types from `@i2analyze/notebook-sdk`; the runtime API is grouped into:
|
|
159
|
+
`app`, `chart`, `commands`, `data`, `dialog`, `records`, `schema`, `toolview`, `visual`
|
|
160
|
+
(plus `ILogger`, `IEntryPointApi`, `LogLevel`). Prefer these typed namespaces over `any`.
|
|
161
|
+
|
|
162
|
+
## 8. Footguns / anti-patterns
|
|
163
|
+
|
|
164
|
+
- ❌ Hand-rolling the project or copying `basic-plugin` — see §0.
|
|
165
|
+
- ❌ Guessing the API version, or letting manifest `pluginId` drift from the code id.
|
|
166
|
+
- ❌ Forgetting `api.initializationComplete()`.
|
|
167
|
+
- ❌ Reading a property without an `isValueUnfetched` check.
|
|
168
|
+
- ❌ Using `runTrackedMutations` for selection-only changes (use untracked), or mutating model objects outside a mutation callback.
|
|
169
|
+
- ❌ Leaving commands always-enabled instead of gating in `onSurface`.
|
|
170
|
+
- ⚠️ Before relying on a member, check its `@i2since` tag in the API reference: it names the API
|
|
171
|
+
version that introduced it. If you use it, the plug-in's requested minimum version (§2) must be at
|
|
172
|
+
least that value. The public API is a single stable surface — there are no `@beta`/`@alpha` tiers.
|
|
173
|
+
|
|
174
|
+
## 9. When unsure
|
|
175
|
+
|
|
176
|
+
Prefer these accurate sources over memory: the API reference
|
|
177
|
+
(https://i2group.github.io/notebook-sdk/api/), the guide, the `samples/` directory, and
|
|
178
|
+
`packages/notebook-sdk/src/use-the-api.ts` (worked mutation examples). For machine ingestion, fetch
|
|
179
|
+
`https://i2group.github.io/notebook-sdk/llms-full.txt`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i2analyze/notebook-sdk",
|
|
3
|
-
"version": "1.10.0-dev.
|
|
3
|
+
"version": "1.10.0-dev.16",
|
|
4
4
|
"description": "i2 Notebook SDK",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"publishConfig": {
|
|
@@ -33,14 +33,16 @@
|
|
|
33
33
|
"api-extractor:dev": "api-extractor run --local --verbose --config scripts/api-extractor.json",
|
|
34
34
|
"api-extractor:ci": "api-extractor run --verbose --config scripts/api-extractor.json",
|
|
35
35
|
"build": "npm run compile",
|
|
36
|
-
"clean": "rimraf bld dist doc/obj",
|
|
37
|
-
"prepare": "copyfiles --flat dist/es/index.js lib/"
|
|
36
|
+
"clean": "rimraf bld dist doc/obj AGENTS.md",
|
|
37
|
+
"prepare": "copyfiles --flat dist/es/index.js lib/",
|
|
38
|
+
"prepack": "node scripts/copy-agents-md.js"
|
|
38
39
|
},
|
|
39
40
|
"files": [
|
|
40
41
|
"lib/index.js",
|
|
41
42
|
"lib/index.d.ts",
|
|
42
43
|
"lib/gen/notebook-sdk-public.d.ts",
|
|
43
|
-
"lib/tsdoc-metadata.json"
|
|
44
|
+
"lib/tsdoc-metadata.json",
|
|
45
|
+
"AGENTS.md"
|
|
44
46
|
],
|
|
45
47
|
"main": "",
|
|
46
48
|
"module": "lib/index.js",
|