@sero-ai/app-runtime 0.1.3 → 0.2.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/LICENSE +201 -0
- package/package.json +9 -7
- package/src/app-launch.ts +94 -0
- package/src/context.ts +5 -0
- package/src/index.ts +10 -0
- package/src/sero-bridge.ts +24 -0
- package/src/use-agent-prompt.ts +2 -2
- package/src/use-ai.ts +2 -2
- package/src/use-app-info.ts +2 -2
- package/src/use-app-state.test.ts +56 -0
- package/src/use-app-state.ts +19 -3
- package/src/use-app-tools.ts +2 -2
- package/src/use-context-presets.ts +52 -0
- package/src/use-subagent-context.ts +59 -0
- package/src/use-theme.ts +5 -2
- package/src/use-widget-registration.ts +25 -19
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
https://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Dan Carter and contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
https://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sero-ai/app-runtime",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Hooks for Sero federated app modules — useAppState, useAppInfo, useAgentPrompt, useAppTools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -13,9 +13,6 @@
|
|
|
13
13
|
"src",
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
|
-
"scripts": {
|
|
17
|
-
"typecheck": "tsc --noEmit"
|
|
18
|
-
},
|
|
19
16
|
"publishConfig": {
|
|
20
17
|
"access": "public"
|
|
21
18
|
},
|
|
@@ -24,8 +21,13 @@
|
|
|
24
21
|
"react": "^19.2.4"
|
|
25
22
|
},
|
|
26
23
|
"devDependencies": {
|
|
27
|
-
"@sero-ai/common": "workspace:*",
|
|
28
24
|
"@types/react": "^19.2.13",
|
|
29
|
-
"typescript": "^5.9.3"
|
|
25
|
+
"typescript": "^5.9.3",
|
|
26
|
+
"vitest": "^4.1.7",
|
|
27
|
+
"@sero-ai/common": "0.7.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"typecheck": "tsc --noEmit",
|
|
31
|
+
"test": "vitest run"
|
|
30
32
|
}
|
|
31
|
-
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-app navigation — open another Sero app, optionally handing it launch
|
|
3
|
+
* params (e.g. the Scheduler app opening the Orchestrator on a specific loop).
|
|
4
|
+
*
|
|
5
|
+
* Only the active app is mounted, so the target app always mounts fresh and can
|
|
6
|
+
* consume its pending params in a state initializer. The registry is a
|
|
7
|
+
* globalThis singleton so all module-federation copies share it, matching the
|
|
8
|
+
* AppContext pattern.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { getSeroApi } from './sero-bridge';
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
var __sero_app_launch_params__: Map<string, Record<string, unknown>> | undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getRegistry(): Map<string, Record<string, unknown>> {
|
|
18
|
+
globalThis.__sero_app_launch_params__ ??= new Map();
|
|
19
|
+
return globalThis.__sero_app_launch_params__;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function launchEventName(appId: string): string {
|
|
23
|
+
return `sero:app-launch:${appId}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Switch the shell to another app. Optional `params` are held for the target
|
|
28
|
+
* app to pick up via `consumeAppLaunchParams` when it mounts. Resolves false
|
|
29
|
+
* when the app is unknown or the shell doesn't expose app control.
|
|
30
|
+
*/
|
|
31
|
+
export async function openSeroApp(appId: string, params?: Record<string, unknown>): Promise<boolean> {
|
|
32
|
+
if (params) getRegistry().set(appId, params);
|
|
33
|
+
const opened = (await getSeroApi().appControl?.open(appId)) ?? false;
|
|
34
|
+
if (!opened) getRegistry().delete(appId);
|
|
35
|
+
if (opened && params && typeof window !== 'undefined') {
|
|
36
|
+
window.dispatchEvent(new CustomEvent(launchEventName(appId), { detail: params }));
|
|
37
|
+
}
|
|
38
|
+
return opened;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Open a workspace file in the shell's explorer editor. Resolves false when the
|
|
43
|
+
* shell doesn't expose file opening. Used by search panels to make results
|
|
44
|
+
* clickable — `workspaceId` + `filePath` come straight from graph node tags.
|
|
45
|
+
* Opening a file does NOT close the search overlay; the panel decides that via
|
|
46
|
+
* `closeSeroSearch` so it can keep the overlay open for opening several files.
|
|
47
|
+
*/
|
|
48
|
+
export async function openSeroFile(workspaceId: string, filePath: string): Promise<boolean> {
|
|
49
|
+
return (await getSeroApi().appControl?.openFile(workspaceId, filePath)) ?? false;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Event the shell's global-search overlay listens for to dismiss itself. */
|
|
53
|
+
export const SERO_GLOBAL_SEARCH_CLOSE_EVENT = 'sero:global-search:close';
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Ask the shell to close the global-search overlay a search panel is mounted in.
|
|
57
|
+
* Uses a window event (same renderer as the host, like `openSeroApp`'s launch
|
|
58
|
+
* events) so panels stay decoupled from the host's store. No-op outside a window.
|
|
59
|
+
*/
|
|
60
|
+
export function closeSeroSearch(): void {
|
|
61
|
+
if (typeof window === 'undefined') return;
|
|
62
|
+
window.dispatchEvent(new CustomEvent(SERO_GLOBAL_SEARCH_CLOSE_EVENT));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Take (and clear) the launch params another app handed to `openSeroApp`.
|
|
67
|
+
* Call from a mount-time state initializer; returns undefined when the app
|
|
68
|
+
* was opened without params.
|
|
69
|
+
*/
|
|
70
|
+
export function consumeAppLaunchParams<T extends Record<string, unknown>>(appId: string): T | undefined {
|
|
71
|
+
const registry = getRegistry();
|
|
72
|
+
const params = registry.get(appId);
|
|
73
|
+
registry.delete(appId);
|
|
74
|
+
return params as T | undefined;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Receives launch params when an already-mounted app is opened again. Apps still
|
|
79
|
+
* consume the registry on mount; this covers same-app deep links without forcing
|
|
80
|
+
* an unnecessary unmount/remount.
|
|
81
|
+
*/
|
|
82
|
+
export function onAppLaunchParams<T extends Record<string, unknown>>(
|
|
83
|
+
appId: string,
|
|
84
|
+
callback: (params: T) => void,
|
|
85
|
+
): () => void {
|
|
86
|
+
if (typeof window === 'undefined') return () => {};
|
|
87
|
+
const listener = (event: Event) => {
|
|
88
|
+
getRegistry().delete(appId);
|
|
89
|
+
callback((event as CustomEvent<T>).detail);
|
|
90
|
+
};
|
|
91
|
+
const eventName = launchEventName(appId);
|
|
92
|
+
window.addEventListener(eventName, listener);
|
|
93
|
+
return () => window.removeEventListener(eventName, listener);
|
|
94
|
+
}
|
package/src/context.ts
CHANGED
|
@@ -27,6 +27,11 @@ export interface AppContextValue {
|
|
|
27
27
|
themeMode?: 'light' | 'dark';
|
|
28
28
|
/** Active theme preset ID. */
|
|
29
29
|
themePresetId?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Active editor/diff theme ID (`'auto'` follows `themeMode`). Plugins that
|
|
32
|
+
* render code or diffs use it so their syntax colours match the host editor.
|
|
33
|
+
*/
|
|
34
|
+
editorThemeId?: string;
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
declare global {
|
package/src/index.ts
CHANGED
|
@@ -12,8 +12,18 @@ export { useAgentPrompt } from './use-agent-prompt';
|
|
|
12
12
|
export { useAI, type AppAI } from './use-ai';
|
|
13
13
|
export { useAppTools, type AppTools } from './use-app-tools';
|
|
14
14
|
export { useAvailableModels, type UseAvailableModelsResult } from './use-available-models';
|
|
15
|
+
export { useSubagentContext, type UseSubagentContextResult } from './use-subagent-context';
|
|
16
|
+
export { useContextPresets, type UseContextPresetsResult } from './use-context-presets';
|
|
15
17
|
export { useTheme, type UseThemeResult } from './use-theme';
|
|
16
18
|
export { getSeroApi } from './sero-bridge';
|
|
19
|
+
export {
|
|
20
|
+
openSeroApp,
|
|
21
|
+
openSeroFile,
|
|
22
|
+
closeSeroSearch,
|
|
23
|
+
SERO_GLOBAL_SEARCH_CLOSE_EVENT,
|
|
24
|
+
consumeAppLaunchParams,
|
|
25
|
+
onAppLaunchParams,
|
|
26
|
+
} from './app-launch';
|
|
17
27
|
export type { AppModelInfo, AppModelGroup } from './sero-bridge';
|
|
18
28
|
export type { AppToolContentBlock, AppToolImageContent, AppToolResult, AppToolTextContent } from '@sero-ai/common';
|
|
19
29
|
export { registerWidget, getRuntimeWidgets, onWidgetRegistryChange } from './widget-registry';
|
package/src/sero-bridge.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
11
|
AppToolResult,
|
|
12
|
+
AvailableContext,
|
|
13
|
+
ContextPreset,
|
|
12
14
|
GitActionResult,
|
|
13
15
|
GitManagerRequest,
|
|
14
16
|
SharedAvailableModelGroup,
|
|
@@ -41,6 +43,13 @@ export interface SeroAppAgentBridge {
|
|
|
41
43
|
): Promise<AppToolResult>;
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
export interface SeroAppControlBridge {
|
|
47
|
+
/** Switch the shell to the app with this id. False when the app is unknown. */
|
|
48
|
+
open(appId: string): Promise<boolean>;
|
|
49
|
+
/** Open a workspace file in the explorer editor. False when unavailable. */
|
|
50
|
+
openFile(workspaceId: string, filePath: string): Promise<boolean>;
|
|
51
|
+
}
|
|
52
|
+
|
|
44
53
|
export interface SeroGitAppBridge {
|
|
45
54
|
run(workspaceId: string, params: GitManagerRequest): Promise<GitActionResult>;
|
|
46
55
|
}
|
|
@@ -71,13 +80,28 @@ export interface SeroModelsBridge {
|
|
|
71
80
|
list(): Promise<AppModelGroup[]>;
|
|
72
81
|
}
|
|
73
82
|
|
|
83
|
+
export interface SeroSubagentContextBridge {
|
|
84
|
+
/** Available context (tools + skills) for a workspace's background subagents, no session. */
|
|
85
|
+
get(workspaceId: string): Promise<AvailableContext>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface SeroContextPresetsBridge {
|
|
89
|
+
/** Load profile-level context presets. */
|
|
90
|
+
load(): Promise<ContextPreset[]>;
|
|
91
|
+
/** Persist the full preset list. */
|
|
92
|
+
save(presets: ContextPreset[]): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
|
|
74
95
|
export interface SeroBridge {
|
|
75
96
|
appState: SeroWindowAppStateBridge;
|
|
76
97
|
appAgent: SeroAppAgentBridge;
|
|
98
|
+
appControl?: SeroAppControlBridge;
|
|
77
99
|
gitApp?: SeroGitAppBridge;
|
|
78
100
|
webApp?: SeroWebAppBridge;
|
|
79
101
|
editor?: SeroEditorBridge;
|
|
80
102
|
models?: SeroModelsBridge;
|
|
103
|
+
subagentContext?: SeroSubagentContextBridge;
|
|
104
|
+
contextPresets?: SeroContextPresetsBridge;
|
|
81
105
|
}
|
|
82
106
|
|
|
83
107
|
function readWindowSero(value: Window): unknown {
|
package/src/use-agent-prompt.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* session IDs or storage details.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { use, useCallback } from 'react';
|
|
11
11
|
import { AppContext } from './context';
|
|
12
12
|
|
|
13
13
|
/**
|
|
@@ -18,7 +18,7 @@ import { AppContext } from './context';
|
|
|
18
18
|
* prompt("Add a todo: buy milk");
|
|
19
19
|
*/
|
|
20
20
|
export function useAgentPrompt(): (text: string) => void {
|
|
21
|
-
const ctx =
|
|
21
|
+
const ctx = use(AppContext);
|
|
22
22
|
|
|
23
23
|
return useCallback(
|
|
24
24
|
(text: string) => {
|
package/src/use-ai.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* const response = await ai.prompt("Generate an inspirational quote.");
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { use, useCallback, useMemo } from 'react';
|
|
15
15
|
import { AppContext } from './context';
|
|
16
16
|
import { getSeroApi } from './sero-bridge';
|
|
17
17
|
|
|
@@ -23,7 +23,7 @@ export interface AppAI {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
export function useAI(): AppAI {
|
|
26
|
-
const ctx =
|
|
26
|
+
const ctx = use(AppContext);
|
|
27
27
|
|
|
28
28
|
const prompt = useCallback(
|
|
29
29
|
async (text: string): Promise<string> => {
|
package/src/use-app-info.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* useAppInfo — read-only context about the current app and workspace.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { use } from 'react';
|
|
6
6
|
import { AppContext } from './context';
|
|
7
7
|
|
|
8
8
|
export interface AppInfo {
|
|
@@ -12,7 +12,7 @@ export interface AppInfo {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export function useAppInfo(): AppInfo {
|
|
15
|
-
const ctx =
|
|
15
|
+
const ctx = use(AppContext);
|
|
16
16
|
if (!ctx) {
|
|
17
17
|
throw new Error('useAppInfo must be used inside an <AppProvider>');
|
|
18
18
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { applyDefaultState } from './use-app-state';
|
|
4
|
+
|
|
5
|
+
interface DemoState {
|
|
6
|
+
name: string;
|
|
7
|
+
count: number;
|
|
8
|
+
tags: string[];
|
|
9
|
+
nested: { open: boolean };
|
|
10
|
+
optional?: { from: string };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DEFAULT_STATE: DemoState = {
|
|
14
|
+
name: '',
|
|
15
|
+
count: 0,
|
|
16
|
+
tags: [],
|
|
17
|
+
nested: { open: false },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe('applyDefaultState', () => {
|
|
21
|
+
it('takes the file’s values over the defaults', () => {
|
|
22
|
+
expect(applyDefaultState(DEFAULT_STATE, {
|
|
23
|
+
name: 'repo',
|
|
24
|
+
count: 3,
|
|
25
|
+
tags: ['a'],
|
|
26
|
+
nested: { open: true },
|
|
27
|
+
})).toEqual({ name: 'repo', count: 3, tags: ['a'], nested: { open: true } });
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('keeps the default where the file disagrees about the type', () => {
|
|
31
|
+
const merged = applyDefaultState(DEFAULT_STATE, { name: 42, tags: 'nope' });
|
|
32
|
+
expect(merged.name).toBe('');
|
|
33
|
+
expect(merged.tags).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('fills in what the file leaves out', () => {
|
|
37
|
+
expect(applyDefaultState(DEFAULT_STATE, { name: 'repo' }).count).toBe(0);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// An `undefined` default says the field is optional, not that it must be
|
|
41
|
+
// absent. Enforcing it dropped the file's value on every read, which is how
|
|
42
|
+
// a whole feature's state could be written correctly and never arrive.
|
|
43
|
+
it('passes optional fields through when the default is undefined', () => {
|
|
44
|
+
const withOptional: DemoState = { ...DEFAULT_STATE, optional: undefined };
|
|
45
|
+
|
|
46
|
+
expect(applyDefaultState(withOptional, {
|
|
47
|
+
name: 'repo',
|
|
48
|
+
optional: { from: 'the file' },
|
|
49
|
+
}).optional).toEqual({ from: 'the file' });
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('leaves an absent optional field absent', () => {
|
|
53
|
+
const withOptional: DemoState = { ...DEFAULT_STATE, optional: undefined };
|
|
54
|
+
expect(applyDefaultState(withOptional, { name: 'repo' }).optional).toBeUndefined();
|
|
55
|
+
});
|
|
56
|
+
});
|
package/src/use-app-state.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* 3. Writes via IPC (atomic file write → watcher fires → all consumers update)
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { useState, useEffect, useCallback,
|
|
9
|
+
import { useState, useEffect, useCallback, use, useRef } from 'react';
|
|
10
10
|
import { AppContext } from './context';
|
|
11
11
|
import { getSeroApi, type SeroWindowAppStateBridge } from './sero-bridge';
|
|
12
12
|
|
|
@@ -20,7 +20,19 @@ function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
|
20
20
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* The state file is merged over the app's default state key by key, and the
|
|
25
|
+
* default wins wherever the two disagree in type — a malformed file cannot
|
|
26
|
+
* hand an app a number where it expects a string.
|
|
27
|
+
*
|
|
28
|
+
* An `undefined` default is the exception: it says the field is optional, not
|
|
29
|
+
* that it must be absent. Enforcing it would drop the file's value on every
|
|
30
|
+
* read, which is exactly what used to happen to any optional field an app
|
|
31
|
+
* declared as `undefined` in its default state.
|
|
32
|
+
*/
|
|
23
33
|
function normalizeStateValue(defaultValue: unknown, currentValue: unknown): unknown {
|
|
34
|
+
if (defaultValue === undefined) return currentValue;
|
|
35
|
+
|
|
24
36
|
if (Array.isArray(defaultValue)) {
|
|
25
37
|
return Array.isArray(currentValue) ? currentValue : defaultValue;
|
|
26
38
|
}
|
|
@@ -39,12 +51,16 @@ function normalizeStateValue(defaultValue: unknown, currentValue: unknown): unkn
|
|
|
39
51
|
return typeof currentValue === typeof defaultValue ? currentValue : defaultValue;
|
|
40
52
|
}
|
|
41
53
|
|
|
42
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Merge a state file's contents over an app's default state. Exported for its
|
|
56
|
+
* tests, not from the package entry point — it is not public API.
|
|
57
|
+
*/
|
|
58
|
+
export function applyDefaultState<T>(defaultState: T, current: unknown): T {
|
|
43
59
|
return normalizeStateValue(defaultState, current) as T;
|
|
44
60
|
}
|
|
45
61
|
|
|
46
62
|
export function useAppState<T>(defaultState: T): [T, (updater: (prev: T) => T) => void] {
|
|
47
|
-
const ctx =
|
|
63
|
+
const ctx = use(AppContext);
|
|
48
64
|
if (!ctx) {
|
|
49
65
|
throw new Error('useAppState must be used inside an <AppProvider>');
|
|
50
66
|
}
|
package/src/use-app-tools.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AppToolResult } from '@sero-ai/common';
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, use, useMemo } from 'react';
|
|
3
3
|
|
|
4
4
|
import { AppContext } from './context';
|
|
5
5
|
import { getSeroApi } from './sero-bridge';
|
|
@@ -9,7 +9,7 @@ export interface AppTools {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export function useAppTools(): AppTools {
|
|
12
|
-
const ctx =
|
|
12
|
+
const ctx = use(AppContext);
|
|
13
13
|
|
|
14
14
|
const run = useCallback<AppTools['run']>(
|
|
15
15
|
async (toolName, params): Promise<AppToolResult> => {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useContextPresets — loads and persists profile-level context-editor presets,
|
|
3
|
+
* the same store the chat session editor uses. Lets app modules reuse a user's
|
|
4
|
+
* saved contexts.
|
|
5
|
+
*
|
|
6
|
+
* Returns { presets, save, loading, error }.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
10
|
+
import type { ContextPreset } from '@sero-ai/common';
|
|
11
|
+
import { getSeroApi } from './sero-bridge';
|
|
12
|
+
|
|
13
|
+
export interface UseContextPresetsResult {
|
|
14
|
+
presets: ContextPreset[];
|
|
15
|
+
/** Persist a new full preset list and update local state. */
|
|
16
|
+
save: (next: ContextPreset[]) => Promise<void>;
|
|
17
|
+
loading: boolean;
|
|
18
|
+
error: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function useContextPresets(): UseContextPresetsResult {
|
|
22
|
+
const [presets, setPresets] = useState<ContextPreset[]>([]);
|
|
23
|
+
const [loading, setLoading] = useState(true);
|
|
24
|
+
const [error, setError] = useState<string | null>(null);
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const api = getSeroApi();
|
|
28
|
+
if (!api.contextPresets) {
|
|
29
|
+
setError('Context presets not available in this Sero version');
|
|
30
|
+
setLoading(false);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
api.contextPresets
|
|
34
|
+
.load()
|
|
35
|
+
.then(setPresets)
|
|
36
|
+
.catch((err: unknown) => setError(err instanceof Error ? err.message : 'Failed to load presets'))
|
|
37
|
+
.finally(() => setLoading(false));
|
|
38
|
+
}, []);
|
|
39
|
+
|
|
40
|
+
const save = useCallback(async (next: ContextPreset[]) => {
|
|
41
|
+
setPresets(next);
|
|
42
|
+
const api = getSeroApi();
|
|
43
|
+
if (!api.contextPresets) return;
|
|
44
|
+
try {
|
|
45
|
+
await api.contextPresets.save(next);
|
|
46
|
+
} catch (err) {
|
|
47
|
+
setError(err instanceof Error ? err.message : 'Failed to save presets');
|
|
48
|
+
}
|
|
49
|
+
}, []);
|
|
50
|
+
|
|
51
|
+
return { presets, save, loading, error };
|
|
52
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useSubagentContext — fetches the available context (tools + skills) for a
|
|
3
|
+
* workspace's background subagents, without an agent session. Lets app modules
|
|
4
|
+
* (e.g. the Orchestrator loop context override) offer tool/skill toggles.
|
|
5
|
+
*
|
|
6
|
+
* Returns { context, loading, error, refresh }.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
10
|
+
import type { AvailableContext } from '@sero-ai/common';
|
|
11
|
+
import { getSeroApi } from './sero-bridge';
|
|
12
|
+
|
|
13
|
+
export interface UseSubagentContextResult {
|
|
14
|
+
context: AvailableContext | null;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
error: string | null;
|
|
17
|
+
refresh: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useSubagentContext(workspaceId: string | null): UseSubagentContextResult {
|
|
21
|
+
const [context, setContext] = useState<AvailableContext | null>(null);
|
|
22
|
+
const [loading, setLoading] = useState(false);
|
|
23
|
+
const [error, setError] = useState<string | null>(null);
|
|
24
|
+
|
|
25
|
+
const fetch = useCallback(() => {
|
|
26
|
+
if (!workspaceId) {
|
|
27
|
+
setContext(null);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
setLoading(true);
|
|
31
|
+
setError(null);
|
|
32
|
+
|
|
33
|
+
const api = getSeroApi();
|
|
34
|
+
if (!api.subagentContext) {
|
|
35
|
+
setError('Subagent context not available in this Sero version');
|
|
36
|
+
setLoading(false);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
api.subagentContext
|
|
41
|
+
.get(workspaceId)
|
|
42
|
+
.then((result) => {
|
|
43
|
+
setContext(result);
|
|
44
|
+
setError(null);
|
|
45
|
+
})
|
|
46
|
+
.catch((err: unknown) => {
|
|
47
|
+
setError(err instanceof Error ? err.message : 'Failed to fetch context');
|
|
48
|
+
})
|
|
49
|
+
.finally(() => {
|
|
50
|
+
setLoading(false);
|
|
51
|
+
});
|
|
52
|
+
}, [workspaceId]);
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
fetch();
|
|
56
|
+
}, [fetch]);
|
|
57
|
+
|
|
58
|
+
return { context, loading, error, refresh: fetch };
|
|
59
|
+
}
|
package/src/use-theme.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* canvas rendering, charts, or conditional logic).
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { use } from 'react';
|
|
10
10
|
import { AppContext } from './context';
|
|
11
11
|
|
|
12
12
|
export interface UseThemeResult {
|
|
@@ -14,12 +14,15 @@ export interface UseThemeResult {
|
|
|
14
14
|
mode: 'light' | 'dark';
|
|
15
15
|
/** Active theme preset ID. */
|
|
16
16
|
presetId: string;
|
|
17
|
+
/** Active editor/diff theme ID; `'auto'` follows `mode`. */
|
|
18
|
+
editorThemeId: string;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export function useTheme(): UseThemeResult {
|
|
20
|
-
const ctx =
|
|
22
|
+
const ctx = use(AppContext);
|
|
21
23
|
return {
|
|
22
24
|
mode: ctx?.themeMode ?? 'dark',
|
|
23
25
|
presetId: ctx?.themePresetId ?? 'default',
|
|
26
|
+
editorThemeId: ctx?.editorThemeId ?? 'auto',
|
|
24
27
|
};
|
|
25
28
|
}
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
* ```
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
import {
|
|
24
|
+
import { use, useEffect } from 'react';
|
|
25
25
|
import type { ComponentType } from 'react';
|
|
26
26
|
import { AppContext } from './context';
|
|
27
27
|
import { registerWidget } from './widget-registry';
|
|
@@ -50,8 +50,14 @@ interface WidgetRegistrationOptions {
|
|
|
50
50
|
* dashboard widget can keep rendering after the full app view unmounts.
|
|
51
51
|
*/
|
|
52
52
|
export function useWidgetRegistration(options: WidgetRegistrationOptions): void {
|
|
53
|
-
const ctx =
|
|
53
|
+
const ctx = use(AppContext);
|
|
54
54
|
const appId = ctx?.appId;
|
|
55
|
+
const { component, defaultSize, description, maxSize, minSize, name, widgetId } = options;
|
|
56
|
+
const { h: defaultHeight, w: defaultWidth } = defaultSize;
|
|
57
|
+
const minHeight = minSize?.h;
|
|
58
|
+
const minWidth = minSize?.w;
|
|
59
|
+
const maxHeight = maxSize?.h;
|
|
60
|
+
const maxWidth = maxSize?.w;
|
|
55
61
|
|
|
56
62
|
// Acceptable useEffect — registration into a shared external registry
|
|
57
63
|
useEffect(() => {
|
|
@@ -59,25 +65,25 @@ export function useWidgetRegistration(options: WidgetRegistrationOptions): void
|
|
|
59
65
|
|
|
60
66
|
registerWidget({
|
|
61
67
|
appId,
|
|
62
|
-
widgetId
|
|
63
|
-
name
|
|
64
|
-
component
|
|
65
|
-
defaultSize:
|
|
66
|
-
minSize:
|
|
67
|
-
maxSize:
|
|
68
|
-
description
|
|
68
|
+
widgetId,
|
|
69
|
+
name,
|
|
70
|
+
component,
|
|
71
|
+
defaultSize: { w: defaultWidth, h: defaultHeight },
|
|
72
|
+
minSize: minWidth === undefined || minHeight === undefined ? undefined : { w: minWidth, h: minHeight },
|
|
73
|
+
maxSize: maxWidth === undefined || maxHeight === undefined ? undefined : { w: maxWidth, h: maxHeight },
|
|
74
|
+
description,
|
|
69
75
|
});
|
|
70
76
|
}, [
|
|
71
77
|
appId,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
widgetId,
|
|
79
|
+
name,
|
|
80
|
+
component,
|
|
81
|
+
defaultHeight,
|
|
82
|
+
defaultWidth,
|
|
83
|
+
minHeight,
|
|
84
|
+
minWidth,
|
|
85
|
+
maxHeight,
|
|
86
|
+
maxWidth,
|
|
87
|
+
description,
|
|
82
88
|
]);
|
|
83
89
|
}
|