@cognite/cli 1.1.0-alpha.50 → 1.1.0-alpha.51
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.md +6 -0
- package/README.md +12 -0
- package/_templates/app/new/config/vitest.config.ts.ejs.t +5 -0
- package/_templates/app/new/root/AGENTS.md.ejs.t +77 -6
- package/_templates/app/new/root/gitignore.ejs.t +1 -0
- package/_templates/app/new/root/package.json.ejs.t +4 -2
- package/_templates/app/new/src/App.test.tsx.ejs.t +37 -11
- package/_templates/app/new/src/App.tsx.ejs.t +46 -64
- package/dist/{chunk-HE6P4LDC.js → chunk-3MRP5PCT.js} +6 -6
- package/dist/chunk-VTE66IK5.js +8 -0
- package/dist/cli/cli.js +90 -86
- package/dist/deploy/index.d.ts +3 -0
- package/dist/deploy/index.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{skills-GQ5TZKCM.js → skills-SV7BPHAZ.js} +1 -1
- package/package.json +3 -3
- package/dist/chunk-A5ASLC6T.js +0 -7
package/LICENSE.md
ADDED
package/README.md
CHANGED
|
@@ -47,6 +47,18 @@ Browse available skills at [cognitedata/builder-skills](https://github.com/cogni
|
|
|
47
47
|
- Node.js ≥ 20
|
|
48
48
|
- React ≥ 18 (optional peer dependency — only needed for auth components)
|
|
49
49
|
|
|
50
|
+
## Telemetry
|
|
51
|
+
|
|
52
|
+
`@cognite/cli` collects anonymous usage data (commands run, success/failure, CLI and Node.js versions) to help improve the tool.
|
|
53
|
+
|
|
54
|
+
To opt out:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
export COGNITE_TELEMETRY_DISABLED=1
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`DO_NOT_TRACK=1` is also honoured.
|
|
61
|
+
|
|
50
62
|
## Development
|
|
51
63
|
|
|
52
64
|
### Running tests
|
|
@@ -10,5 +10,10 @@ export default defineConfig({
|
|
|
10
10
|
globals: true,
|
|
11
11
|
environment: 'happy-dom',
|
|
12
12
|
setupFiles: ['vitest.setup.ts'],
|
|
13
|
+
coverage: {
|
|
14
|
+
provider: 'v8',
|
|
15
|
+
reporter: ['text', 'json', 'html', 'lcov'],
|
|
16
|
+
exclude: ['node_modules/', 'dist/', 'vitest.setup.ts', '**/*.config.ts', '**/*.d.ts'],
|
|
17
|
+
},
|
|
13
18
|
},
|
|
14
19
|
});
|
|
@@ -28,7 +28,54 @@ Always check `@cognite/aura/components` before reaching for a raw HTML element o
|
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
31
|
-
## 2.
|
|
31
|
+
## 2. Host integration (`@cognite/app-sdk`)
|
|
32
|
+
|
|
33
|
+
The Fusion host exposes a `HostAppAPI` (imported as `HostAppAPI` from `@cognite/app-sdk`) via `connectToHostApp(...)`. Reach for it whenever the situation calls for it — don't hand-roll an equivalent or read browser globals directly.
|
|
34
|
+
|
|
35
|
+
### Decision rule for any new piece of state
|
|
36
|
+
|
|
37
|
+
Before adding `useState`, `useReducer`, or a store entry, ask: **"would a user expect this to survive a page reload, or to be restored when someone opens a shared link?"** If yes, it belongs in `syncInternalState` + `initialState`, **not** in plain React state.
|
|
38
|
+
|
|
39
|
+
- **Yes, host-synced:** current page / active view / route, selected tab, active filters, selected resource id, search query, sort order, expanded rows, focused row, side-panel open/closed — anything that drives what the user sees.
|
|
40
|
+
- **No, local-only:** in-flight form input before submit, hover/focus, transient toasts, animation state, optimistic UI mid-flight.
|
|
41
|
+
|
|
42
|
+
When in doubt, host-synced is the safer default — over-syncing is cheap, under-syncing breaks reload and share.
|
|
43
|
+
|
|
44
|
+
### API surface
|
|
45
|
+
|
|
46
|
+
- **Host-synced UI state** → on startup, seed your state from the `initialState` string returned by `connectToHostApp`. On every change, call `api.syncInternalState(JSON.stringify(state))`. The host serializes this into the URL so reloads and shared links restore the same state. **Do not** hold state from the "host-synced" category above in plain `useState` / `useRef` / a local store.
|
|
47
|
+
- **Navigating elsewhere in Fusion** (another app, a Fusion route) → `api.navigateInternal({ path, queryParams, hash })`. Never set `window.location` directly.
|
|
48
|
+
- **Navigating to an external URL** → `api.navigateExternal({ url, openInNewTab })`. Only `https:` is allowed.
|
|
49
|
+
- **Needing a CDF base URL or access token** for API requests → `api.getBaseUrl()` / `api.getAccessToken()`. Never hardcode the cluster URL.
|
|
50
|
+
- **Needing the current CDF project name** → `api.getProject()`. Don't read it from config or URL params.
|
|
51
|
+
- **Exposing the app's capabilities to a Fusion agent** → register a custom agent server with `api.registerAgentServer(handle)` and clean up on unmount with `api.unregisterAgentServer(uri)`.
|
|
52
|
+
|
|
53
|
+
Get `api` once at app startup and surface it to the rest of the app via React context so view models can depend on it through the patterns below.
|
|
54
|
+
|
|
55
|
+
### Round-trip example: host-synced state
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { connectToHostApp, type HostAppAPI } from '@cognite/app-sdk';
|
|
59
|
+
|
|
60
|
+
type AppState = { page: 'a' | 'b'; filters: string[] };
|
|
61
|
+
const DEFAULT_STATE: AppState = { page: 'a', filters: [] };
|
|
62
|
+
|
|
63
|
+
// On startup — seed from initialState, not from a hardcoded default.
|
|
64
|
+
const { api, initialState } = await connectToHostApp({ applicationName: '<%= name %>' });
|
|
65
|
+
const seeded: AppState = initialState ? (JSON.parse(initialState) as AppState) : DEFAULT_STATE;
|
|
66
|
+
|
|
67
|
+
// On every change — push the new state to the host so the URL stays in sync.
|
|
68
|
+
async function updateState(next: AppState, api: HostAppAPI) {
|
|
69
|
+
setState(next); // your local React/store setter
|
|
70
|
+
await api.syncInternalState(JSON.stringify(next));
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
`initialState` is the JSON string the host extracted from the URL on this load — the host owns the URL plumbing, the app just reads/writes the string.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## 3. Dependency Injection
|
|
32
79
|
|
|
33
80
|
Inject dependencies via React context (hooks/components) or factory-override pattern (plain functions). Never hard-code dependencies.
|
|
34
81
|
|
|
@@ -57,7 +104,7 @@ export const doWork = async (props: Props, overrides?: Partial<Deps>) => {
|
|
|
57
104
|
|
|
58
105
|
---
|
|
59
106
|
|
|
60
|
-
##
|
|
107
|
+
## 4. Interface-Based Services
|
|
61
108
|
|
|
62
109
|
Define an interface; implement with a class. Never reference the concrete class outside its own file.
|
|
63
110
|
|
|
@@ -74,7 +121,7 @@ export class ApiDataService implements DataService {
|
|
|
74
121
|
|
|
75
122
|
---
|
|
76
123
|
|
|
77
|
-
##
|
|
124
|
+
## 5. ViewModel Pattern
|
|
78
125
|
|
|
79
126
|
Business logic lives in `use<Name>ViewModel`. Components only render.
|
|
80
127
|
|
|
@@ -95,9 +142,26 @@ export const TodoView = () => {
|
|
|
95
142
|
};
|
|
96
143
|
```
|
|
97
144
|
|
|
145
|
+
### Where state lives
|
|
146
|
+
|
|
147
|
+
A ViewModel hook must **not** hold state with `useState` / `useReducer` directly. State lives in a shared storage layer — a context-backed hook (like `useTodoStorage` above), a store, or a `*StateProvider` rendered once near the root of the view tree. The ViewModel composes that storage with commands and derivations; it is itself stateless.
|
|
148
|
+
|
|
149
|
+
This matters because each call to a `useState`-backed hook creates an **independent** piece of React state. Two components calling the same ViewModel hook would each get their own copy and never sync.
|
|
150
|
+
|
|
151
|
+
> ⚠️ Anti-pattern: `useState` inside `useFooViewModel`, then two sibling components each call `useFooViewModel()`. Clicks update one copy; the other renders stale data.
|
|
152
|
+
|
|
153
|
+
### How many times to call a ViewModel hook
|
|
154
|
+
|
|
155
|
+
- **Backed by shared context / store** → multiple components may call the hook; they all observe the same value. This is the default for non-trivial views.
|
|
156
|
+
- **Not backed by shared state** → call the hook **once** at the top of the view tree and pass values down as props. Never call it twice and expect them to stay in sync.
|
|
157
|
+
|
|
158
|
+
### Host-synced state inside a ViewModel
|
|
159
|
+
|
|
160
|
+
When a ViewModel exposes state that falls under §2's "host-synced" category, the **ViewModel** — not the view component — is responsible for seeding from `initialState` and pushing changes via `syncInternalState`. The state itself still lives in the shared storage layer described above; the ViewModel just owns the read/write contract with the host.
|
|
161
|
+
|
|
98
162
|
---
|
|
99
163
|
|
|
100
|
-
##
|
|
164
|
+
## 6. Test-First Development
|
|
101
165
|
|
|
102
166
|
Write tests before implementation for all non-trivial behavior changes.
|
|
103
167
|
|
|
@@ -193,7 +257,7 @@ Place reusable factories in `src/__mocks__/`. Use `.test` TLD for fake URLs (RFC
|
|
|
193
257
|
|
|
194
258
|
---
|
|
195
259
|
|
|
196
|
-
##
|
|
260
|
+
## 7. TypeScript Rules
|
|
197
261
|
|
|
198
262
|
- Never use `any`; prefer `unknown` or explicit strong types
|
|
199
263
|
- Never use `as unknown as T`; for partial test doubles use `{ ...defaults, ...overrides } as T`
|
|
@@ -207,7 +271,14 @@ function createMockWindow(overrides: Partial<Window> = {}): Window {
|
|
|
207
271
|
|
|
208
272
|
---
|
|
209
273
|
|
|
210
|
-
## 7.
|
|
274
|
+
## 7. CogniteClient / authentication
|
|
275
|
+
|
|
276
|
+
Auth is handled by `CogniteSdkProvider` from `@cognite/app-sdk/react` (see `App.tsx`). Nested components get the client via `useCogniteSdk()`. To wire up or migrate auth, run the `/setup-flows-auth` skill.
|
|
277
|
+
|
|
278
|
+
---
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
## 8. Commits and pull requests
|
|
211
282
|
|
|
212
283
|
Use [Conventional Commits v1.0.0](https://www.conventionalcommits.org/en/v1.0.0/).
|
|
213
284
|
|
|
@@ -18,6 +18,7 @@ to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>package.json'
|
|
|
18
18
|
"test": "vitest run",
|
|
19
19
|
"test:watch": "vitest",
|
|
20
20
|
"test:ui": "vitest --ui",
|
|
21
|
+
"test:coverage": "vitest run --coverage",
|
|
21
22
|
"lint": "eslint . --ext .js,.mjs,.cjs,.ts,.tsx",
|
|
22
23
|
"lint:fix": "eslint . --fix --ext .js,.mjs,.cjs,.ts,.tsx",
|
|
23
24
|
"deploy": "npx @cognite/cli@latest apps deploy --interactive",
|
|
@@ -26,8 +27,8 @@ to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>package.json'
|
|
|
26
27
|
"dependencies": {
|
|
27
28
|
"@cognite/aura": "^0.1.7",
|
|
28
29
|
"@cognite/sdk": "^10.3.0",
|
|
29
|
-
"@cognite/cli": "1.1.0-alpha.
|
|
30
|
-
"@cognite/app-sdk": "^0.
|
|
30
|
+
"@cognite/cli": "1.1.0-alpha.51",
|
|
31
|
+
"@cognite/app-sdk": "^0.5.1",
|
|
31
32
|
"@tabler/icons-react": "^3.35.0",
|
|
32
33
|
"@tanstack/react-query": "^5.90.10",
|
|
33
34
|
"clsx": "^2.1.1",
|
|
@@ -47,6 +48,7 @@ to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>package.json'
|
|
|
47
48
|
"@types/react": "^18.3.1",
|
|
48
49
|
"@types/react-dom": "^18.3.1",
|
|
49
50
|
"@vitejs/plugin-react": "^5.1.1",
|
|
51
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
50
52
|
"@vitest/ui": "^2.1.8",
|
|
51
53
|
"autoprefixer": "^10.4.22",
|
|
52
54
|
"eslint": "9.39.4",
|
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
---
|
|
2
2
|
to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>src/App.test.tsx'
|
|
3
3
|
---
|
|
4
|
-
import * as appSdk from '@cognite/app-sdk';
|
|
5
4
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
6
5
|
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
6
|
+
import type { HostAppAPI, ConnectToHostAppResult } from '@cognite/app-sdk';
|
|
7
|
+
import { CogniteClient } from '@cognite/sdk';
|
|
8
|
+
import type { ComponentProps } from 'react';
|
|
7
9
|
|
|
8
10
|
import App from './App';
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
type AppDeps = NonNullable<ComponentProps<typeof App>['deps']>;
|
|
13
|
+
|
|
14
|
+
function makeApi(): HostAppAPI {
|
|
15
|
+
return {
|
|
16
|
+
getProject: vi.fn<HostAppAPI['getProject']>(() => Promise.resolve('<%= project %>')),
|
|
17
|
+
getBaseUrl: vi.fn<HostAppAPI['getBaseUrl']>(() => Promise.resolve('https://cognite.test')),
|
|
18
|
+
getAccessToken: vi.fn<HostAppAPI['getAccessToken']>(() => Promise.resolve('test-token')),
|
|
19
|
+
getAppId: vi.fn<HostAppAPI['getAppId']>(() => Promise.resolve('test-app-id')),
|
|
20
|
+
syncInternalState: vi.fn<HostAppAPI['syncInternalState']>(() => Promise.resolve(true)),
|
|
21
|
+
navigateInternal: vi.fn<HostAppAPI['navigateInternal']>(() => Promise.resolve(true)),
|
|
22
|
+
navigateExternal: vi.fn<HostAppAPI['navigateExternal']>(() => Promise.resolve(true)),
|
|
23
|
+
registerAgentServer: vi.fn<HostAppAPI['registerAgentServer']>(() => Promise.resolve()),
|
|
24
|
+
unregisterAgentServer: vi.fn<HostAppAPI['unregisterAgentServer']>(() => Promise.resolve()),
|
|
25
|
+
sendAgentLayoutMode: vi.fn<HostAppAPI['sendAgentLayoutMode']>(() => Promise.resolve()),
|
|
26
|
+
sendAgentMessage: vi.fn<HostAppAPI['sendAgentMessage']>(() => Promise.resolve()),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function makeLoadingDeps(): AppDeps {
|
|
31
|
+
return {
|
|
32
|
+
connectToHostApp: vi.fn<AppDeps['connectToHostApp']>(() => new Promise<ConnectToHostAppResult>(() => undefined)),
|
|
33
|
+
createClient: vi.fn<AppDeps['createClient']>((config) => new CogniteClient(config)),
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function makeConnectedDeps(): AppDeps {
|
|
38
|
+
return {
|
|
39
|
+
connectToHostApp: vi.fn<AppDeps['connectToHostApp']>(() => Promise.resolve({ api: makeApi() })),
|
|
40
|
+
createClient: vi.fn<AppDeps['createClient']>((config) => new CogniteClient(config)),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
11
43
|
|
|
12
44
|
describe('App', () => {
|
|
13
45
|
beforeEach(() => {
|
|
@@ -15,19 +47,13 @@ describe('App', () => {
|
|
|
15
47
|
});
|
|
16
48
|
|
|
17
49
|
it('renders loading state', () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
render(<App />);
|
|
50
|
+
render(<App deps={makeLoadingDeps()} />);
|
|
21
51
|
expect(screen.getByText('Loading project...')).toBeInTheDocument();
|
|
22
52
|
});
|
|
23
53
|
|
|
24
54
|
it('renders splash with deployment targets and checklist copy', async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
render(<App />);
|
|
30
|
-
await waitFor(() => expect(screen.getByText('Welcome to Flows')).toBeInTheDocument());
|
|
55
|
+
render(<App deps={makeConnectedDeps()} />);
|
|
56
|
+
await waitFor(() => expect(screen.getByText('Welcome to Flows custom apps')).toBeInTheDocument());
|
|
31
57
|
expect(screen.getByText('App deployment checklist')).toBeInTheDocument();
|
|
32
58
|
expect(screen.getByText('Plan')).toBeInTheDocument();
|
|
33
59
|
expect(screen.getByText('Explore')).toBeInTheDocument();
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
---
|
|
2
2
|
to: '<%= useCurrentDir ? "" : ((directoryName || name) + "/") %>src/App.tsx'
|
|
3
3
|
---
|
|
4
|
-
import {
|
|
4
|
+
import type { ComponentProps } from 'react';
|
|
5
|
+
import { CogniteSdkProvider, useCogniteSdk } from '@cognite/app-sdk/react';
|
|
5
6
|
import {
|
|
6
7
|
Alert,
|
|
7
8
|
AlertDescription,
|
|
@@ -18,7 +19,6 @@ import {
|
|
|
18
19
|
Separator,
|
|
19
20
|
} from '@cognite/aura/components';
|
|
20
21
|
import { IconCaretUpDown, IconRocket } from '@tabler/icons-react';
|
|
21
|
-
import { useEffect, useState } from 'react';
|
|
22
22
|
|
|
23
23
|
import appConfig from '../app.json';
|
|
24
24
|
|
|
@@ -62,71 +62,41 @@ const CHECKLIST_STEPS = [
|
|
|
62
62
|
},
|
|
63
63
|
] as const;
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
<main className="min-h-screen bg-muted/50 text-foreground">
|
|
97
|
-
<section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
|
|
98
|
-
<div className="mx-auto w-full max-w-sm">
|
|
99
|
-
<Card aria-label="Loading project" aria-live="polite">
|
|
100
|
-
<CardContent>
|
|
101
|
-
<div className="inline-flex items-center gap-3 text-muted-foreground">
|
|
102
|
-
<Loader size={20} />
|
|
103
|
-
<span>Loading project...</span>
|
|
104
|
-
</div>
|
|
105
|
-
</CardContent>
|
|
106
|
-
</Card>
|
|
107
|
-
</div>
|
|
108
|
-
</section>
|
|
109
|
-
</main>
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (error) {
|
|
114
|
-
return (
|
|
115
|
-
<main className="min-h-screen bg-muted/50 text-foreground">
|
|
116
|
-
<section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
|
|
117
|
-
<div className="mx-auto w-full max-w-sm">
|
|
118
|
-
<Alert>
|
|
119
|
-
<AlertDescription>Failed to connect to Fusion host: {error}</AlertDescription>
|
|
120
|
-
</Alert>
|
|
121
|
-
</div>
|
|
122
|
-
</section>
|
|
123
|
-
</main>
|
|
124
|
-
);
|
|
125
|
-
}
|
|
65
|
+
const loadingFallback = (
|
|
66
|
+
<main className="min-h-screen bg-muted/50 text-foreground">
|
|
67
|
+
<section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
|
|
68
|
+
<div className="mx-auto w-full max-w-sm">
|
|
69
|
+
<Card aria-label="Loading project" aria-live="polite">
|
|
70
|
+
<CardContent>
|
|
71
|
+
<div className="inline-flex items-center gap-3 text-muted-foreground">
|
|
72
|
+
<Loader size={20} />
|
|
73
|
+
<span>Loading project...</span>
|
|
74
|
+
</div>
|
|
75
|
+
</CardContent>
|
|
76
|
+
</Card>
|
|
77
|
+
</div>
|
|
78
|
+
</section>
|
|
79
|
+
</main>
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
const errorFallback = (
|
|
83
|
+
<main className="min-h-screen bg-muted/50 text-foreground">
|
|
84
|
+
<section className="mx-auto flex min-h-screen w-full max-w-lg flex-col justify-center p-4 sm:p-8">
|
|
85
|
+
<div className="mx-auto w-full max-w-sm">
|
|
86
|
+
<Alert>
|
|
87
|
+
<AlertDescription>Failed to connect to Fusion host</AlertDescription>
|
|
88
|
+
</Alert>
|
|
89
|
+
</div>
|
|
90
|
+
</section>
|
|
91
|
+
</main>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
function AppContent() {
|
|
95
|
+
const client = useCogniteSdk();
|
|
126
96
|
|
|
127
97
|
const deployment = appConfig.deployments?.[0];
|
|
128
98
|
const orgLabel = deployment?.org ?? '';
|
|
129
|
-
const projectLabel = deployment?.project ?? project ?? '';
|
|
99
|
+
const projectLabel = deployment?.project ?? client.project ?? '';
|
|
130
100
|
|
|
131
101
|
return (
|
|
132
102
|
<main className="min-h-screen bg-muted/50 text-foreground">
|
|
@@ -230,4 +200,16 @@ function App() {
|
|
|
230
200
|
);
|
|
231
201
|
}
|
|
232
202
|
|
|
203
|
+
type AppProps = {
|
|
204
|
+
deps?: ComponentProps<typeof CogniteSdkProvider>['deps'];
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
function App({ deps }: AppProps) {
|
|
208
|
+
return (
|
|
209
|
+
<CogniteSdkProvider loadingFallback={loadingFallback} errorFallback={errorFallback} deps={deps}>
|
|
210
|
+
<AppContent />
|
|
211
|
+
</CogniteSdkProvider>
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
|
|
233
215
|
export default App;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{a as s}from"./chunk-EI7MMDWY.js";import Y from"fs";import ut from"path";var
|
|
2
|
-
See: ${
|
|
3
|
-
See: ${
|
|
4
|
-
${n}`),{cause:t}):null}s(A,"enrichedHttpError");function Z(e){if(!m(e))return null;let t=e.missing;if(Array.isArray(t))return t;let n=e.data;if(m(n)){let r=n.error;if(m(r)&&Array.isArray(r.missing))return r.missing;if(Array.isArray(n.missing))return n.missing}return null}s(Z,"findMissingArray");function X(e,t){if(!
|
|
1
|
+
import{a as s}from"./chunk-EI7MMDWY.js";import Y from"fs";import ut from"path";var F="https://docs.cognite.com/cdf/access/";function m(e){return e!==null&&typeof e=="object"}s(m,"isRecord");function P(e){return e instanceof Error&&"status"in e&&typeof e.status=="number"}s(P,"isHttpError");function W(e){switch(e){case 401:return`Your credentials are invalid or expired. Check your client ID and secret.
|
|
2
|
+
See: ${F}`;case 403:return`You don't have the required CDF capabilities. Please contact your CDF admin.
|
|
3
|
+
See: ${F}`;default:return}}s(W,"httpStatusHint");function A(e){let t=e instanceof Error?e:new Error(String(e));if(!P(t))return null;let n=W(t.status);return n?Object.assign(new Error(`${t.message}
|
|
4
|
+
${n}`),{cause:t}):null}s(A,"enrichedHttpError");function Z(e){if(!m(e))return null;let t=e.missing;if(Array.isArray(t))return t;let n=e.data;if(m(n)){let r=n.error;if(m(r)&&Array.isArray(r.missing))return r.missing;if(Array.isArray(n.missing))return n.missing}return null}s(Z,"findMissingArray");function X(e,t){if(!P(e)||e.status!==400)return!1;let n=Z(e);return n?n.some(r=>m(r)&&typeof r.externalId=="string"&&t.includes(r.externalId)):!1}s(X,"isMissingExternalIdError");function $(e,t){return P(e)&&e.status===404||X(e,t)}s($,"isNotFoundError");var M=["DRAFT","PUBLISHED","DEPRECATED","ARCHIVED"],J=["ACTIVE","PREVIEW"],I=class I extends Error{constructor(t,n){super(`Version ${n} of app ${t} not found`),this.name="AppVersionNotFoundError",this.appExternalId=t,this.version=n}};s(I,"AppVersionNotFoundError");var k=I;function q(e,t){return e.includes(t)}s(q,"includesValue");function Q(e){return q(M,e)}s(Q,"isAppVersionLifecycleState");function tt(e){return q(J,e)}s(tt,"isAppVersionAlias");function et(e){return typeof e.version=="string"&&Q(e.lifecycleState)&&typeof e.entrypoint=="string"&&typeof e.createdTime=="number"&&typeof e.createdBy=="string"&&typeof e.appExternalId=="string"&&(e.alias===void 0||tt(e.alias))&&(e.comment===void 0||typeof e.comment=="string")}s(et,"isAppVersion");function H(e){if(!m(e))throw new Error("Invalid version response: not an object");if(!et(e))throw new Error("Invalid version response: missing or malformed fields");return e}s(H,"parseAppVersion");var T=class T{constructor(t){this.client=t}get appsBasePath(){return`/api/v1/projects/${encodeURIComponent(this.client.project)}/apphosting/apps`}async createApp(t,n,r){try{await this.client.post(this.appsBasePath,{data:{items:[{externalId:t,name:n,description:r}]}})}catch(o){throw A(o)??o}}async uploadVersion(t,n,r,o,i="index.html"){console.log(`\u{1F4E4} Uploading version ${n}...`);let a=new FormData;a.append("file",new Blob([new Uint8Array(r)]),o),a.append("version",n),a.append("entryPath",i);let l=encodeURIComponent(t),c=`${this.appsBasePath}/${l}/versions`,p=await this.client.authenticate(),g=`${this.client.getBaseUrl()}${c}`,u=new AbortController,G=setTimeout(()=>u.abort(),300*1e3),h;try{h=await fetch(g,{method:"POST",headers:{Authorization:`Bearer ${p}`},body:a,signal:u.signal})}catch(f){throw f instanceof Error&&f.name==="AbortError"?new Error("Upload timed out after 5 minutes"):f}finally{clearTimeout(G)}if(!h.ok){let f=await h.text(),V=f;try{let x=JSON.parse(f);if(m(x)){let w=x.error;if(typeof w=="string")V=w;else if(m(w)){let E=w.message,B=w.code;V=typeof E=="string"?E:B!=null?`Unknown error (code: ${B})`:f}else{let E=x.message;V=typeof E=="string"?E:f}}}catch{}let j=h.headers.get("x-request-id"),K=j?` | X-Request-ID: ${j}`:"",N=Object.assign(new Error(`Upload failed: ${h.status} \u2014 ${V}${K}`),{status:h.status});throw A(N)??N}console.log(`\u2705 Version ${n} uploaded`)}async getVersion(t,n){let r=encodeURIComponent(t),o=encodeURIComponent(n),i=`${this.appsBasePath}/${r}/versions/${o}`;try{let a=await this.client.get(i);return H(a.data)}catch(a){throw $(a,[t,n])?new k(t,n):A(a)??a}}async getActiveVersion(t){let n=encodeURIComponent(t),r=`${this.appsBasePath}/${n}/active`;try{let o=await this.client.get(r);return H(o.data)}catch(o){if($(o,[t]))return null;throw A(o)??o}}async updateVersions(t,n){let r=encodeURIComponent(t),o=`${this.appsBasePath}/${r}/versions/update`;try{await this.client.post(o,{data:{items:n}})}catch(i){throw A(i)??i}}};s(T,"AppHostingApi");var v=T;var b=class b{constructor(t){this.api=new v(t)}getVersion(t,n){return this.api.getVersion(t,n)}uploadVersion(t,n,r,o,i){return this.api.uploadVersion(t,n,r,o,i)}async ensureApp(t,n,r){console.log("\u{1F50D} Ensuring app exists...");try{await this.api.createApp(t,n,r),console.log(`\u2705 App '${t}' created`)}catch(o){if(P(o)&&o.status===409){console.log(`\u2705 App '${t}' already exists`);return}throw o}}async publishVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"}}}])}async publishAndActivate(t,n){console.log(`\u{1F680} Publishing and activating version ${n}...`),await this.api.updateVersions(t,[{version:n,update:{lifecycleState:{set:"PUBLISHED"},alias:{set:"ACTIVE"}}}]),console.log(`\u2705 Version ${n} is now PUBLISHED and ACTIVE`)}getActiveVersion(t){return this.api.getActiveVersion(t)}async deactivateVersion(t,n){await this.api.updateVersions(t,[{version:n,update:{alias:{setNull:!0}}}])}async activateVersion(t,n){let r=null;try{r=await this.api.getActiveVersion(t)}catch{r=null}let o=r&&r.version!==n?r.version:void 0;return await this.api.updateVersions(t,[{version:n,update:{alias:{set:"ACTIVE"}}}]),{supersededVersion:o}}async deploy(t,n,r,o,i,a,l=!1){console.log(`
|
|
5
5
|
\u{1F680} Deploying application via App Hosting API...
|
|
6
6
|
`);try{await this.ensureApp(t,n,r),await this.uploadVersion(t,o,i,a),l&&await this.publishAndActivate(t,o),console.log(`
|
|
7
|
-
\u2705 Deployment successful!`)}catch(c){let p=c instanceof Error?c.message:String(c);throw Object.assign(new Error(`Deployment failed: ${p}`),{cause:c})}}};s(b,"AppHostingClient");var
|
|
7
|
+
\u2705 Deployment successful!`)}catch(c){let p=c instanceof Error?c.message:String(c);throw Object.assign(new Error(`Deployment failed: ${p}`),{cause:c})}}};s(b,"AppHostingClient");var S=b;import y from"fs";import d from"path";import{parseAndValidateManifestConfig as nt}from"@cognite/app-sdk/vite";import{BlobReader as rt,Uint8ArrayWriter as ot,ZipWriter as st}from"@zip.js/zip.js";var R="package.json",D="package-lock.json",z="manifest.json",_=".cognite",L=class L{constructor(t="dist"){this.distPath=d.isAbsolute(t)?t:d.join(process.cwd(),t),this.appRoot=d.dirname(this.distPath)}validateBuildDirectory(){if(!y.existsSync(this.distPath))throw new Error(`Build directory "${this.distPath}" not found. Run build first.`);let t=d.join(this.appRoot,R);if(!y.existsSync(t))throw new Error(`"${t}" not found. It is required for deployment.`);let n=d.join(this.appRoot,D);if(!y.existsSync(n))throw new Error(`"${n}" not found. It is required for deployment.`)}async createZip(t="app.zip",n=!1){this.validateBuildDirectory(),console.log("\u{1F4E6} Packaging application...");let r=new st(new ot,{level:9}),o=s(async(c,p)=>{await r.add(p,new rt(await y.openAsBlob(c))),n&&console.log(` \u{1F4C4} ${p}`)},"addFile"),i=s(async c=>{let p=await y.promises.readdir(c,{withFileTypes:!0});for(let g of p){let u=d.join(c,g.name);g.isDirectory()?await i(u):await o(u,d.relative(this.distPath,u).replace(/\\/g,"/"))}},"addDir"),a;try{await i(this.distPath);let c=d.join(this.appRoot,R);await o(c,d.posix.join(_,R));let p=d.join(this.appRoot,z);if(y.existsSync(p)){let u=y.readFileSync(p,"utf-8");nt(u,p),await o(p,d.posix.join(_,z))}let g=d.join(this.appRoot,D);await o(g,d.posix.join(_,D)),a=await r.close()}catch(c){let p=c instanceof Error?c.message:String(c);throw new Error(`Failed to create zip: ${p}`)}await y.promises.writeFile(t,a);let l=(a.byteLength/1024/1024).toFixed(2);return console.log(`\u2705 App packaged: ${t} (${l} MB)`),t}};s(L,"ApplicationPackager");var C=L;import{CogniteClient as dt}from"@cognite/sdk";var it=s(()=>{let e=process.env.DEPLOYMENT_SECRETS;if(!e)return{};try{let t=JSON.parse(e),n={};for(let[r,o]of Object.entries(t))if(typeof o=="string"){let i=r.toLowerCase().replace(/_/g,"-");n[i]=o}return n}catch(t){return console.error("Error parsing DEPLOYMENT_SECRETS:",t),{}}},"loadSecretsFromEnv"),at=s(e=>{let t;if(process.env.DEPLOYMENT_SECRET&&(t=process.env.DEPLOYMENT_SECRET),t||(t=it()[e]),t||(t=process.env[e]),!t)throw new Error(`Secret not found in environment: ${e}`);return t},"getSecretFromEnv"),ct=s(e=>{if(!e)return"";try{return new URL(e).hostname.replace(/\.cognitedata\.com$/,"")}catch{let t=e.replace(/^https?:\/\//,"");return t=t.split("/")[0],t=t.split(":")[0],t=t.replace(/\.cognitedata\.com$/,""),t}},"extractClusterFromUrl"),pt=s(async(e,t)=>{let n=`Basic ${btoa(`${e}:${t}`)}`,r=await fetch("https://auth.cognite.com/oauth2/token",{method:"POST",headers:{Authorization:n,"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({grant_type:"client_credentials"})});if(!r.ok){let i=await r.text();throw new Error(`Failed to get token from CDF: ${r.status} ${r.statusText}
|
|
8
8
|
${i}`)}let o=await r.json();if(!o.access_token)throw new Error("No access token returned from CDF authentication");return o.access_token},"getTokenCdf"),lt=s(async(e,t,n,r)=>{if(!r)throw new Error("Entra ID authentication requires 'baseUrl' to be set in deployment configuration");let o=ct(r);if(!o)throw new Error(`Entra ID authentication requires 'baseUrl' to be a valid CDF URL (e.g., https://cluster.cognitedata.com), got: ${r}`);let i=`https://login.microsoftonline.com/${n}/oauth2/v2.0/token`,a=`https://${o}.cognitedata.com/.default`,l=await fetch(i,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({client_id:e,client_secret:t,scope:a,grant_type:"client_credentials"})});if(!l.ok){let p=await l.text();throw new Error(`Failed to get token from Entra ID: ${l.status} ${l.statusText}
|
|
9
|
-
${p}`)}let c=await l.json();if(!c.access_token)throw new Error("No access token returned from Entra ID authentication");return c.access_token},"getTokenEntra"),O=s(async(e,t=process.env)=>{if(t.COGNITE_TOKEN)return t.COGNITE_TOKEN;let{deployClientId:n,deploySecretName:r,idpType:o="cdf",tenantId:i,baseUrl:a}=e,l=at(r);if(o==="entra_id"){if(!i)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return lt(n,l,i,a)}return pt(n,l)},"getToken");async function U(e,t,n=process.env,r){let o=await O(e,n),i=n.COGNITE_BASE_URL??e.baseUrl,a=(r??(l=>new dt(l)))({appId:t,project:e.project,baseUrl:i,oidcTokenProvider:s(async()=>o,"oidcTokenProvider")});return await a.authenticate(),a}s(U,"getSdk");var gt=s(async(e,t,n)=>{let r=await new C(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:o,name:i,description:a,versionTag:l}=t,c=await U(e,n),p=new
|
|
9
|
+
${p}`)}let c=await l.json();if(!c.access_token)throw new Error("No access token returned from Entra ID authentication");return c.access_token},"getTokenEntra"),O=s(async(e,t=process.env)=>{if(t.COGNITE_TOKEN)return t.COGNITE_TOKEN;let{deployClientId:n,deploySecretName:r,idpType:o="cdf",tenantId:i,baseUrl:a}=e,l=at(r);if(o==="entra_id"){if(!i)throw new Error("Entra ID authentication requires 'tenantId' in deployment configuration");return lt(n,l,i,a)}return pt(n,l)},"getToken");async function U(e,t,n=process.env,r){let o=await O(e,n),i=n.COGNITE_BASE_URL??e.baseUrl,a=(r??(l=>new dt(l)))({appId:t,project:e.project,baseUrl:i,oidcTokenProvider:s(async()=>o,"oidcTokenProvider")});return await a.authenticate(),a}s(U,"getSdk");var gt=s(async(e,t,n)=>{let r=await new C(`${n}/dist`).createZip("app.zip",!0);try{let{externalId:o,name:i,description:a,versionTag:l}=t,c=await U(e,n),p=new S(c),g=Y.readFileSync(r),u=ut.basename(r);await p.deploy(o,i,a,l,g,u,e.published)}finally{try{Y.unlinkSync(r)}catch{}}},"deploy");export{S as a,C as b,O as c,U as d,gt as e};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var c=Object.defineProperty;var s=(l,i)=>c(l,"name",{value:i,configurable:!0});import{execFileSync as a}from"child_process";import{createRequire as p}from"module";import{InvalidArgumentError as u}from"commander";var t="https://github.com/cognitedata/builder-skills/tree/data-modeling-runtime-sdk-alpha",e=["claude-code","cursor"],o=e.flatMap(l=>["-a",l]),d=p(import.meta.url).resolve("skills/bin/cli.mjs");function n(l,i={}){a(process.execPath,[d,...l],{stdio:"inherit",cwd:process.cwd(),...i})}s(n,"execSkillsCli");function y(){return["add",t,...o,"--skill","*","-y"]}s(y,"pullAllArgs");function m(l){let i=/^[\w.-]+\/[\w.-]+$/.test(l),r=/^https:\/\/github\.com\/[\w.-]+\/[\w.-]+(\/tree\/[^\s]+)?$/.test(l);if(!i&&!r)throw new u("Expected owner/repo or GitHub URL with optional branch (e.g., cognitedata/builder-skills or https://github.com/cognitedata/builder-skills/tree/alpha)");return l}s(m,"validateSource");function g(l){let i=["add",l.source,...o];return l.skill?i.push("--skill",l.skill):l.interactive||i.push("--skill","*","-y"),l.global&&i.push("--global"),i}s(g,"buildPullArgs");function k(l){console.log(`\u{1F504} Pulling skills from ${l.source}...`),n(g(l)),console.log(`
|
|
2
|
+
\u2705 Skills pulled successfully`)}s(k,"handlePull");function S(l){let i=l.command("skills").summary("Manage AI agent skills for your app").description(`Manage AI agent skills for your app.
|
|
3
|
+
Supports: ${e.join(", ")}`).addHelpText("after",`
|
|
4
|
+
Examples:
|
|
5
|
+
npx @cognite/cli apps skills pull Pull all skills
|
|
6
|
+
npx @cognite/cli apps skills pull --skill create-client-tool Pull a specific skill
|
|
7
|
+
npx @cognite/cli apps skills pull --source https://github.com/cognitedata/builder-skills/tree/alpha Pull from a specific branch
|
|
8
|
+
npx @cognite/cli apps skills list List installed skills`);return i.command("pull").description("Pull all skills into your project").option("--source <owner/repo|url>","Skills repository \u2014 owner/repo shorthand or full GitHub URL (supports /tree/<branch>)",m,t).option("--skill <name>","Pull a specific skill by name").option("-i, --interactive","Interactively select which skills to install",!1).option("--global","Install skills globally",!1).action(k),i.command("list").description("List installed skills").action(()=>{n(["list"])}),i}s(S,"registerSkillsCommand");export{s as a,n as b,y as c,g as d,S as e};
|