@creact-labs/creact 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.
package/README.md CHANGED
@@ -1,88 +1,60 @@
1
- # CReact
2
-
3
- **Declarative universal reactive runtime.**
4
-
5
- ## Install
1
+ <p align="center">
2
+ <img src="https://img.shields.io/npm/v/@creact-labs/creact" alt="npm version" />
3
+ <img src="https://img.shields.io/npm/l/@creact-labs/creact" alt="license" />
4
+ </p>
6
5
 
7
- ```bash
8
- npm install creact
9
- ```
6
+ # CReact
10
7
 
11
- ## Quick Example
8
+ What if you could generate SEO-optimized product pages by researching competitors automatically?
12
9
 
13
10
  ```tsx
14
- // tsconfig.json: "jsxImportSource": "creact"
15
-
16
- import { CReact, renderCloudDOM, useInstance } from 'creact';
17
-
18
- // Define constructs
19
- class ChatModel {
20
- constructor(public props: { model: string }) {}
21
- }
22
-
23
- class Memory {
24
- constructor(public props: {}) {}
25
- }
26
-
27
- // Define components
28
- function Model({ model, children }) {
29
- const out = useInstance(ChatModel, { model });
30
- return children(out);
31
- }
32
-
33
- function Mem({ children }) {
34
- const out = useInstance(Memory, {});
35
- return children(out);
36
- }
37
-
38
- function App({ prompt }) {
39
- return (
40
- <Model model="gpt-4">
41
- {(model) => (
42
- <Mem>
43
- {(memory) => (
44
- <Agent
45
- prompt={prompt}
46
- modelId={model.id()}
47
- messages={memory.messages()}
48
- />
11
+ <FormTrigger fields={['productTitle']}>
12
+ {(form) => (
13
+ <GoogleSearch query={`intitle:"${form.productTitle()}" pricing OR features`}>
14
+ {(results) => (
15
+ <ExtractText items={results.items()} fields={['title', 'snippet']}>
16
+ {(extracted) => (
17
+ <GeminiCompletion prompt={`Generate SEO meta and product description:\n${extracted.text()}`}>
18
+ {(content) => (
19
+ <>
20
+ <ParseSections text={content.output()} format="seo,product">
21
+ {(parsed) => (
22
+ <GoogleSheetAppend doc="catalog" row={parsed.fields()} />
23
+ )}
24
+ </ParseSections>
25
+
26
+ <SlackMessage channel="#products" text={`New: ${form.productTitle()}`} />
27
+ </>
28
+ )}
29
+ </GeminiCompletion>
49
30
  )}
50
- </Mem>
31
+ </ExtractText>
51
32
  )}
52
- </Model>
53
- );
54
- }
33
+ </GoogleSearch>
34
+ )}
35
+ </FormTrigger>
36
+ ```
55
37
 
56
- // Run
57
- CReact.provider = new AgentProvider();
58
- CReact.backend = new FileBackend({ directory: '.state' });
38
+ Form → Search → Extract → AI → branches to Sheets and Slack. Each construct is one action.
59
39
 
60
- await renderCloudDOM(<App prompt="Hello" />, 'agent');
40
+ ```bash
41
+ npm install @creact-labs/creact
61
42
  ```
62
43
 
63
- ## The Four Pillars
44
+ ## How it works
64
45
 
65
- **Declarative** Describe what you want, not how to get it.
46
+ **Constructs** define what you want (props) and what you get (outputs).
66
47
 
67
- **Universal** Works for AI agents, cloud infrastructure, APIs, anything.
48
+ **Components** compose constructs with JSX. Dependencies flow through render props.
68
49
 
69
- **Reactive** Automatically responds when things change.
50
+ **Providers** execute constructs against real infrastructure (AWS, Terraform, APIs).
70
51
 
71
- **Runtime** Keeps running continuously, handles events, recovers from crashes.
52
+ **Backends** persist state for crash recovery and incremental updates.
72
53
 
73
54
  ## Documentation
74
55
 
75
- ### Getting Started
76
-
77
- - [Tutorial: Build an AI Agent](./docs/getting-started/1-setup.md)
78
-
79
- ### Concepts
80
-
81
- - [Thinking in CReact](./docs/concepts/thinking-in-creact.md) — The mental model
82
- - [Constructs](./docs/concepts/constructs.md) — Your building blocks
83
- - [Components](./docs/concepts/components.md) — Composing with JSX
84
- - [Reactivity](./docs/concepts/reactivity.md) — When things change
85
- - [Providers](./docs/concepts/providers.md) — Connecting to the real world
56
+ - [Tutorial](./docs/getting-started/1-setup.md) — Build an AI agent with Wikipedia search
57
+ - [Concepts](./docs/concepts/index.md) — Core mental model
86
58
 
87
59
  ## License
88
60
 
package/dist/cli.js CHANGED
@@ -8,8 +8,10 @@
8
8
  * Runs a CReact application with the configured provider.
9
9
  * Uses tsx under the hood to execute TypeScript/TSX files.
10
10
  */
11
- import { spawn } from 'node:child_process';
12
- import { resolve } from 'node:path';
11
+ import { tsImport } from 'tsx/esm/api';
12
+ import { watch } from 'node:fs/promises';
13
+ import { dirname, resolve } from 'node:path';
14
+ import { pathToFileURL } from 'node:url';
13
15
  function showHelp() {
14
16
  console.log(`
15
17
  CReact CLI
@@ -41,6 +43,12 @@ Example entrypoint:
41
43
  }
42
44
  `);
43
45
  }
46
+ async function runEntrypoint(entrypoint) {
47
+ const module = await tsImport(pathToFileURL(entrypoint).href, import.meta.url);
48
+ if (typeof module.default === 'function') {
49
+ await module.default();
50
+ }
51
+ }
44
52
  async function main() {
45
53
  const args = process.argv.slice(2);
46
54
  if (args.length === 0 || args[0] === '--help' || args[0] === '-h') {
@@ -48,11 +56,11 @@ async function main() {
48
56
  process.exit(0);
49
57
  }
50
58
  // Parse --watch / -w flag and get entrypoint
51
- let watch = false;
59
+ let watchMode = false;
52
60
  let entrypointArg;
53
61
  const firstArg = args[0];
54
62
  if (firstArg === '--watch' || firstArg === '-w') {
55
- watch = true;
63
+ watchMode = true;
56
64
  const arg = args[1];
57
65
  if (!arg) {
58
66
  console.error('Error: --watch requires an entrypoint');
@@ -68,21 +76,18 @@ async function main() {
68
76
  process.exit(0);
69
77
  }
70
78
  const entrypoint = resolve(process.cwd(), entrypointArg);
71
- // Build tsx command
72
- const tsxArgs = watch ? ['tsx', 'watch', entrypoint] : ['tsx', entrypoint];
73
- // Spawn tsx to run the entrypoint
74
- const child = spawn('npx', tsxArgs, {
75
- stdio: 'inherit',
76
- cwd: process.cwd(),
77
- shell: true,
78
- });
79
- child.on('error', (error) => {
80
- console.error('Error running CReact application:');
81
- console.error(error.message);
82
- process.exit(1);
83
- });
84
- child.on('exit', (code) => {
85
- process.exit(code ?? 0);
86
- });
79
+ // Initial run
80
+ await runEntrypoint(entrypoint);
81
+ // Watch mode: async iterator keeps process alive
82
+ if (watchMode) {
83
+ console.log('Watching for changes...');
84
+ const watcher = watch(dirname(entrypoint), { recursive: true });
85
+ for await (const event of watcher) {
86
+ if (event.filename?.match(/\.(tsx?|jsx?)$/)) {
87
+ console.log(`\nRestarting...`);
88
+ await runEntrypoint(entrypoint);
89
+ }
90
+ }
91
+ }
87
92
  }
88
93
  main();
package/dist/index.d.ts CHANGED
@@ -5,17 +5,9 @@ export { createElement, Fragment, jsx, jsxs } from './jsx/jsx-runtime';
5
5
  export { createContext, useContext } from './primitives/context';
6
6
  export { useInstance } from './primitives/instance';
7
7
  export { createStore } from './primitives/store';
8
- export type { AuditLogEntry, Backend, ChangeSet, DeploymentState, DeploymentStatus, ResourceState, SerializedNode, } from './provider/backend';
9
- export { serializeNode, serializeNodes } from './provider/backend';
8
+ export { createEffect } from './reactive/effect';
9
+ export { CReact, renderCloudDOM } from './runtime/run';
10
+ export type { AuditLogEntry, Backend, DeploymentState } from './provider/backend';
10
11
  export type { OutputChangeEvent, Provider } from './provider/interface';
11
12
  export { createMockProvider } from './provider/interface';
12
- export { createEffect, onCleanup } from './reactive/effect';
13
- export { createSignal } from './reactive/signal';
14
- export { batch, untrack } from './reactive/tracking';
15
- export type { DependencyGraph } from './runtime/reconcile';
16
- export { buildDependencyGraph, computeParallelBatches, hasNewNodes, reconcile, topologicalSort, } from './runtime/reconcile';
17
- export type { CReactOptions } from './runtime/run';
18
- export { CReact, renderCloudDOM, resetRuntime, run, runWithBackend } from './runtime/run';
19
- export type { StateMachineOptions } from './runtime/state-machine';
20
- export { StateMachine } from './runtime/state-machine';
21
- export type { Accessor, Context, Fiber, InstanceNode, JSXElement, OutputAccessors, SetStoreFunction, Setter, } from './types';
13
+ export type { Context, InstanceNode, JSXElement, OutputAccessors, SetStoreFunction, } from './types';
package/dist/index.js CHANGED
@@ -7,16 +7,7 @@ export { createContext, useContext } from './primitives/context';
7
7
  // Primitives
8
8
  export { useInstance } from './primitives/instance';
9
9
  export { createStore } from './primitives/store';
10
- // Backend
11
- export { serializeNode, serializeNodes } from './provider/backend';
12
- // Provider
13
- export { createMockProvider } from './provider/interface';
14
- // Reactive
15
- export { createEffect, onCleanup } from './reactive/effect';
16
- export { createSignal } from './reactive/signal';
17
- export { batch, untrack } from './reactive/tracking';
18
- // Reconciler
19
- export { buildDependencyGraph, computeParallelBatches, hasNewNodes, reconcile, topologicalSort, } from './runtime/reconcile';
10
+ export { createEffect } from './reactive/effect';
20
11
  // Runtime
21
- export { CReact, renderCloudDOM, resetRuntime, run, runWithBackend } from './runtime/run';
22
- export { StateMachine } from './runtime/state-machine';
12
+ export { CReact, renderCloudDOM } from './runtime/run';
13
+ export { createMockProvider } from './provider/interface';
package/package.json CHANGED
@@ -1,9 +1,27 @@
1
1
  {
2
2
  "name": "@creact-labs/creact",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Declarative universal reactive runtime",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ },
12
+ "./jsx-runtime": {
13
+ "types": "./dist/jsx/jsx-runtime.d.ts",
14
+ "default": "./dist/jsx/jsx-runtime.js"
15
+ },
16
+ "./jsx-dev-runtime": {
17
+ "types": "./dist/jsx/jsx-dev-runtime.d.ts",
18
+ "default": "./dist/jsx/jsx-dev-runtime.js"
19
+ },
20
+ "./jsx": {
21
+ "types": "./dist/jsx/index.d.ts",
22
+ "default": "./dist/jsx/index.js"
23
+ }
24
+ },
7
25
  "typesVersions": {
8
26
  "*": {
9
27
  "jsx": [