bleam 0.0.11 → 0.0.13

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 (66) hide show
  1. package/dist/ai.cjs +2315 -2173
  2. package/dist/ai.d.cts +227 -322
  3. package/dist/ai.d.ts +227 -322
  4. package/dist/ai.js +2310 -2159
  5. package/dist/app-storage-D8W4n8ey.cjs +39 -0
  6. package/dist/app-storage-Isi5Bo0R.js +34 -0
  7. package/dist/cli.cjs +148 -22
  8. package/dist/cli.d.cts +14 -1
  9. package/dist/cli.d.ts +13 -0
  10. package/dist/cli.js +148 -22
  11. package/dist/config.d.cts +1 -1
  12. package/dist/elements-CFk0QHw0.d.cts +127 -0
  13. package/dist/{ui-CHc4xEs_.d.ts → elements-ClGQ41Sc.d.ts} +84 -49
  14. package/dist/{ui.cjs → elements.cjs} +307 -168
  15. package/dist/elements.d.cts +2 -0
  16. package/dist/elements.d.ts +2 -0
  17. package/dist/{ui.js → elements.js} +306 -169
  18. package/dist/{files-Ds1wT8C2.js → files-DErLhzCB.js} +11 -12
  19. package/dist/{files-Bo7h9fik.cjs → files-lMk-CpL_.cjs} +16 -11
  20. package/dist/files.cjs +1 -1
  21. package/dist/files.d.cts +1 -1
  22. package/dist/files.js +1 -1
  23. package/dist/index.d.cts +1 -1
  24. package/dist/schema-B7ELMpuI.js +226 -0
  25. package/dist/schema-B7SLUBLN.cjs +286 -0
  26. package/dist/schema-BWsDPc6c.d.cts +125 -0
  27. package/dist/schema-LxnzAfgw.d.ts +125 -0
  28. package/dist/schema.cjs +10 -2
  29. package/dist/schema.d.cts +2 -2
  30. package/dist/schema.d.ts +2 -2
  31. package/dist/schema.js +2 -2
  32. package/dist/secrets.cjs +146 -0
  33. package/dist/secrets.d.cts +14 -0
  34. package/dist/secrets.d.ts +14 -0
  35. package/dist/secrets.js +142 -0
  36. package/dist/state-BZYyrE2-.cjs +936 -0
  37. package/dist/state-DkaRFkZJ.js +843 -0
  38. package/dist/state.cjs +17 -12
  39. package/dist/state.d.cts +144 -140
  40. package/dist/state.d.ts +145 -140
  41. package/dist/state.js +4 -3
  42. package/dist/window.d.cts +1 -1
  43. package/dist/window.d.ts +3 -3
  44. package/package.json +13 -6
  45. package/templates/basic/app/index.tsx +2 -2
  46. package/templates/foundation-models/app/index.tsx +78 -16
  47. package/templates/image-generation/app/index.tsx +4 -4
  48. package/templates/native/ios/Bleam.xcodeproj/project.pbxproj +46 -46
  49. package/templates/native/ios/Podfile.lock +173 -173
  50. package/templates/native/modules/bleam-runtime/ios/AIModule.swift +42 -365
  51. package/templates/state/app/index.tsx +2 -2
  52. package/templates/text-generation/app/index.tsx +83 -52
  53. package/templates/updates/README.md +1 -1
  54. package/dist/schema-Bo5Jvqus.js +0 -90
  55. package/dist/schema-CYh6n8GS.d.ts +0 -58
  56. package/dist/schema-oeOrd3i1.d.cts +0 -58
  57. package/dist/schema-rQ13mrpD.cjs +0 -102
  58. package/dist/state-Bx0VlTlO.cjs +0 -852
  59. package/dist/state-CAwe-Vw1.js +0 -767
  60. package/dist/ui-1WepaMS4.d.cts +0 -92
  61. package/dist/ui.d.cts +0 -2
  62. package/dist/ui.d.ts +0 -2
  63. /package/dist/{config-CufOVJV3.d.cts → config-COcRnn5a.d.cts} +0 -0
  64. /package/dist/{files-Dt5mbzLq.d.cts → files-DwA7pzr3.d.cts} +0 -0
  65. /package/dist/{native-sqlite-yQLD5s9i.cjs → native-sqlite-Dw--FI9a.cjs} +0 -0
  66. /package/dist/{native-sqlite-xcGdamRD.js → native-sqlite-WzRNzCSh.js} +0 -0
package/dist/state.d.ts CHANGED
@@ -1,159 +1,164 @@
1
- import { a as FieldValue, f as SchemaOutput, l as SchemaInput, m as SchemaShape, t as BleamSchema } from "./schema-CYh6n8GS.js";
1
+ import { A as array, C as SchemaOutput, E as SchemaShape, F as number, I as object, P as literal, R as string, _ as ObjectField, b as SchemaInput, c as FieldPath, j as boolean, k as ValueAtFieldPath, s as FieldOutput, w as SchemaPatch } from "./schema-LxnzAfgw.js";
2
+ import "jotai/vanilla";
2
3
 
3
4
  //#region src/state/atom.d.ts
4
- type Listener = () => void;
5
- interface Store<Value> {
6
- get(): Value;
7
- subscribe(listener: Listener): () => void;
5
+ declare const atomValue: unique symbol;
6
+ declare const atomWrite: unique symbol;
7
+ interface Atom<Value> {
8
+ readonly [atomValue]: Value;
8
9
  }
9
- interface WritableStore<Value> extends Store<Value> {
10
- set(value: Value): void;
11
- update(updater: (value: Value) => Value): void;
12
- }
13
- declare class LiveStore<Value> implements WritableStore<Value> {
14
- private value;
15
- private listeners;
16
- constructor(value: Value);
17
- get(): Value;
18
- set(value: Value): void;
19
- update(updater: (value: Value) => Value): void;
20
- subscribe(listener: Listener): () => void;
10
+ interface WritableAtom<Value, Args$1 extends unknown[], Result$1> extends Atom<Value> {
11
+ readonly [atomWrite]: {
12
+ args: Args$1;
13
+ result: Result$1;
14
+ };
21
15
  }
22
- type Atom<Value> = WritableStore<Value>;
23
- type SetStoreValue<Value> = (value: Value | ((current: Value) => Value)) => void;
24
- declare function atom<Value>(initialValue: Value): Atom<Value>;
25
- declare function useStore<Value>(store: Store<Value>): Value;
26
- declare function useAtom<Value>(value: Atom<Value>): readonly [Value, SetStoreValue<Value>];
16
+ type SetStateAction<Value> = Value | ((current: Value) => Value);
17
+ type PrimitiveAtom<Value> = WritableAtom<Value, [SetStateAction<Value>], void>;
18
+ type Getter = <Value>(value: Atom<Value>) => Value;
19
+ type Setter = <Value, Args$1 extends unknown[], Result$1>(value: WritableAtom<Value, Args$1, Result$1>, ...args: Args$1) => Result$1;
20
+ type AtomOptions = {
21
+ storage?: string;
22
+ };
23
+ declare function atom<Value, Args$1 extends unknown[], Result$1>(read: (get: Getter) => Value, write: (get: Getter, set: Setter, ...args: Args$1) => Result$1): WritableAtom<Value, Args$1, Result$1>;
24
+ declare function atom<Value>(read: (get: Getter) => Value): Atom<Value>;
25
+ declare function atom<Value>(initialValue: Value, options?: AtomOptions): PrimitiveAtom<Value>;
26
+ declare function useAtomValue<Value>(value: Atom<Value>): Awaited<Value>;
27
+ declare function useSetAtom<Value, Args$1 extends unknown[], Result$1>(value: WritableAtom<Value, Args$1, Result$1>): (...args: Args$1) => Result$1;
28
+ declare function useAtom<Value, Args$1 extends unknown[], Result$1>(value: WritableAtom<Value, Args$1, Result$1>): [Awaited<Value>, (...args: Args$1) => Result$1];
27
29
  //#endregion
28
30
  //#region src/state/collection.d.ts
29
- type FieldRecord = Record<string, FieldValue | undefined>;
30
- type CollectionFields<Shape extends SchemaShape> = SchemaOutput<Shape>;
31
- type CollectionInput<Shape extends SchemaShape> = SchemaInput<Shape>;
32
- type CollectionData<Shape extends SchemaShape> = CollectionFields<Shape>;
33
- type CollectionFieldKey<Shape extends SchemaShape> = Extract<keyof Shape, string>;
34
- type CollectionFieldValue<Shape extends SchemaShape, Key extends CollectionFieldKey<Shape>> = Key extends keyof CollectionData<Shape> ? CollectionData<Shape>[Key] : undefined;
35
- type Entry<Value> = {
36
- value: Value | undefined;
37
- error: unknown;
38
- promise: Promise<unknown> | null;
39
- version: number;
40
- listeners: Set<Listener>;
41
- };
42
- type RawCollectionView = {
43
- id: string;
44
- collection: string;
45
- createdAt: string;
46
- updatedAt: string;
47
- data: FieldRecord;
48
- links: Record<string, string[]>;
49
- };
50
- type RecordEntry = Entry<RawCollectionView | null>;
51
- type ListEntry = Entry<string[]> & {
52
- dependencies: ListDependencies;
53
- };
54
- type CollectionReference = {
55
- readonly name: string;
56
- get(id: string): Promise<unknown>;
31
+ declare const collectionBrand: unique symbol;
32
+ type AnyShape = SchemaShape;
33
+ type AnyCollection = CollectionAtom<AnyShape>;
34
+ type Scalar = string | number | boolean;
35
+ type MaybePromise<Value> = Value | Promise<Value>;
36
+ type Order = 'asc' | 'desc';
37
+ type Comparison = 'equals' | 'greater-than' | 'less-than' | 'contains';
38
+ type ComparisonFor<Value> = Value extends number ? Exclude<Comparison, 'contains'> : Value extends string ? 'equals' | 'contains' : 'equals';
39
+ type WhereClauseValue<Value> = Value | readonly [ComparisonFor<Value>, Value] | ReadonlyArray<readonly [ComparisonFor<Value>, Value]>;
40
+ type ScalarFieldPath<Shape extends SchemaShape> = { [Key in Extract<keyof Shape, string>]: Shape[Key] extends {
41
+ kind: 'object';
42
+ shape: infer Nested extends SchemaShape;
43
+ } ? `${Key}.${ScalarFieldPath<Nested>}` : Shape[Key] extends {
44
+ kind: 'array';
45
+ } ? never : Key }[Extract<keyof Shape, string>];
46
+ type ScalarAtPath<Shape extends SchemaShape, Path$1 extends ScalarFieldPath<Shape>> = Path$1 extends `${infer Key}.${infer Rest}` ? Key extends keyof Shape ? Shape[Key] extends ObjectField<infer Nested> ? Rest extends ScalarFieldPath<Nested> ? ScalarAtPath<Nested, Rest> : never : never : never : Path$1 extends keyof Shape ? Extract<FieldOutput<Shape[Path$1]>, Scalar> : never;
47
+ type CollectionRow<Shape extends SchemaShape> = {
48
+ readonly id: string;
49
+ readonly collection: string;
50
+ readonly version: number;
51
+ readonly createdAt: string;
52
+ readonly updatedAt: string;
53
+ readonly data: SchemaOutput<Shape>;
54
+ readonly links: Readonly<Record<string, readonly string[]>>;
57
55
  };
58
- type ViewOptions = {
59
- links?: CollectionReference[];
56
+ interface CollectionAtom<Shape extends SchemaShape> extends Atom<Promise<readonly string[]>> {
57
+ readonly [collectionBrand]: Shape;
58
+ }
59
+ declare class CollectionVersionConflictError extends Error {
60
+ readonly collection: string;
61
+ readonly id: string;
62
+ readonly expectedVersion: number;
63
+ readonly actualVersion: number;
64
+ readonly name = "CollectionVersionConflictError";
65
+ constructor(collection: string, id: string, expectedVersion: number, actualVersion: number);
66
+ }
67
+ type UpdateOptions = {
68
+ ifVersion?: number;
60
69
  };
61
- type ListWhereValue = FieldValue | ['equals' | 'greater-than' | 'less-than' | 'contains', FieldValue] | Array<['equals' | 'greater-than' | 'less-than' | 'contains', FieldValue]>;
62
- type ListOptions<Shape extends SchemaShape> = {
63
- where?: Partial<Record<CollectionFieldKey<Shape>, ListWhereValue>>;
64
- sortBy?: CollectionFieldKey<Shape> | 'createdAt' | 'updatedAt';
65
- order?: 'asc' | 'desc';
66
- take?: number;
70
+ type RowOptions = {
71
+ links?: readonly AnyCollection[];
67
72
  };
68
- type NormalizedListOptions = {
69
- where?: Record<string, Array<[string, FieldValue]>>;
70
- sortBy?: string;
71
- order?: 'asc' | 'desc';
72
- take?: number;
73
+ type CollectionWhere<Shape extends SchemaShape> = Partial<{ [Path in ScalarFieldPath<Shape>]: WhereClauseValue<ScalarAtPath<Shape, Path>> }>;
74
+ type WhereClause = {
75
+ path: string;
76
+ comparison: Comparison;
77
+ operand: Scalar;
73
78
  };
74
- type RecordChange = {
75
- collection: string;
76
- id: string;
77
- previous: RawCollectionView | null;
78
- next: RawCollectionView | null;
79
- changedPaths: Set<string>;
80
- };
81
- type EdgeChange = {
82
- type: 'link' | 'unlink';
83
- left: {
79
+ type QueryPlan = {
80
+ terminal: 'ids' | 'row' | 'field';
81
+ where: WhereClause[];
82
+ from?: {
84
83
  collection: string;
85
84
  id: string;
86
85
  };
87
- right: {
88
- collection: string;
89
- id: string;
86
+ sort?: {
87
+ path: string;
88
+ order: Order;
90
89
  };
90
+ take?: number;
91
+ id?: string;
92
+ path?: string;
93
+ links?: string[];
91
94
  };
92
- type ListDependencies = {
93
- collection: string;
94
- paths: Set<string>;
95
- options: NormalizedListOptions;
95
+ type QueryTerminal<Shape extends SchemaShape, Result$1> = {
96
+ readonly plan: QueryPlan;
97
+ readonly result?: Result$1;
98
+ readonly shape?: Shape;
96
99
  };
97
- type CollectionView<Shape extends SchemaShape> = {
98
- readonly id: string;
99
- readonly collection: string;
100
- readonly createdAt: string;
101
- readonly updatedAt: string;
102
- readonly data: CollectionData<Shape>;
103
- readonly links: Record<string, string[]>;
100
+ interface QueryBuilder<Shape extends SchemaShape> {
101
+ where(filters: CollectionWhere<Shape>): QueryBuilder<Shape>;
102
+ from<OtherShape extends SchemaShape>(other: CollectionAtom<OtherShape>, id: string): QueryBuilder<Shape>;
103
+ sortBy(path: ScalarFieldPath<Shape> | 'createdAt' | 'updatedAt', order?: Order): QueryBuilder<Shape>;
104
+ take(count: number): QueryBuilder<Shape>;
105
+ ids(): QueryTerminal<Shape, readonly string[]>;
106
+ row(id: string, options?: RowOptions): QueryTerminal<Shape, CollectionRow<Shape> | null>;
107
+ field<Path$1 extends FieldPath<Shape>>(id: string, path: Path$1): QueryTerminal<Shape, ValueAtFieldPath<Shape, Path$1> | undefined>;
108
+ }
109
+ type InsertTerminal<Shape extends SchemaShape> = {
110
+ kind: 'insert';
111
+ args: [SchemaInput<Shape>];
112
+ result: string;
104
113
  };
105
- declare class Collection<Shape extends SchemaShape> {
106
- readonly name: string;
107
- readonly shape: Shape;
108
- readonly validator: BleamSchema<SchemaInput<Shape>, SchemaOutput<Shape>>;
109
- private records;
110
- private lists;
111
- private fields;
112
- constructor(name: string, shape: Shape);
113
- validateListOptions(options?: ListOptions<Shape>): void;
114
- getRecordEntry(id: string): RecordEntry;
115
- getListEntry(options?: ListOptions<Shape>): ListEntry;
116
- private getFieldEntry;
117
- private notifyFields;
118
- private setRecordValue;
119
- private rawRecord;
120
- private loadRecord;
121
- private loadListRows;
122
- private selectListRows;
123
- private applyListOptions;
124
- private refreshListEntry;
125
- invalidateChanges(recordChanges: RecordChange[], edgeChanges?: EdgeChange[]): Promise<void>;
126
- private refreshLoadedLinks;
127
- private peekRecord;
128
- insert(value: CollectionInput<Shape>): Promise<string>;
129
- update(id: string, value: Partial<CollectionInput<Shape>>): Promise<void>;
130
- delete(id: string): Promise<void>;
131
- all(): Promise<CollectionView<Shape>[]>;
132
- get(id: string): Promise<CollectionView<Shape> | null>;
133
- subscribeRecord(id: string, listener: Listener): () => void;
134
- subscribeList(options: ListOptions<Shape> | undefined, listener: Listener): () => void;
135
- subscribeField(id: string, path: string, listener: Listener): () => void;
136
- getRecordVersion(id: string): number;
137
- getListVersion(options?: ListOptions<Shape>): number;
138
- getFieldVersion(id: string, path: string): number;
139
- getRecordSnapshot(id: string, options?: ViewOptions): CollectionView<Shape> | null | undefined;
140
- getListSnapshot(options?: ListOptions<Shape>): string[] | undefined;
141
- ensureRecord(id: string, options?: ViewOptions): Promise<RawCollectionView | null>;
142
- ensureList(options?: ListOptions<Shape>): Promise<string[]>;
143
- private deleteLinksForRecord;
114
+ type UpdateTerminal<Shape extends SchemaShape> = {
115
+ kind: 'update';
116
+ id: string;
117
+ args: [SchemaPatch<Shape>, UpdateOptions?];
118
+ result: CollectionRow<Shape>;
119
+ };
120
+ type RemoveTerminal = {
121
+ kind: 'remove';
122
+ id: string;
123
+ args: [];
124
+ result: boolean;
125
+ };
126
+ type LinkTerminal = {
127
+ kind: 'link' | 'unlink';
128
+ id: string;
129
+ other: AnyCollection;
130
+ args: [string];
131
+ result: boolean;
132
+ };
133
+ type MutationTerminal<Shape extends SchemaShape> = InsertTerminal<Shape> | UpdateTerminal<Shape> | RemoveTerminal | LinkTerminal;
134
+ interface MutationBuilder<Shape extends SchemaShape> {
135
+ insert(): InsertTerminal<Shape>;
136
+ update(id: string): UpdateTerminal<Shape>;
137
+ remove(id: string): RemoveTerminal;
138
+ link<OtherShape extends SchemaShape>(id: string, other: CollectionAtom<OtherShape>): LinkTerminal;
139
+ unlink<OtherShape extends SchemaShape>(id: string, other: CollectionAtom<OtherShape>): LinkTerminal;
144
140
  }
145
- declare function collection<Shape extends SchemaShape>(name: string, shape: Shape): Collection<Shape>;
146
- declare function link<FirstShape extends SchemaShape, SecondShape extends SchemaShape>(firstCollection: Collection<FirstShape>, firstId: string, secondCollection: Collection<SecondShape>, secondId: string): Promise<void>;
147
- declare function unlink<FirstShape extends SchemaShape, SecondShape extends SchemaShape>(firstCollection: Collection<FirstShape>, firstId: string, secondCollection: Collection<SecondShape>, secondId: string): Promise<void>;
148
- declare function isLinked<FirstShape extends SchemaShape, SecondShape extends SchemaShape>(firstCollection: Collection<FirstShape>, firstId: string, secondCollection: Collection<SecondShape>, secondId: string): Promise<boolean>;
149
- declare function useList<Shape extends SchemaShape>(collection: Collection<Shape>, options?: ListOptions<Shape>): string[];
150
- declare function useView<Shape extends SchemaShape>(collection: Collection<Shape>, id: string, options?: ViewOptions): CollectionView<Shape> | null | undefined;
151
- declare function useField<Shape extends SchemaShape, Key extends CollectionFieldKey<Shape>>(collection: Collection<Shape>, id: string, key: Key): CollectionFieldValue<Shape, Key> | undefined;
152
- //#endregion
153
- //#region src/state/setting.d.ts
154
- type Setting<Value> = WritableStore<Value>;
155
- type SetSettingValue<Value> = SetStoreValue<Value>;
156
- declare function setting<Value extends string | number | boolean>(key: string, initialValue: Value): Setting<Value>;
157
- declare function useSetting<Value>(value: Setting<Value>): readonly [Value, SetStoreValue<Value>];
141
+ type TerminalArgs<Terminal> = Terminal extends {
142
+ args: infer Args extends unknown[];
143
+ } ? Args : never;
144
+ type TerminalResult<Terminal> = Terminal extends {
145
+ result: infer Result;
146
+ } ? Result : never;
147
+ declare function atomCollection<const Shape extends SchemaShape>(name: string, shape: Shape): CollectionAtom<Shape>;
148
+ declare function queryAtom<Shape extends SchemaShape, Result$1>(collection: CollectionAtom<Shape>, build: (builder: QueryBuilder<Shape>) => QueryTerminal<Shape, Result$1>): Atom<Promise<Result$1>>;
149
+ declare function mutateAtom<Shape extends SchemaShape, Terminal extends MutationTerminal<Shape>>(collection: CollectionAtom<Shape>, build: (builder: MutationBuilder<Shape>) => Terminal): WritableAtom<null, TerminalArgs<Terminal>, Promise<TerminalResult<Terminal>>>;
150
+ interface TransactionContext {
151
+ get<Shape extends SchemaShape>(collection: CollectionAtom<Shape>, id: string, options?: RowOptions): Promise<CollectionRow<Shape> | null>;
152
+ query<Shape extends SchemaShape, Result$1>(collection: CollectionAtom<Shape>, build: (builder: QueryBuilder<Shape>) => QueryTerminal<Shape, Result$1>): Promise<Result$1>;
153
+ insert<Shape extends SchemaShape>(collection: CollectionAtom<Shape>, value: SchemaInput<Shape>): Promise<string>;
154
+ update<Shape extends SchemaShape>(collection: CollectionAtom<Shape>, id: string, patch: SchemaPatch<Shape>, options?: UpdateOptions): Promise<CollectionRow<Shape>>;
155
+ remove<Shape extends SchemaShape>(collection: CollectionAtom<Shape>, id: string): Promise<boolean>;
156
+ link<LeftShape extends SchemaShape, RightShape extends SchemaShape>(collection: CollectionAtom<LeftShape>, id: string, other: CollectionAtom<RightShape>, otherId: string): Promise<boolean>;
157
+ unlink<LeftShape extends SchemaShape, RightShape extends SchemaShape>(collection: CollectionAtom<LeftShape>, id: string, other: CollectionAtom<RightShape>, otherId: string): Promise<boolean>;
158
+ }
159
+ declare function transactionAtom<Args$1 extends unknown[], Result$1>(action: (context: TransactionContext, ...args: Args$1) => MaybePromise<Result$1>): WritableAtom<null, Args$1, Promise<Result$1>>;
160
+ declare function useList<Shape extends SchemaShape>(collection: CollectionAtom<Shape>, build?: (builder: QueryBuilder<Shape>) => QueryTerminal<Shape, readonly string[]>): readonly string[];
161
+ declare function useRow<Shape extends SchemaShape>(collection: CollectionAtom<Shape>, id: string, options?: RowOptions): CollectionRow<Shape> | null;
162
+ declare function useField<Shape extends SchemaShape, Path$1 extends FieldPath<Shape>>(collection: CollectionAtom<Shape>, id: string, path: Path$1): ValueAtFieldPath<Shape, Path$1> | undefined;
158
163
  //#endregion
159
- export { Atom, Collection, CollectionView, ListOptions, Listener, LiveStore, SetSettingValue, SetStoreValue, Setting, Store, WritableStore, atom, collection, isLinked, link, setting, unlink, useAtom, useField, useList, useSetting, useStore, useView };
164
+ export { type Atom, type AtomOptions, CollectionAtom, CollectionRow, CollectionVersionConflictError, CollectionWhere, type Getter, MutationBuilder, type PrimitiveAtom, QueryBuilder, RowOptions, type SetStateAction, type Setter, TransactionContext, UpdateOptions, type WritableAtom, array, atom, atomCollection, boolean, literal, mutateAtom, number, object, queryAtom, string, transactionAtom, useAtom, useAtomValue, useField, useList, useRow, useSetAtom };
package/dist/state.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import "./native-runtime-C85Nuc4F.js";
2
2
  import "./crypto-BB92-Upx.js";
3
- import { a as isLinked, c as useField, d as LiveStore, f as atom, i as collection, l as useList, m as useStore, n as useSetting, o as link, p as useAtom, r as Collection, s as unlink, t as setting, u as useView } from "./state-CAwe-Vw1.js";
4
- import "./schema-Bo5Jvqus.js";
3
+ import "./app-storage-Isi5Bo0R.js";
4
+ import { c as object, n as array, o as literal, r as boolean, s as number, u as string } from "./schema-B7ELMpuI.js";
5
+ import { a as transactionAtom, c as useRow, h as useSetAtom, i as queryAtom, l as atom, m as useAtomValue, n as atomCollection, o as useField, p as useAtom, r as mutateAtom, s as useList, t as CollectionVersionConflictError } from "./state-DkaRFkZJ.js";
5
6
 
6
- export { Collection, LiveStore, atom, collection, isLinked, link, setting, unlink, useAtom, useField, useList, useSetting, useStore, useView };
7
+ export { CollectionVersionConflictError, array, atom, atomCollection, boolean, literal, mutateAtom, number, object, queryAtom, string, transactionAtom, useAtom, useAtomValue, useField, useList, useRow, useSetAtom };
package/dist/window.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { p as SymbolName } from "./ui-1WepaMS4.cjs";
1
+ import { n as SymbolName } from "./elements-CFk0QHw0.cjs";
2
2
  import * as react3 from "react";
3
3
  import { ComponentType } from "react";
4
4
  import { StyleProp, ViewStyle } from "react-native";
package/dist/window.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { p as SymbolName } from "./ui-CHc4xEs_.js";
2
- import * as react3 from "react";
1
+ import { n as SymbolName } from "./elements-ClGQ41Sc.js";
2
+ import * as react5 from "react";
3
3
  import { ComponentType } from "react";
4
4
  import { StyleProp, ViewStyle } from "react-native";
5
5
 
@@ -55,7 +55,7 @@ type SidebarNavigatorConfig<Routes extends SidebarScreenMap> = {
55
55
  style?: StyleProp<ViewStyle>;
56
56
  };
57
57
  declare function createSidebarNavigator<const Routes extends SidebarScreenMap>(config: SidebarNavigatorConfig<Routes>): {
58
- Navigator: () => react3.JSX.Element;
58
+ Navigator: () => react5.JSX.Element;
59
59
  useNavigation: () => SidebarNavigation<Routes>;
60
60
  useRoute: () => SidebarRouteState<Routes>;
61
61
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bleam",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "packageManager": "yarn@1.22.22",
5
5
  "type": "module",
6
6
  "files": [
@@ -35,6 +35,8 @@
35
35
  "@types/react": "~19.2.17",
36
36
  "expo": "57",
37
37
  "expo-splash-screen": "57.0.2",
38
+ "jotai": "2.20.2",
39
+ "jotai-family": "1.0.2",
38
40
  "react": "19.2.3",
39
41
  "react-native": "0.86.0",
40
42
  "tsx": "^4.21.0",
@@ -95,6 +97,11 @@
95
97
  "import": "./dist/dev-protocol.js",
96
98
  "require": "./dist/dev-protocol.cjs"
97
99
  },
100
+ "./elements": {
101
+ "types": "./dist/elements.d.ts",
102
+ "import": "./dist/elements.js",
103
+ "require": "./dist/elements.cjs"
104
+ },
98
105
  "./files": {
99
106
  "types": "./dist/files.d.ts",
100
107
  "import": "./dist/files.js",
@@ -115,6 +122,11 @@
115
122
  "import": "./dist/schema.js",
116
123
  "require": "./dist/schema.cjs"
117
124
  },
125
+ "./secrets": {
126
+ "types": "./dist/secrets.d.ts",
127
+ "import": "./dist/secrets.js",
128
+ "require": "./dist/secrets.cjs"
129
+ },
118
130
  "./state": {
119
131
  "types": "./dist/state.d.ts",
120
132
  "import": "./dist/state.js",
@@ -125,11 +137,6 @@
125
137
  "import": "./dist/styles.js",
126
138
  "require": "./dist/styles.cjs"
127
139
  },
128
- "./ui": {
129
- "types": "./dist/ui.d.ts",
130
- "import": "./dist/ui.js",
131
- "require": "./dist/ui.cjs"
132
- },
133
140
  "./window": {
134
141
  "types": "./dist/window.d.ts",
135
142
  "import": "./dist/window.js",
@@ -1,6 +1,6 @@
1
+ import { Button } from 'bleam/elements'
1
2
  import { atom, useAtom } from 'bleam/state'
2
3
  import { sx } from 'bleam/styles'
3
- import { Button } from 'bleam/ui'
4
4
  import { Toolbar, Window } from 'bleam/window'
5
5
  import { Text, View } from 'react-native'
6
6
 
@@ -125,7 +125,7 @@ export default function App() {
125
125
  </View>
126
126
 
127
127
  <Button
128
- title={`Count is ${count}`}
128
+ label={`Count is ${count}`}
129
129
  variant="secondary"
130
130
  size="regular"
131
131
  onPress={() => setCount((value) => value + 1)}
@@ -1,32 +1,94 @@
1
- import { generate } from 'bleam/ai'
1
+ import { chat, useChat, useChatList } from 'bleam/ai'
2
+ import { Button } from 'bleam/elements'
2
3
  import { sx } from 'bleam/styles'
3
- import { Button } from 'bleam/ui'
4
4
  import { Window } from 'bleam/window'
5
- import { useState } from 'react'
6
- import { Text, View } from 'react-native'
5
+ import { useEffect, useRef, useState } from 'react'
6
+ import { Text, TextInput, View } from 'react-native'
7
7
 
8
8
  const appName = 'Bleam Basic'
9
9
 
10
10
  export default function App() {
11
- const [answer, setAnswer] = useState('Ask the on-device model for an idea.')
11
+ const chats = useChatList()
12
+ const creating = useRef(false)
13
+ const [error, setError] = useState('')
12
14
 
13
- async function ask() {
14
- setAnswer('Thinking...')
15
- try {
16
- setAnswer(
17
- await generate({ prompt: 'Suggest one useful native Mac app.' }),
15
+ useEffect(() => {
16
+ if (chats.length > 0 || creating.current) return
17
+ creating.current = true
18
+ void chat
19
+ .create({ title: 'App ideas' })
20
+ .catch((nextError) =>
21
+ setError(
22
+ nextError instanceof Error ? nextError.message : String(nextError),
23
+ ),
18
24
  )
19
- } catch (error) {
20
- setAnswer(error instanceof Error ? error.message : String(error))
21
- }
22
- }
25
+ }, [chats.length])
23
26
 
24
27
  return (
25
28
  <View style={sx('flex-1', 'p-8', 'gap-6')}>
26
29
  <Window title={appName} />
27
30
  <Text style={sx('text-3xl', 'font-semibold')}>Foundation Models</Text>
28
- <Text style={sx('text-lg', 'text-secondary-label')}>{answer}</Text>
29
- <Button title="Generate an idea" onPress={ask} />
31
+ <Text style={sx('text-secondary-label')}>
32
+ Chats persist on this Mac and use Apple Foundation Models by default.
33
+ </Text>
34
+ {error ? <Text style={sx('text-system-red')}>{error}</Text> : null}
35
+ {chats[0] ? (
36
+ <Conversation id={chats[0].id} />
37
+ ) : (
38
+ <Text>Creating chat...</Text>
39
+ )}
40
+ </View>
41
+ )
42
+ }
43
+
44
+ function Conversation({ id }: { id: string }) {
45
+ const conversation = useChat(id, {
46
+ system: 'You suggest practical, concise native Mac app ideas.',
47
+ })
48
+ const [prompt, setPrompt] = useState('Suggest one useful native Mac app.')
49
+ const latestAssistant = conversation.messages.findLast(
50
+ (message) => message.role === 'assistant',
51
+ )
52
+ const retryable =
53
+ latestAssistant?.status === 'failed' ||
54
+ latestAssistant?.status === 'canceled'
55
+ ? latestAssistant
56
+ : null
57
+
58
+ return (
59
+ <View style={sx('gap-4')}>
60
+ <TextInput
61
+ value={prompt}
62
+ onChangeText={setPrompt}
63
+ style={sx('rounded-xl', 'border', 'border-separator', 'p-4')}
64
+ />
65
+ <View style={sx('flex-row', 'gap-3')}>
66
+ <Button
67
+ label="Send"
68
+ loading={conversation.isGenerating}
69
+ disabled={!conversation.canSend}
70
+ onPress={() => void conversation.send(prompt)}
71
+ />
72
+ <Button
73
+ label="Cancel"
74
+ variant="secondary"
75
+ disabled={!conversation.canCancel}
76
+ onPress={() => void conversation.cancel()}
77
+ />
78
+ {retryable ? (
79
+ <Button
80
+ label="Retry"
81
+ variant="secondary"
82
+ onPress={() => void conversation.retry(retryable.id)}
83
+ />
84
+ ) : null}
85
+ </View>
86
+ {conversation.messages.map((message) => (
87
+ <Text key={message.id} style={sx('text-lg', 'text-label')}>
88
+ {message.role === 'user' ? 'You: ' : 'Assistant: '}
89
+ {message.content || message.status}
90
+ </Text>
91
+ ))}
30
92
  </View>
31
93
  )
32
94
  }
@@ -1,6 +1,6 @@
1
- import { bonsai, generateImage } from 'bleam/ai'
1
+ import { bonsai, image } from 'bleam/ai'
2
+ import { Button } from 'bleam/elements'
2
3
  import { sx } from 'bleam/styles'
3
- import { Button } from 'bleam/ui'
4
4
  import { Window } from 'bleam/window'
5
5
  import { useState } from 'react'
6
6
  import { Image, Text, View } from 'react-native'
@@ -15,7 +15,7 @@ export default function App() {
15
15
  async function create() {
16
16
  setStatus('Generating...')
17
17
  try {
18
- const result = await generateImage({
18
+ const result = await image.generate({
19
19
  model,
20
20
  prompt: 'A precise editorial illustration of a small native Mac app',
21
21
  aspectRatio: '1:1',
@@ -35,7 +35,7 @@ export default function App() {
35
35
  <Image source={{ uri }} style={sx('w-96', 'h-96', 'rounded-xl')} />
36
36
  ) : null}
37
37
  <Text style={sx('text-secondary-label')}>{status}</Text>
38
- <Button title="Generate image" onPress={create} />
38
+ <Button label="Generate image" onPress={create} />
39
39
  </View>
40
40
  )
41
41
  }