@nimbalyst/extension-sdk 0.2.0 → 0.2.2

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.
Files changed (79) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +32 -0
  3. package/dist/__tests__/createTextCollabContentAdapter.test.d.ts +2 -0
  4. package/dist/__tests__/createTextCollabContentAdapter.test.d.ts.map +1 -0
  5. package/dist/__tests__/createTextCollabContentAdapter.test.js +60 -0
  6. package/dist/__tests__/externalsPlugin.test.d.ts +2 -0
  7. package/dist/__tests__/externalsPlugin.test.d.ts.map +1 -0
  8. package/dist/__tests__/externalsPlugin.test.js +16 -0
  9. package/dist/__tests__/fileDirectoryTree.test.d.ts +2 -0
  10. package/dist/__tests__/fileDirectoryTree.test.d.ts.map +1 -0
  11. package/dist/__tests__/fileDirectoryTree.test.js +54 -0
  12. package/dist/__tests__/hasSeedableContent.test.d.ts +2 -0
  13. package/dist/__tests__/hasSeedableContent.test.d.ts.map +1 -0
  14. package/dist/__tests__/hasSeedableContent.test.js +25 -0
  15. package/dist/__tests__/manifestValidation.agentProviders.test.d.ts +2 -0
  16. package/dist/__tests__/manifestValidation.agentProviders.test.d.ts.map +1 -0
  17. package/dist/__tests__/manifestValidation.agentProviders.test.js +44 -0
  18. package/dist/agents/AgentProtocol.d.ts +233 -0
  19. package/dist/agents/AgentProtocol.d.ts.map +1 -0
  20. package/dist/agents/AgentProtocol.js +23 -0
  21. package/dist/agents/AgentProtocolHost.d.ts +190 -0
  22. package/dist/agents/AgentProtocolHost.d.ts.map +1 -0
  23. package/dist/agents/AgentProtocolHost.js +42 -0
  24. package/dist/agents/index.d.ts +26 -0
  25. package/dist/agents/index.d.ts.map +1 -0
  26. package/dist/agents/index.js +24 -0
  27. package/dist/collab/createTextCollabContentAdapter.d.ts +26 -0
  28. package/dist/collab/createTextCollabContentAdapter.d.ts.map +1 -0
  29. package/dist/collab/createTextCollabContentAdapter.js +79 -0
  30. package/dist/externalsPlugin.js +10 -0
  31. package/dist/fileDirectoryTree.d.ts +19 -0
  32. package/dist/fileDirectoryTree.d.ts.map +1 -0
  33. package/dist/fileDirectoryTree.js +98 -0
  34. package/dist/index.d.ts +5 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +7 -0
  37. package/dist/manifestValidation.d.ts +118 -0
  38. package/dist/manifestValidation.d.ts.map +1 -0
  39. package/dist/manifestValidation.js +475 -0
  40. package/dist/trackerReferences.d.ts +32 -0
  41. package/dist/trackerReferences.d.ts.map +1 -0
  42. package/dist/trackerReferences.js +7 -0
  43. package/dist/types/collab.d.ts +138 -0
  44. package/dist/types/collab.d.ts.map +1 -0
  45. package/dist/types/collab.js +1 -0
  46. package/dist/types/editor.d.ts +81 -0
  47. package/dist/types/editor.d.ts.map +1 -1
  48. package/dist/types/editors.d.ts +4 -0
  49. package/dist/types/editors.d.ts.map +1 -1
  50. package/dist/types/extension.d.ts +364 -5
  51. package/dist/types/extension.d.ts.map +1 -1
  52. package/dist/types/extension.js +11 -1
  53. package/dist/types/index.d.ts +3 -0
  54. package/dist/types/index.d.ts.map +1 -1
  55. package/dist/types/index.js +3 -0
  56. package/dist/types/panel.d.ts +50 -0
  57. package/dist/types/panel.d.ts.map +1 -1
  58. package/dist/types/permissions.d.ts +119 -0
  59. package/dist/types/permissions.d.ts.map +1 -0
  60. package/dist/types/permissions.js +33 -0
  61. package/dist/types/theme.d.ts +50 -0
  62. package/dist/types/theme.d.ts.map +1 -1
  63. package/dist/types/theme.js +7 -1
  64. package/dist/types/trackerImporter.d.ts +147 -0
  65. package/dist/types/trackerImporter.d.ts.map +1 -0
  66. package/dist/types/trackerImporter.js +33 -0
  67. package/dist/useCollaborativeEditor.d.ts +84 -30
  68. package/dist/useCollaborativeEditor.d.ts.map +1 -1
  69. package/dist/useCollaborativeEditor.js +98 -7
  70. package/dist/validate.browser.d.ts +5 -0
  71. package/dist/validate.browser.d.ts.map +1 -0
  72. package/dist/validate.browser.js +27 -0
  73. package/dist/validate.d.ts +2 -8
  74. package/dist/validate.d.ts.map +1 -1
  75. package/dist/validate.js +117 -0
  76. package/dist/validationTypes.d.ts +9 -0
  77. package/dist/validationTypes.d.ts.map +1 -0
  78. package/dist/validationTypes.js +1 -0
  79. package/package.json +8 -1
@@ -0,0 +1,190 @@
1
+ /**
2
+ * AgentProtocolHost
3
+ * -----------------
4
+ *
5
+ * Surface that the host (Nimbalyst) provides to an extension-owned
6
+ * `AgentProtocol` implementation at runtime. The protocol implementation
7
+ * lives in an extension's backend module and is brokered to the host by
8
+ * the privileged-host backend-module runtime; it must never reach for
9
+ * host internals directly.
10
+ *
11
+ * Identity fields are immutable for the lifetime of the host: they
12
+ * identify which extension contribution this protocol instance belongs
13
+ * to and which backend module is hosting it. Per-turn inputs (session
14
+ * id, workspace path, model, abort signal, permission mode, MCP
15
+ * servers, environment) are immutable for the lifetime of a single
16
+ * turn but may differ between turns on the same host instance.
17
+ *
18
+ * All async methods reject when the underlying broker call is rejected
19
+ * by the host (missing permission, unknown session, workspace
20
+ * mismatch, etc.) -- the protocol implementation is expected to
21
+ * surface those rejections as protocol-level errors rather than
22
+ * swallowing them.
23
+ *
24
+ * -------------------------------------------------------------------
25
+ * Q7 -- scope of this host (Phase-4 SDK proposal, resolved 2026-06-02)
26
+ * -------------------------------------------------------------------
27
+ *
28
+ * Per Q7 (Phase-4 SDK proposal, resolved 2026-06-02):
29
+ * emitEvent / requestPermission / askUserQuestion stay provider-private
30
+ * per the established upstream pattern (OpenAICodexProvider:1422-1491,
31
+ * claudeCode/askUserQuestion.ts:10, ProviderSessionManager.ts:49).
32
+ * Section 4.3's full facade is the agreed end-state, hoisted
33
+ * incrementally when each in-tree provider is next touched. Phase 4
34
+ * therefore ships the minimal 5-method host below; the missing
35
+ * methods are NOT a regression -- they live on the provider's own
36
+ * surface today and migrate behind a stable facade as each provider
37
+ * is reworked.
38
+ *
39
+ * See `docs/EXTENSION_ARCHITECTURE.md` and the Phase 4 SDK design doc
40
+ * (Section 4.3) for the full host contract.
41
+ */
42
+ import type { MCPServerConfig } from './index';
43
+ /**
44
+ * Permission posture the host has set for the current turn.
45
+ *
46
+ * - `ask` -- prompt the user for every tool call that requires
47
+ * consent.
48
+ * - `auto` -- pre-approved tool calls run without prompting;
49
+ * everything else still goes through the provider's own
50
+ * permission path (see Q7 above).
51
+ * - `plan` -- read-only / planning posture; the protocol
52
+ * implementation MUST NOT invoke side-effecting tools
53
+ * and SHOULD use this hint to bias the model toward
54
+ * planning output.
55
+ *
56
+ * This is advisory metadata about the host's posture. The provider's
57
+ * own permission code (kept provider-private per Q7) is still the
58
+ * authoritative gate at tool-call time.
59
+ */
60
+ export type PermissionMode = 'ask' | 'auto' | 'plan';
61
+ /**
62
+ * MCP tool the protocol implementation wants to register with the
63
+ * host for this session. The host federates these into the
64
+ * session-wide tool registry and exposes them to the model alongside
65
+ * built-in tools.
66
+ */
67
+ export interface McpToolDefinition {
68
+ /**
69
+ * Tool name as the model will see it (e.g.
70
+ * `mcp__antigravity__plan`).
71
+ */
72
+ name: string;
73
+ /**
74
+ * Short description for the model and for the consent prompt.
75
+ */
76
+ description: string;
77
+ /**
78
+ * JSON Schema for the tool's input. The host validates calls
79
+ * against this before invoking the handler.
80
+ */
81
+ inputSchema: Record<string, unknown>;
82
+ }
83
+ /**
84
+ * Host surface passed to an extension's `AgentProtocol`
85
+ * implementation.
86
+ *
87
+ * Identity fields are constant; per-turn inputs are constant for the
88
+ * lifetime of a single turn. Methods may be invoked multiple times
89
+ * per turn (subject to the host's rate-limits and permission gates).
90
+ *
91
+ * Surface size is intentionally minimal -- see the Q7 note in the
92
+ * file header for why emitEvent / requestPermission /
93
+ * askUserQuestion are not on this interface.
94
+ */
95
+ export interface AgentProtocolHost {
96
+ /** Extension that owns the protocol implementation. */
97
+ readonly extensionId: string;
98
+ /**
99
+ * Contribution id this host instance was created for (matches the
100
+ * `id` field on an `AiAgentProviderContribution`).
101
+ */
102
+ readonly providerContributionId: string;
103
+ /**
104
+ * Backend module id hosting the protocol implementation (matches
105
+ * the `id` on a `BackendModuleContribution`).
106
+ */
107
+ readonly backendModuleId: string;
108
+ /** Active AI session id this turn belongs to. */
109
+ readonly sessionId: string;
110
+ /** Absolute workspace path the session is scoped to. */
111
+ readonly workspacePath: string;
112
+ /**
113
+ * Model id the user picked for this turn (`undefined` if the
114
+ * provider does not require a model selection).
115
+ */
116
+ readonly model?: string;
117
+ /**
118
+ * Abort signal that fires when the user cancels the turn or the
119
+ * host tears the session down. Protocol implementations MUST
120
+ * honour it promptly.
121
+ */
122
+ readonly abortSignal: AbortSignal;
123
+ /** Permission posture the host has set for this turn. */
124
+ readonly permissionMode: PermissionMode;
125
+ /**
126
+ * MCP servers the user has configured for this session. The
127
+ * protocol implementation may pass these through to the
128
+ * underlying agent runtime; the host is responsible for credential
129
+ * resolution.
130
+ */
131
+ readonly mcpServers: readonly MCPServerConfig[];
132
+ /**
133
+ * Environment overrides the host wants applied when the protocol
134
+ * spawns its agent runtime. Keys are environment variable names;
135
+ * values are already-resolved strings (no template substitution).
136
+ */
137
+ readonly env: Readonly<Record<string, string>>;
138
+ /**
139
+ * Append a raw provider-native payload to `ai_agent_messages`.
140
+ * This is the single source of truth for the transcript; the
141
+ * host's transcript transformer derives canonical events from it.
142
+ *
143
+ * `direction` is `'input'` for payloads the host sent to the
144
+ * provider and `'output'` for payloads the provider returned.
145
+ * `metadata` is opaque to the host; surfaced verbatim in raw-log
146
+ * tooling.
147
+ *
148
+ * Resolves once the row is durably written.
149
+ */
150
+ logRaw(sessionId: string, direction: 'input' | 'output', content: string, metadata?: Record<string, unknown>): Promise<void>;
151
+ /**
152
+ * Resolve an API key for the given provider id from the host's
153
+ * settings store (the same store the user manages from Settings).
154
+ *
155
+ * Resolves to `undefined` when no key is configured; the protocol
156
+ * implementation MUST NOT fall back to `process.env` (see the
157
+ * "Never Use Environment Variables as Implicit API Key Sources"
158
+ * rule in the project CLAUDE.md).
159
+ */
160
+ getApiKey(providerId: string): Promise<string | undefined>;
161
+ /**
162
+ * Read a workspace file via the host's filesystem broker. The
163
+ * path is resolved against `workspacePath`; reads outside the
164
+ * workspace are rejected.
165
+ *
166
+ * Returns the raw bytes; the protocol implementation is
167
+ * responsible for decoding.
168
+ */
169
+ readWorkspaceFile(path: string): Promise<Uint8Array>;
170
+ /**
171
+ * Write a workspace file via the host's filesystem broker.
172
+ * Subject to the extension's granted workspace-files permission;
173
+ * writes outside the workspace are rejected.
174
+ */
175
+ writeWorkspaceFile(path: string, content: Uint8Array): Promise<void>;
176
+ /**
177
+ * Register a batch of MCP tools with the host's session-scoped
178
+ * tool registry for the lifetime of this session. The returned
179
+ * promise resolves once the tools are visible to the model.
180
+ *
181
+ * Calling again replaces the prior registration for this host
182
+ * instance; pass an empty array to clear it. Tool handlers
183
+ * themselves are NOT part of this contract -- per Q7, the
184
+ * provider keeps its own dispatch path. The host only needs the
185
+ * advertised name / description / schema to expose the tool to
186
+ * the model and (eventually) to the provider's permission path.
187
+ */
188
+ registerMcpTools(tools: McpToolDefinition[]): Promise<void>;
189
+ }
190
+ //# sourceMappingURL=AgentProtocolHost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentProtocolHost.d.ts","sourceRoot":"","sources":["../../src/agents/AgentProtocolHost.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,CAAC;AAErD;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;A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ErE;;;;;;;;;;;OAWG;IACH,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7D"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * AgentProtocolHost
3
+ * -----------------
4
+ *
5
+ * Surface that the host (Nimbalyst) provides to an extension-owned
6
+ * `AgentProtocol` implementation at runtime. The protocol implementation
7
+ * lives in an extension's backend module and is brokered to the host by
8
+ * the privileged-host backend-module runtime; it must never reach for
9
+ * host internals directly.
10
+ *
11
+ * Identity fields are immutable for the lifetime of the host: they
12
+ * identify which extension contribution this protocol instance belongs
13
+ * to and which backend module is hosting it. Per-turn inputs (session
14
+ * id, workspace path, model, abort signal, permission mode, MCP
15
+ * servers, environment) are immutable for the lifetime of a single
16
+ * turn but may differ between turns on the same host instance.
17
+ *
18
+ * All async methods reject when the underlying broker call is rejected
19
+ * by the host (missing permission, unknown session, workspace
20
+ * mismatch, etc.) -- the protocol implementation is expected to
21
+ * surface those rejections as protocol-level errors rather than
22
+ * swallowing them.
23
+ *
24
+ * -------------------------------------------------------------------
25
+ * Q7 -- scope of this host (Phase-4 SDK proposal, resolved 2026-06-02)
26
+ * -------------------------------------------------------------------
27
+ *
28
+ * Per Q7 (Phase-4 SDK proposal, resolved 2026-06-02):
29
+ * emitEvent / requestPermission / askUserQuestion stay provider-private
30
+ * per the established upstream pattern (OpenAICodexProvider:1422-1491,
31
+ * claudeCode/askUserQuestion.ts:10, ProviderSessionManager.ts:49).
32
+ * Section 4.3's full facade is the agreed end-state, hoisted
33
+ * incrementally when each in-tree provider is next touched. Phase 4
34
+ * therefore ships the minimal 5-method host below; the missing
35
+ * methods are NOT a regression -- they live on the provider's own
36
+ * surface today and migrate behind a stable facade as each provider
37
+ * is reworked.
38
+ *
39
+ * See `docs/EXTENSION_ARCHITECTURE.md` and the Phase 4 SDK design doc
40
+ * (Section 4.3) for the full host contract.
41
+ */
42
+ export {};
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Public agent-provider surface for the Nimbalyst extension SDK.
3
+ *
4
+ * Extensions that ship an `AiAgentProviderContribution` import the
5
+ * `AgentProtocol`, `AgentProtocolHost`, and supporting types from
6
+ * this subpath:
7
+ *
8
+ * import type {
9
+ * AgentProtocol,
10
+ * AgentProtocolHost,
11
+ * PermissionMode,
12
+ * } from '@nimbalyst/extension-sdk/agents';
13
+ *
14
+ * Ownership model (post Phase-4 dependency inversion):
15
+ *
16
+ * - The transport types (`AgentProtocol`, `ProtocolEvent`, ...) are
17
+ * owned by the SDK in `./AgentProtocol`. The runtime re-exports
18
+ * them from its own `ProtocolInterface` module so existing
19
+ * runtime imports stay source-stable.
20
+ * - The host-surface types (`AgentProtocolHost`, `PermissionMode`,
21
+ * `McpToolDefinition`) live in this package because they only
22
+ * have meaning at the extension boundary.
23
+ */
24
+ export type { AgentProtocol, ProtocolEvent, ProtocolMessage, ProtocolSession, ProtocolAttachment, SessionOptions, ProtocolEventType, ToolResult, MCPServerConfig, RawProtocolSession, } from './AgentProtocol.js';
25
+ export type { AgentProtocolHost, PermissionMode, McpToolDefinition, } from './AgentProtocolHost.js';
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agents/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAGH,YAAY,EACV,aAAa,EACb,aAAa,EACb,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAc5B,YAAY,EACV,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Public agent-provider surface for the Nimbalyst extension SDK.
3
+ *
4
+ * Extensions that ship an `AiAgentProviderContribution` import the
5
+ * `AgentProtocol`, `AgentProtocolHost`, and supporting types from
6
+ * this subpath:
7
+ *
8
+ * import type {
9
+ * AgentProtocol,
10
+ * AgentProtocolHost,
11
+ * PermissionMode,
12
+ * } from '@nimbalyst/extension-sdk/agents';
13
+ *
14
+ * Ownership model (post Phase-4 dependency inversion):
15
+ *
16
+ * - The transport types (`AgentProtocol`, `ProtocolEvent`, ...) are
17
+ * owned by the SDK in `./AgentProtocol`. The runtime re-exports
18
+ * them from its own `ProtocolInterface` module so existing
19
+ * runtime imports stay source-stable.
20
+ * - The host-surface types (`AgentProtocolHost`, `PermissionMode`,
21
+ * `McpToolDefinition`) live in this package because they only
22
+ * have meaning at the extension boundary.
23
+ */
24
+ export {};
@@ -0,0 +1,26 @@
1
+ import type { CollabAdapterDescriptor, CollabContentAdapter } from '../types/collab.js';
2
+ /** Default `Y.Text` field name used when none is supplied. */
3
+ export declare const TEXT_COLLAB_DEFAULT_FIELD = "content";
4
+ export interface TextCollabContentAdapterOptions {
5
+ /** Logical document type. Matches the shared doc's documentType and, by
6
+ * convention, the custom-editor suffix without its dot (e.g. 'calc.md'). */
7
+ documentType: string;
8
+ /** On-disk extensions this adapter is the codec for (leading dot). The
9
+ * first entry is the default for save-a-copy / export. */
10
+ fileExtensions: string[];
11
+ /** Optional MIME type for save dialogs / asset uploads. */
12
+ mimeType?: string;
13
+ /** Y.Text field name carrying the document text. Default 'content'. The
14
+ * live binding MUST use the same field. */
15
+ textField?: string;
16
+ /** Layout schema version. Default 1. */
17
+ layoutVersion?: number;
18
+ }
19
+ export declare function createTextCollabContentAdapter(options: TextCollabContentAdapterOptions): CollabContentAdapter;
20
+ /**
21
+ * Rebuild a CollabContentAdapter from a serializable descriptor (produced by a
22
+ * host factory and shipped across the process boundary). Returns null for an
23
+ * unknown descriptor kind so callers can fall back gracefully.
24
+ */
25
+ export declare function reconstructCollabContentAdapterFromDescriptor(descriptor: CollabAdapterDescriptor): CollabContentAdapter | null;
26
+ //# sourceMappingURL=createTextCollabContentAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createTextCollabContentAdapter.d.ts","sourceRoot":"","sources":["../../src/collab/createTextCollabContentAdapter.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EACV,uBAAuB,EACvB,oBAAoB,EAErB,MAAM,oBAAoB,CAAC;AAE5B,8DAA8D;AAC9D,eAAO,MAAM,yBAAyB,YAAY,CAAC;AAEnD,MAAM,WAAW,+BAA+B;IAC9C;iFAC6E;IAC7E,YAAY,EAAE,MAAM,CAAC;IACrB;+DAC2D;IAC3D,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;gDAC4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,wCAAwC;IACxC,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAWD,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,oBAAoB,CAoDtB;AAED;;;;GAIG;AACH,wBAAgB,6CAA6C,CAC3D,UAAU,EAAE,uBAAuB,GAClC,oBAAoB,GAAG,IAAI,CAW7B"}
@@ -0,0 +1,79 @@
1
+ /** Default `Y.Text` field name used when none is supplied. */
2
+ export const TEXT_COLLAB_DEFAULT_FIELD = 'content';
3
+ function decodeSource(source) {
4
+ if (typeof source === 'string')
5
+ return source;
6
+ try {
7
+ return new TextDecoder('utf-8').decode(source);
8
+ }
9
+ catch {
10
+ return '';
11
+ }
12
+ }
13
+ export function createTextCollabContentAdapter(options) {
14
+ const field = options.textField ?? TEXT_COLLAB_DEFAULT_FIELD;
15
+ const layoutVersion = options.layoutVersion ?? 1;
16
+ const getText = (yDoc) => yDoc.getText(field);
17
+ return {
18
+ documentType: options.documentType,
19
+ fileExtensions: options.fileExtensions,
20
+ mimeType: options.mimeType,
21
+ layoutVersion,
22
+ // Lets the host rebuild this adapter in another process (e.g. Electron
23
+ // main) without loading the extension. See reconstruct fn below.
24
+ serializableDescriptor: {
25
+ kind: 'text',
26
+ documentType: options.documentType,
27
+ fileExtensions: options.fileExtensions,
28
+ mimeType: options.mimeType,
29
+ textField: field,
30
+ layoutVersion,
31
+ },
32
+ isEmpty(yDoc) {
33
+ return getText(yDoc).length === 0;
34
+ },
35
+ seedFromFile(yDoc, source) {
36
+ const text = decodeSource(source);
37
+ if (!text)
38
+ return;
39
+ const yText = getText(yDoc);
40
+ // Guard against a concurrent seed during the open race.
41
+ if (yText.length > 0)
42
+ return;
43
+ yText.insert(0, text);
44
+ },
45
+ applyFromFile(yDoc, source) {
46
+ const text = decodeSource(source);
47
+ yDoc.transact(() => {
48
+ const yText = getText(yDoc);
49
+ if (yText.length > 0)
50
+ yText.delete(0, yText.length);
51
+ if (text.length > 0)
52
+ yText.insert(0, text);
53
+ });
54
+ },
55
+ exportToFile(yDoc) {
56
+ return getText(yDoc).toString();
57
+ },
58
+ toPlainText(yDoc) {
59
+ return getText(yDoc).toString();
60
+ },
61
+ };
62
+ }
63
+ /**
64
+ * Rebuild a CollabContentAdapter from a serializable descriptor (produced by a
65
+ * host factory and shipped across the process boundary). Returns null for an
66
+ * unknown descriptor kind so callers can fall back gracefully.
67
+ */
68
+ export function reconstructCollabContentAdapterFromDescriptor(descriptor) {
69
+ if (descriptor.kind === 'text') {
70
+ return createTextCollabContentAdapter({
71
+ documentType: descriptor.documentType,
72
+ fileExtensions: descriptor.fileExtensions,
73
+ mimeType: descriptor.mimeType,
74
+ textField: descriptor.textField,
75
+ layoutVersion: descriptor.layoutVersion,
76
+ });
77
+ }
78
+ return null;
79
+ }
@@ -224,6 +224,16 @@ function generateCommonExports(externalKey) {
224
224
  else if (externalKey === '@nimbalyst/runtime/ui/icons/MaterialSymbol') {
225
225
  exports = ['MaterialSymbol'];
226
226
  }
227
+ else if (externalKey === '@nimbalyst/runtime') {
228
+ exports = [
229
+ 'MaterialSymbol', 'useDocumentPath', 'useEditorLifecycle',
230
+ 'useCollaborativeEditor', 'COLLAB_INIT_ORIGIN',
231
+ 'setTranscriptMarkdownContributions', 'clearTranscriptMarkdownContributions',
232
+ 'MarkdownEditor', 'MonacoEditor', 'MonacoCodeEditor',
233
+ 'TrackerReferenceChip', 'TrackerReferencePicker',
234
+ 'useResolvedTrackerReference', 'navigateToTrackerReference',
235
+ ];
236
+ }
227
237
  else if (externalKey === '@nimbalyst/screenshot-service') {
228
238
  exports = ['screenshotService'];
229
239
  }
@@ -0,0 +1,19 @@
1
+ export interface FileDirectoryNode<T> {
2
+ path: string;
3
+ displayPath: string;
4
+ files: T[];
5
+ subdirectories: Map<string, FileDirectoryNode<T>>;
6
+ fileCount: number;
7
+ }
8
+ /** Normalize filesystem separators for renderer-side path comparison and display. */
9
+ export declare function normalizeFilePath(filePath: string): string;
10
+ export declare function getFilePathBasename(filePath: string): string;
11
+ /**
12
+ * Return a forward-slash path relative to the workspace when the file is inside it.
13
+ * Windows drive paths are compared case-insensitively to match filesystem behavior.
14
+ */
15
+ export declare function getWorkspaceRelativeFilePath(filePath: string, workspacePath?: string): string;
16
+ /** Build a collapsed directory tree for arbitrary file records. */
17
+ export declare function buildFileDirectoryTree<T>(files: T[], getFilePath: (file: T) => string, workspacePath?: string): FileDirectoryNode<T>;
18
+ export declare function getFileDirectoryPaths<T>(node: FileDirectoryNode<T>): string[];
19
+ //# sourceMappingURL=fileDirectoryTree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileDirectoryTree.d.ts","sourceRoot":"","sources":["../src/fileDirectoryTree.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,CAAC,EAAE,CAAC;IACX,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAG5D;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,MAAM,CAkB7F;AA6BD,mEAAmE;AACnE,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,KAAK,EAAE,CAAC,EAAE,EACV,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAChC,aAAa,CAAC,EAAE,MAAM,GACrB,iBAAiB,CAAC,CAAC,CAAC,CAwCtB;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,MAAM,EAAE,CAM7E"}
@@ -0,0 +1,98 @@
1
+ /** Normalize filesystem separators for renderer-side path comparison and display. */
2
+ export function normalizeFilePath(filePath) {
3
+ return filePath.replace(/[\\/]+/g, '/');
4
+ }
5
+ export function getFilePathBasename(filePath) {
6
+ const normalizedPath = normalizeFilePath(filePath);
7
+ return normalizedPath.slice(normalizedPath.lastIndexOf('/') + 1);
8
+ }
9
+ /**
10
+ * Return a forward-slash path relative to the workspace when the file is inside it.
11
+ * Windows drive paths are compared case-insensitively to match filesystem behavior.
12
+ */
13
+ export function getWorkspaceRelativeFilePath(filePath, workspacePath) {
14
+ const normalizedFile = normalizeFilePath(filePath);
15
+ if (!workspacePath)
16
+ return normalizedFile;
17
+ const normalizedWorkspace = normalizeFilePath(workspacePath).replace(/\/$/, '');
18
+ const windowsDrivePath = /^[A-Za-z]:\//.test(normalizedFile)
19
+ && /^[A-Za-z]:\//.test(normalizedWorkspace);
20
+ const comparableFile = windowsDrivePath ? normalizedFile.toLowerCase() : normalizedFile;
21
+ const comparableWorkspace = windowsDrivePath
22
+ ? normalizedWorkspace.toLowerCase()
23
+ : normalizedWorkspace;
24
+ if (comparableFile === comparableWorkspace)
25
+ return '';
26
+ if (comparableFile.startsWith(`${comparableWorkspace}/`)) {
27
+ return normalizedFile.slice(normalizedWorkspace.length + 1);
28
+ }
29
+ return normalizedFile;
30
+ }
31
+ function collapseDirectoryTree(node) {
32
+ node.subdirectories.forEach((subdirectory, key) => {
33
+ node.subdirectories.set(key, collapseDirectoryTree(subdirectory));
34
+ });
35
+ if (node.subdirectories.size === 1 && node.files.length === 0) {
36
+ const childNode = node.subdirectories.values().next().value;
37
+ return {
38
+ ...childNode,
39
+ displayPath: node.displayPath
40
+ ? `${node.displayPath}/${childNode.displayPath}`
41
+ : childNode.displayPath,
42
+ };
43
+ }
44
+ return node;
45
+ }
46
+ function updateFileCounts(node) {
47
+ let count = node.files.length;
48
+ node.subdirectories.forEach(subdirectory => {
49
+ count += updateFileCounts(subdirectory);
50
+ });
51
+ node.fileCount = count;
52
+ return count;
53
+ }
54
+ /** Build a collapsed directory tree for arbitrary file records. */
55
+ export function buildFileDirectoryTree(files, getFilePath, workspacePath) {
56
+ const root = {
57
+ path: '',
58
+ displayPath: '',
59
+ files: [],
60
+ subdirectories: new Map(),
61
+ fileCount: 0,
62
+ };
63
+ files.forEach(file => {
64
+ const relativePath = getWorkspaceRelativeFilePath(getFilePath(file), workspacePath);
65
+ const parts = relativePath.split('/').filter(Boolean);
66
+ if (parts.length <= 1) {
67
+ root.files.push(file);
68
+ return;
69
+ }
70
+ let currentNode = root;
71
+ const directoryParts = parts.slice(0, -1);
72
+ directoryParts.forEach((part, index) => {
73
+ const path = directoryParts.slice(0, index + 1).join('/');
74
+ let childNode = currentNode.subdirectories.get(part);
75
+ if (!childNode) {
76
+ childNode = {
77
+ path,
78
+ displayPath: part,
79
+ files: [],
80
+ subdirectories: new Map(),
81
+ fileCount: 0,
82
+ };
83
+ currentNode.subdirectories.set(part, childNode);
84
+ }
85
+ currentNode = childNode;
86
+ });
87
+ currentNode.files.push(file);
88
+ });
89
+ updateFileCounts(root);
90
+ return collapseDirectoryTree(root);
91
+ }
92
+ export function getFileDirectoryPaths(node) {
93
+ const paths = node.path ? [node.path] : [];
94
+ node.subdirectories.forEach(subdirectory => {
95
+ paths.push(...getFileDirectoryPaths(subdirectory));
96
+ });
97
+ return paths;
98
+ }
package/dist/index.d.ts CHANGED
@@ -26,9 +26,14 @@ export { REQUIRED_EXTERNALS, EXTERNAL_PATTERNS, ROLLUP_EXTERNALS, type RequiredE
26
26
  export * from './types/index.js';
27
27
  export { useEditorLifecycle, type UseEditorLifecycleOptions, type UseEditorLifecycleResult, type DiffState, } from './useEditorLifecycle.js';
28
28
  export { useCollaborativeEditor, COLLAB_INIT_ORIGIN, type UseCollaborativeEditorConfig, type UseCollaborativeEditorResult, } from './useCollaborativeEditor.js';
29
+ export { createTextCollabContentAdapter, reconstructCollabContentAdapterFromDescriptor, TEXT_COLLAB_DEFAULT_FIELD, type TextCollabContentAdapterOptions, } from './collab/createTextCollabContentAdapter.js';
29
30
  export { useDocumentPath, type DocumentPathContextValue, } from './documentPath.js';
30
31
  export { MaterialSymbol } from './MaterialSymbol.js';
32
+ export { TrackerReferenceChip, TrackerReferencePicker, navigateToTrackerReference, useResolvedTrackerReference, type ResolvedTrackerReference, type TrackerReferenceChipProps, type TrackerReferencePickerProps, } from './trackerReferences.js';
31
33
  export { createReadOnlyHost, type ReadOnlyHost, type ReadOnlyHostOptions, } from './createReadOnlyHost.js';
32
34
  export { copyToClipboard, readClipboard } from './clipboard.js';
35
+ export { buildFileDirectoryTree, getFileDirectoryPaths, getFilePathBasename, getWorkspaceRelativeFilePath, normalizeFilePath, type FileDirectoryNode, } from './fileDirectoryTree.js';
33
36
  export { validateExtensionBundle, printValidationResult, type ValidationResult, } from './validate.js';
37
+ export { validateBackendModules, assertBackendModulesValid, effectiveModulePermissions, validateAgentProviders, assertAgentProvidersValid, extractBackendModuleIds, MAX_AGENT_PROVIDERS_PER_EXTENSION, type BackendModuleValidationIssue, type AgentProviderValidationIssue, } from './manifestValidation.js';
38
+ export type { AgentProtocol, ProtocolEvent, ProtocolMessage, ProtocolSession, SessionOptions, ProtocolEventType, ToolResult as ProtocolToolResult, MCPServerConfig, RawProtocolSession, AgentProtocolHost, PermissionMode, McpToolDefinition, } from './agents/index.js';
34
39
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,SAAS,GACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,KAAK,4BAA4B,EACjC,KAAK,4BAA4B,GAClC,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,eAAe,EACf,KAAK,wBAAwB,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EACL,kBAAkB,EAClB,KAAK,YAAY,EACjB,KAAK,mBAAmB,GACzB,MAAM,yBAAyB,CAAC;AAGjC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAO,EACL,uBAAuB,EACvB,qBAAqB,EACrB,KAAK,gBAAgB,GACtB,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,gBAAgB,GACtB,MAAM,gBAAgB,CAAC;AAGxB,cAAc,kBAAkB,CAAC;AAGjC,OAAO,EACL,kBAAkB,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AAI,kBAAkB,EAChC,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,GAClB,MAAM,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -29,12 +29,19 @@ export * from './types/index.js';
29
29
  // Re-export hooks
30
30
  export { useEditorLifecycle, } from './useEditorLifecycle.js';
31
31
  export { useCollaborativeEditor, COLLAB_INIT_ORIGIN, } from './useCollaborativeEditor.js';
32
+ export { createTextCollabContentAdapter, reconstructCollabContentAdapterFromDescriptor, TEXT_COLLAB_DEFAULT_FIELD, } from './collab/createTextCollabContentAdapter.js';
32
33
  // Re-export host-provided editor context and UI helpers for extensions.
33
34
  export { useDocumentPath, } from './documentPath.js';
34
35
  export { MaterialSymbol } from './MaterialSymbol.js';
36
+ // Re-export host-owned tracker reference UI. Extensions persist only reference
37
+ // keys while Nimbalyst owns live resolution, previews, selection, and opening.
38
+ export { TrackerReferenceChip, TrackerReferencePicker, navigateToTrackerReference, useResolvedTrackerReference, } from './trackerReferences.js';
35
39
  // Re-export read-only host factory (for web viewers and testing)
36
40
  export { createReadOnlyHost, } from './createReadOnlyHost.js';
37
41
  // Re-export clipboard utilities
38
42
  export { copyToClipboard, readClipboard } from './clipboard.js';
43
+ // Re-export cross-platform file tree utilities for host and extension UIs.
44
+ export { buildFileDirectoryTree, getFileDirectoryPaths, getFilePathBasename, getWorkspaceRelativeFilePath, normalizeFilePath, } from './fileDirectoryTree.js';
39
45
  // Re-export validation
40
46
  export { validateExtensionBundle, printValidationResult, } from './validate.js';
47
+ export { validateBackendModules, assertBackendModulesValid, effectiveModulePermissions, validateAgentProviders, assertAgentProvidersValid, extractBackendModuleIds, MAX_AGENT_PROVIDERS_PER_EXTENSION, } from './manifestValidation.js';