@agentick/core 0.1.9 → 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.
Files changed (62) hide show
  1. package/README.md +73 -54
  2. package/dist/.tsbuildinfo.build +1 -1
  3. package/dist/app/session.js +2 -2
  4. package/dist/app/session.js.map +1 -1
  5. package/dist/app/types.d.ts +1 -1
  6. package/dist/app/types.d.ts.map +1 -1
  7. package/dist/compiler/collector.d.ts +1 -1
  8. package/dist/compiler/collector.js +1 -1
  9. package/dist/compiler/fiber-compiler.d.ts +8 -14
  10. package/dist/compiler/fiber-compiler.d.ts.map +1 -1
  11. package/dist/compiler/fiber-compiler.js +22 -41
  12. package/dist/compiler/fiber-compiler.js.map +1 -1
  13. package/dist/compiler/index.d.ts +1 -1
  14. package/dist/compiler/index.js +1 -1
  15. package/dist/compiler/scheduler.d.ts +3 -3
  16. package/dist/compiler/scheduler.js +4 -4
  17. package/dist/compiler/scheduler.js.map +1 -1
  18. package/dist/hibernation/index.d.ts +1 -1
  19. package/dist/hibernation/index.js +1 -1
  20. package/dist/hooks/com-state.d.ts +4 -3
  21. package/dist/hooks/com-state.d.ts.map +1 -1
  22. package/dist/hooks/com-state.js +16 -13
  23. package/dist/hooks/com-state.js.map +1 -1
  24. package/dist/hooks/context.d.ts +1 -1
  25. package/dist/hooks/context.js +1 -1
  26. package/dist/hooks/data.d.ts +1 -1
  27. package/dist/hooks/data.js +1 -1
  28. package/dist/hooks/formatter-context.d.ts +1 -2
  29. package/dist/hooks/formatter-context.d.ts.map +1 -1
  30. package/dist/hooks/formatter-context.js +1 -2
  31. package/dist/hooks/formatter-context.js.map +1 -1
  32. package/dist/hooks/index.d.ts +1 -1
  33. package/dist/hooks/index.js +1 -1
  34. package/dist/hooks/message-context.d.ts +1 -1
  35. package/dist/hooks/message-context.js +1 -1
  36. package/dist/hooks/runtime-context.d.ts +1 -1
  37. package/dist/hooks/runtime-context.js +1 -1
  38. package/dist/hooks/types.d.ts +1 -1
  39. package/dist/hooks/types.js +1 -1
  40. package/dist/jsx/jsx-runtime.d.ts +1 -3
  41. package/dist/jsx/jsx-runtime.d.ts.map +1 -1
  42. package/dist/reconciler/host-config.d.ts +6 -5
  43. package/dist/reconciler/host-config.d.ts.map +1 -1
  44. package/dist/reconciler/host-config.js +56 -27
  45. package/dist/reconciler/host-config.js.map +1 -1
  46. package/dist/reconciler/index.d.ts +1 -1
  47. package/dist/reconciler/index.js +1 -1
  48. package/dist/reconciler/reconciler.d.ts +12 -11
  49. package/dist/reconciler/reconciler.d.ts.map +1 -1
  50. package/dist/reconciler/reconciler.js +23 -22
  51. package/dist/reconciler/reconciler.js.map +1 -1
  52. package/dist/reconciler/types.d.ts +2 -8
  53. package/dist/reconciler/types.d.ts.map +1 -1
  54. package/dist/reconciler/types.js +2 -2
  55. package/dist/reconciler/types.js.map +1 -1
  56. package/dist/renderers/types.d.ts +1 -1
  57. package/dist/renderers/types.js +1 -1
  58. package/dist/testing/act.d.ts.map +1 -1
  59. package/dist/testing/act.js +2 -3
  60. package/dist/testing/act.js.map +1 -1
  61. package/dist/testing/mock-app.js.map +1 -1
  62. package/package.json +14 -14
package/README.md CHANGED
@@ -40,7 +40,9 @@ function MyApp() {
40
40
  // Create and run
41
41
  const app = createApp(MyApp, { model: createOpenAIModel() });
42
42
  const session = await app.session();
43
- await session.send({ messages: [{ role: "user", content: [{ type: "text", text: "What is 2 + 2?" }] }] }).result;
43
+ await session.send({
44
+ messages: [{ role: "user", content: [{ type: "text", text: "What is 2 + 2?" }] }],
45
+ }).result;
44
46
  ```
45
47
 
46
48
  ## Level 0: `createAgent` (No JSX Required)
@@ -151,11 +153,11 @@ When `maxTokens` is set, Timeline automatically compacts entries that exceed the
151
153
 
152
154
  ```typescript
153
155
  interface TokenBudgetInfo {
154
- maxTokens: number; // configured budget
156
+ maxTokens: number; // configured budget
155
157
  effectiveBudget: number; // maxTokens - headroom
156
- currentTokens: number; // tokens in kept entries
157
- evictedCount: number; // entries dropped
158
- isCompacted: boolean; // whether compaction fired
158
+ currentTokens: number; // tokens in kept entries
159
+ evictedCount: number; // entries dropped
160
+ isCompacted: boolean; // whether compaction fired
159
161
  }
160
162
  ```
161
163
 
@@ -180,8 +182,7 @@ Group content with semantic meaning:
180
182
 
181
183
  ```tsx
182
184
  <Section id="context" title="Current Context">
183
- Today is {new Date().toDateString()}.
184
- User is logged in as {user.name}.
185
+ Today is {new Date().toDateString()}. User is logged in as {user.name}.
185
186
  </Section>
186
187
  ```
187
188
 
@@ -254,15 +255,15 @@ function MyComponent() {
254
255
  const counter = useSignal(0);
255
256
  const doubled = useComputed(() => counter() * 2, [counter]);
256
257
 
257
- counter(); // read: 0
258
- counter.set(5); // write
259
- counter.update(v => v + 1); // update with function
260
- doubled(); // read: 12
258
+ counter(); // read: 0
259
+ counter.set(5); // write
260
+ counter.update((v) => v + 1); // update with function
261
+ doubled(); // read: 12
261
262
 
262
263
  // COM state (persisted across ticks, shared between components)
263
264
  // Returns Signal<T>, NOT a tuple
264
265
  const notes = useComState<string[]>("notes", []);
265
- notes(); // read current value
266
+ notes(); // read current value
266
267
  notes.set(["a", "b"]); // write new value
267
268
  }
268
269
  ```
@@ -272,7 +273,14 @@ function MyComponent() {
272
273
  All lifecycle hooks follow the pattern: data first, COM (context) last.
273
274
 
274
275
  ```tsx
275
- import { useOnMount, useOnUnmount, useOnTickStart, useOnTickEnd, useAfterCompile, useContinuation } from "@agentick/core";
276
+ import {
277
+ useOnMount,
278
+ useOnUnmount,
279
+ useOnTickStart,
280
+ useOnTickEnd,
281
+ useAfterCompile,
282
+ useContinuation,
283
+ } from "@agentick/core";
276
284
 
277
285
  function MyComponent() {
278
286
  // Called when component mounts
@@ -304,7 +312,7 @@ function MyComponent() {
304
312
  useContinuation((result) => {
305
313
  // Return true to continue, false to stop
306
314
  if (result.text?.includes("<DONE>")) return false;
307
- if (result.tick >= 10) return false; // Safety limit
315
+ if (result.tick >= 10) return false; // Safety limit
308
316
  return true;
309
317
  });
310
318
 
@@ -376,7 +384,9 @@ function Agent() {
376
384
  const [temp] = useKnob("temp", 0.7, {
377
385
  description: "Temperature",
378
386
  group: "Model",
379
- min: 0, max: 2, step: 0.1,
387
+ min: 0,
388
+ max: 2,
389
+ step: 0.1,
380
390
  });
381
391
 
382
392
  // Boolean → model sees [toggle] type
@@ -496,13 +506,13 @@ function ContextAwareComponent() {
496
506
  ```typescript
497
507
  interface ContextInfo {
498
508
  // Model identification
499
- modelId: string; // "gpt-4o", "claude-3-5-sonnet", etc.
500
- modelName?: string; // Human-readable name
501
- provider?: string; // "openai", "anthropic", etc.
509
+ modelId: string; // "gpt-4o", "claude-3-5-sonnet", etc.
510
+ modelName?: string; // Human-readable name
511
+ provider?: string; // "openai", "anthropic", etc.
502
512
 
503
513
  // Context limits
504
- contextWindow?: number; // Total context window size
505
- maxOutputTokens?: number; // Max output tokens for model
514
+ contextWindow?: number; // Total context window size
515
+ maxOutputTokens?: number; // Max output tokens for model
506
516
 
507
517
  // Token usage (current tick)
508
518
  inputTokens: number;
@@ -510,7 +520,7 @@ interface ContextInfo {
510
520
  totalTokens: number;
511
521
 
512
522
  // Utilization
513
- utilization?: number; // Percentage (0-100)
523
+ utilization?: number; // Percentage (0-100)
514
524
 
515
525
  // Model capabilities
516
526
  supportsVision?: boolean;
@@ -518,7 +528,7 @@ interface ContextInfo {
518
528
  isReasoningModel?: boolean;
519
529
 
520
530
  // Execution info
521
- tick: number; // Current tick number
531
+ tick: number; // Current tick number
522
532
 
523
533
  // Cumulative usage across all ticks
524
534
  cumulativeUsage?: {
@@ -543,7 +553,7 @@ const contextInfoStore = createContextInfoStore();
543
553
  // Provide to components
544
554
  <ContextInfoProvider store={contextInfoStore}>
545
555
  <MyApp />
546
- </ContextInfoProvider>
556
+ </ContextInfoProvider>;
547
557
 
548
558
  // Update the store
549
559
  contextInfoStore.update({
@@ -579,11 +589,7 @@ const WeatherTool = createTool({
579
589
  return [{ type: "text", text: JSON.stringify(weather) }];
580
590
  },
581
591
  // Optional: render state to model context (receives tickState, ctx)
582
- render: (tickState, ctx) => (
583
- <Section id="weather-info">
584
- Last checked: {lastChecked}
585
- </Section>
586
- ),
592
+ render: (tickState, ctx) => <Section id="weather-info">Last checked: {lastChecked}</Section>,
587
593
  });
588
594
 
589
595
  // Use in your app
@@ -607,7 +613,7 @@ import { createApp } from "@agentick/core";
607
613
 
608
614
  const app = createApp(MyApp, {
609
615
  model: myModel,
610
- devTools: true, // Enable DevTools
616
+ devTools: true, // Enable DevTools
611
617
  });
612
618
  ```
613
619
 
@@ -638,11 +644,17 @@ const app = createApp(MyApp, {
638
644
  onError: (error) => console.error(error),
639
645
 
640
646
  // All events (fine-grained)
641
- onEvent: (event) => { /* handle any stream event */ },
647
+ onEvent: (event) => {
648
+ /* handle any stream event */
649
+ },
642
650
 
643
651
  // Send lifecycle
644
- onBeforeSend: (session, input) => { /* modify input */ },
645
- onAfterSend: (session, result) => { /* post-processing */ },
652
+ onBeforeSend: (session, input) => {
653
+ /* modify input */
654
+ },
655
+ onAfterSend: (session, result) => {
656
+ /* post-processing */
657
+ },
646
658
 
647
659
  // Tool confirmation
648
660
  onToolConfirmation: async (call, message) => {
@@ -689,18 +701,17 @@ const handle = await session.spawn(
689
701
  );
690
702
 
691
703
  // Spawn with a JSX element (props from element + input.props are merged)
692
- const handle = await session.spawn(
693
- <Researcher query="quantum computing" />,
694
- { messages: [{ role: "user", content: [{ type: "text", text: "Go" }] }] },
695
- );
704
+ const handle = await session.spawn(<Researcher query="quantum computing" />, {
705
+ messages: [{ role: "user", content: [{ type: "text", text: "Go" }] }],
706
+ });
696
707
  ```
697
708
 
698
709
  **Parallel spawns** work with `Promise.all`:
699
710
 
700
711
  ```tsx
701
712
  const [researchResult, factCheckResult] = await Promise.all([
702
- session.spawn(Researcher, { messages }).then(h => h.result),
703
- session.spawn(FactChecker, { messages }).then(h => h.result),
713
+ session.spawn(Researcher, { messages }).then((h) => h.result),
714
+ session.spawn(FactChecker, { messages }).then((h) => h.result),
704
715
  ]);
705
716
  ```
706
717
 
@@ -738,26 +749,34 @@ Control hibernation, limits, and auto-cleanup:
738
749
  const app = createApp(MyApp, {
739
750
  model,
740
751
  sessions: {
741
- store: new RedisSessionStore(redis), // Or ":memory:" for SQLite
742
- maxActive: 100, // Max concurrent sessions
743
- idleTimeout: 5 * 60 * 1000, // Hibernate after 5 min idle
744
- autoHibernate: true, // Auto-hibernate on idle
752
+ store: new RedisSessionStore(redis), // Or ":memory:" for SQLite
753
+ maxActive: 100, // Max concurrent sessions
754
+ idleTimeout: 5 * 60 * 1000, // Hibernate after 5 min idle
755
+ autoHibernate: true, // Auto-hibernate on idle
745
756
  },
746
757
 
747
758
  // Session lifecycle hooks
748
- onSessionCreate: (session) => { /* ... */ },
749
- onSessionClose: (sessionId) => { /* ... */ },
759
+ onSessionCreate: (session) => {
760
+ /* ... */
761
+ },
762
+ onSessionClose: (sessionId) => {
763
+ /* ... */
764
+ },
750
765
 
751
766
  // Hibernation hooks
752
767
  onBeforeHibernate: (session, snapshot) => {
753
768
  // Return false to cancel, modified snapshot, or void
754
769
  if (session.inspect().lastToolCalls.length > 0) return false;
755
770
  },
756
- onAfterHibernate: (sessionId, snapshot) => { /* ... */ },
771
+ onAfterHibernate: (sessionId, snapshot) => {
772
+ /* ... */
773
+ },
757
774
  onBeforeHydrate: (sessionId, snapshot) => {
758
775
  // Migrate old formats, validate, etc.
759
776
  },
760
- onAfterHydrate: (session, snapshot) => { /* ... */ },
777
+ onAfterHydrate: (session, snapshot) => {
778
+ /* ... */
779
+ },
761
780
  });
762
781
  ```
763
782
 
@@ -802,8 +821,8 @@ Apps inherit from the global `Agentick` instance by default:
802
821
  import { Agentick, createApp } from "@agentick/core";
803
822
 
804
823
  // Register global middleware
805
- Agentick.use('*', loggingMiddleware);
806
- Agentick.use('tool:*', authMiddleware);
824
+ Agentick.use("*", loggingMiddleware);
825
+ Agentick.use("tool:*", authMiddleware);
807
826
 
808
827
  // App inherits global middleware (default)
809
828
  const app = createApp(MyApp, { model });
@@ -811,7 +830,7 @@ const app = createApp(MyApp, { model });
811
830
  // Isolated app (for testing)
812
831
  const testApp = createApp(TestApp, {
813
832
  model,
814
- inheritDefaults: false
833
+ inheritDefaults: false,
815
834
  });
816
835
  ```
817
836
 
@@ -822,10 +841,10 @@ For one-off executions without session management:
822
841
  ```tsx
823
842
  import { run } from "@agentick/core";
824
843
 
825
- const result = await run(
826
- <MyApp />,
827
- { messages: [{ role: "user", content: [{ type: "text", text: "Hello!" }] }], model: myModel }
828
- );
844
+ const result = await run(<MyApp />, {
845
+ messages: [{ role: "user", content: [{ type: "text", text: "Hello!" }] }],
846
+ model: myModel,
847
+ });
829
848
  ```
830
849
 
831
850
  ### Choosing `run()` vs `createApp`
@@ -867,7 +886,7 @@ For debugging the reconciler itself with React DevTools:
867
886
  import { enableReactDevTools } from "@agentick/core";
868
887
 
869
888
  // Before creating sessions
870
- enableReactDevTools(); // Connects to npx react-devtools on port 8097
889
+ enableReactDevTools(); // Connects to npx react-devtools on port 8097
871
890
  ```
872
891
 
873
892
  ## License