@rozenite/storage-plugin 2.1.0 → 2.3.0
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/CHANGELOG.md +34 -0
- package/dist/devtools/assets/panel-CcThj-0Z.js +32 -0
- package/dist/devtools/assets/panel-DTYbHqnH.css +1 -0
- package/dist/devtools/panel.html +2 -2
- package/dist/react-native/cjs/package.json +3 -0
- package/dist/react-native/cjs/react-native.js +38 -0
- package/dist/react-native/cjs/src/react-native/adapters/async-storage.js +60 -0
- package/dist/react-native/cjs/src/react-native/adapters/index.js +10 -0
- package/dist/react-native/cjs/src/react-native/adapters/mmkv.js +143 -0
- package/dist/react-native/cjs/src/react-native/adapters/secure-storage.js +51 -0
- package/dist/react-native/cjs/src/react-native/entry-preview-pagination.js +198 -0
- package/dist/react-native/cjs/src/react-native/export-snapshot.js +70 -0
- package/dist/react-native/cjs/src/react-native/full-entry-request.js +72 -0
- package/dist/react-native/cjs/src/react-native/import.js +185 -0
- package/dist/react-native/cjs/src/react-native/storage-discovery.js +69 -0
- package/dist/react-native/cjs/src/react-native/storage-view.js +128 -0
- package/dist/react-native/cjs/src/react-native/useRozeniteStoragePlugin.js +145 -0
- package/dist/react-native/cjs/src/react-native/useStorageAgentTools.js +228 -0
- package/dist/react-native/cjs/src/shared/agent-tools.js +119 -0
- package/dist/react-native/cjs/src/shared/entry-preview.js +48 -0
- package/dist/react-native/cjs/src/shared/messaging.js +2 -0
- package/dist/react-native/cjs/src/shared/snapshot.js +185 -0
- package/dist/react-native/cjs/src/shared/types.js +13 -0
- package/dist/react-native/package.json +3 -0
- package/dist/react-native/react-native.d.ts +7 -0
- package/dist/react-native/react-native.js +40 -0
- package/dist/react-native/src/react-native/adapters/async-storage.d.ts +34 -0
- package/dist/react-native/src/react-native/adapters/async-storage.js +56 -0
- package/dist/react-native/src/react-native/adapters/index.d.ts +6 -0
- package/dist/react-native/src/react-native/adapters/index.js +3 -0
- package/dist/react-native/src/react-native/adapters/mmkv.d.ts +13 -0
- package/dist/react-native/src/react-native/adapters/mmkv.js +139 -0
- package/dist/react-native/src/react-native/adapters/secure-storage.d.ts +18 -0
- package/dist/react-native/src/react-native/adapters/secure-storage.js +47 -0
- package/dist/react-native/src/react-native/entry-preview-pagination.d.ts +7 -0
- package/dist/react-native/src/react-native/entry-preview-pagination.js +194 -0
- package/dist/react-native/src/react-native/export-snapshot.d.ts +5 -0
- package/dist/react-native/src/react-native/export-snapshot.js +66 -0
- package/dist/react-native/src/react-native/full-entry-request.d.ts +5 -0
- package/dist/react-native/src/react-native/full-entry-request.js +68 -0
- package/dist/react-native/src/react-native/import.d.ts +7 -0
- package/dist/react-native/src/react-native/import.js +180 -0
- package/dist/react-native/src/react-native/storage-discovery.d.ts +5 -0
- package/dist/react-native/src/react-native/storage-discovery.js +65 -0
- package/dist/react-native/src/react-native/storage-view.d.ts +19 -0
- package/dist/react-native/src/react-native/storage-view.js +123 -0
- package/dist/react-native/src/react-native/useRozeniteStoragePlugin.d.ts +6 -0
- package/dist/react-native/src/react-native/useRozeniteStoragePlugin.js +141 -0
- package/dist/react-native/src/react-native/useStorageAgentTools.d.ts +37 -0
- package/dist/react-native/src/react-native/useStorageAgentTools.js +223 -0
- package/dist/react-native/src/shared/agent-tools.d.ts +76 -0
- package/dist/react-native/src/shared/agent-tools.js +116 -0
- package/dist/react-native/src/shared/entry-preview.d.ts +4 -0
- package/dist/react-native/src/shared/entry-preview.js +44 -0
- package/dist/react-native/src/shared/messaging.d.ts +134 -0
- package/dist/react-native/src/shared/messaging.js +1 -0
- package/dist/react-native/src/shared/snapshot.d.ts +53 -0
- package/dist/react-native/src/shared/snapshot.js +179 -0
- package/dist/react-native/src/shared/types.d.ts +78 -0
- package/dist/react-native/src/shared/types.js +8 -0
- package/dist/rozenite.json +1 -1
- package/dist/sdk/package.json +3 -0
- package/dist/sdk/sdk.d.ts +44 -0
- package/dist/sdk/sdk.js +9 -0
- package/dist/sdk/src/shared/agent-tools.d.ts +76 -0
- package/dist/sdk/src/shared/agent-tools.js +119 -0
- package/dist/sdk/src/shared/types.d.ts +78 -0
- package/dist/sdk/src/shared/types.js +13 -0
- package/package.json +16 -16
- package/react-native.ts +8 -1
- package/rozenite.config.ts +1 -0
- package/src/__tests__/release-bundle.test.ts +32 -0
- package/src/ui/__tests__/panel.test.tsx +14 -0
- package/src/ui/add-entry-dialog.tsx +63 -73
- package/src/ui/binary-value-editor.tsx +1 -1
- package/src/ui/edit-entry-dialog.tsx +59 -70
- package/src/ui/entry-detail-dialog.tsx +4 -2
- package/src/ui/format-value.tsx +1 -1
- package/src/ui/import-dialog.tsx +5 -5
- package/src/ui/panel.tsx +70 -88
- package/tsconfig.json +4 -7
- package/dist/devtools/assets/panel-BlDRXgVW.js +0 -32
- package/dist/devtools/assets/panel-DBweZnW5.css +0 -1
- package/dist/react-native/chunks/async-storage.require.cjs +0 -1
- package/dist/react-native/chunks/async-storage.require.js +0 -53
- package/dist/react-native/chunks/index.require.cjs +0 -1
- package/dist/react-native/chunks/index.require.js +0 -103
- package/dist/react-native/chunks/secure-storage.require.cjs +0 -1
- package/dist/react-native/chunks/secure-storage.require.js +0 -46
- package/dist/react-native/chunks/types.cjs +0 -1
- package/dist/react-native/chunks/types.js +0 -11
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.cjs +0 -1
- package/dist/react-native/chunks/useRozeniteStoragePlugin.require.js +0 -1037
- package/dist/react-native/index.cjs +0 -1
- package/dist/react-native/index.d.ts +0 -365
- package/dist/react-native/index.js +0 -28
- package/dist/sdk/index.cjs +0 -1
- package/dist/sdk/index.d.ts +0 -206
- package/dist/sdk/index.js +0 -122
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { DEFAULT_SUPPORTED_TYPES, supportsType, } from './types';
|
|
2
|
+
const PLUGIN_ID = '@rozenite/storage-plugin';
|
|
3
|
+
const SUPPORTED_VERSION = 1;
|
|
4
|
+
class ParseException extends Error {
|
|
5
|
+
constructor(path, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.path = path;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const describe = (value) => {
|
|
11
|
+
if (value === null)
|
|
12
|
+
return 'null';
|
|
13
|
+
if (Array.isArray(value))
|
|
14
|
+
return 'array';
|
|
15
|
+
return typeof value;
|
|
16
|
+
};
|
|
17
|
+
const isPlainObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
18
|
+
const expectObject = (value, path) => {
|
|
19
|
+
if (!isPlainObject(value)) {
|
|
20
|
+
throw new ParseException(path, `Expected object, got ${describe(value)}`);
|
|
21
|
+
}
|
|
22
|
+
return value;
|
|
23
|
+
};
|
|
24
|
+
const expectString = (value, path) => {
|
|
25
|
+
if (typeof value !== 'string') {
|
|
26
|
+
throw new ParseException(path, `Expected string, got ${describe(value)}`);
|
|
27
|
+
}
|
|
28
|
+
return value;
|
|
29
|
+
};
|
|
30
|
+
const expectArray = (value, path) => {
|
|
31
|
+
if (!Array.isArray(value)) {
|
|
32
|
+
throw new ParseException(path, `Expected array, got ${describe(value)}`);
|
|
33
|
+
}
|
|
34
|
+
return value;
|
|
35
|
+
};
|
|
36
|
+
const expectEntryType = (value, path) => {
|
|
37
|
+
if (typeof value !== 'string' || !DEFAULT_SUPPORTED_TYPES.includes(value)) {
|
|
38
|
+
throw new ParseException(path, `Expected one of ${DEFAULT_SUPPORTED_TYPES.join(', ')}, got ${describe(value)}`);
|
|
39
|
+
}
|
|
40
|
+
return value;
|
|
41
|
+
};
|
|
42
|
+
const parseCapabilities = (raw, path) => {
|
|
43
|
+
const obj = expectObject(raw, path);
|
|
44
|
+
const supported = expectArray(obj.supportedTypes, `${path}.supportedTypes`);
|
|
45
|
+
const supportedTypes = supported.map((type, index) => expectEntryType(type, `${path}.supportedTypes[${index}]`));
|
|
46
|
+
return { supportedTypes };
|
|
47
|
+
};
|
|
48
|
+
const parseStorageMeta = (raw) => {
|
|
49
|
+
const obj = expectObject(raw, 'storage');
|
|
50
|
+
return {
|
|
51
|
+
adapterId: expectString(obj.adapterId, 'storage.adapterId'),
|
|
52
|
+
storageId: expectString(obj.storageId, 'storage.storageId'),
|
|
53
|
+
adapterName: expectString(obj.adapterName, 'storage.adapterName'),
|
|
54
|
+
storageName: expectString(obj.storageName, 'storage.storageName'),
|
|
55
|
+
capabilities: parseCapabilities(obj.capabilities, 'storage.capabilities'),
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const parseEntry = (raw, path) => {
|
|
59
|
+
const obj = expectObject(raw, path);
|
|
60
|
+
const key = expectString(obj.key, `${path}.key`);
|
|
61
|
+
const type = expectEntryType(obj.type, `${path}.type`);
|
|
62
|
+
const valuePath = `${path}.value`;
|
|
63
|
+
switch (type) {
|
|
64
|
+
case 'string': {
|
|
65
|
+
const value = obj.value;
|
|
66
|
+
if (typeof value !== 'string') {
|
|
67
|
+
throw new ParseException(valuePath, `Expected string for type "string", got ${describe(value)}`);
|
|
68
|
+
}
|
|
69
|
+
return { key, type: 'string', value };
|
|
70
|
+
}
|
|
71
|
+
case 'number': {
|
|
72
|
+
const value = obj.value;
|
|
73
|
+
if (typeof value !== 'number' || !Number.isFinite(value)) {
|
|
74
|
+
throw new ParseException(valuePath, `Expected finite number for type "number", got ${describe(value)}`);
|
|
75
|
+
}
|
|
76
|
+
return { key, type: 'number', value };
|
|
77
|
+
}
|
|
78
|
+
case 'boolean': {
|
|
79
|
+
const value = obj.value;
|
|
80
|
+
if (typeof value !== 'boolean') {
|
|
81
|
+
throw new ParseException(valuePath, `Expected boolean for type "boolean", got ${describe(value)}`);
|
|
82
|
+
}
|
|
83
|
+
return { key, type: 'boolean', value };
|
|
84
|
+
}
|
|
85
|
+
case 'buffer': {
|
|
86
|
+
const value = obj.value;
|
|
87
|
+
if (!Array.isArray(value)) {
|
|
88
|
+
throw new ParseException(valuePath, `Expected number[] for type "buffer", got ${describe(value)}`);
|
|
89
|
+
}
|
|
90
|
+
const bytes = value.map((byte, index) => {
|
|
91
|
+
if (typeof byte !== 'number' || !Number.isInteger(byte) || byte < 0 || byte > 255) {
|
|
92
|
+
throw new ParseException(`${valuePath}[${index}]`, `Expected uint8 (integer 0-255), got ${describe(byte)}`);
|
|
93
|
+
}
|
|
94
|
+
return byte;
|
|
95
|
+
});
|
|
96
|
+
return { key, type: 'buffer', value: bytes };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
export const parseSnapshot = (raw) => {
|
|
101
|
+
try {
|
|
102
|
+
const root = expectObject(raw, '$');
|
|
103
|
+
const version = root.version;
|
|
104
|
+
if (version !== SUPPORTED_VERSION) {
|
|
105
|
+
throw new ParseException('version', `Unsupported snapshot version: ${describe(version)} (this build supports version ${SUPPORTED_VERSION})`);
|
|
106
|
+
}
|
|
107
|
+
const plugin = expectString(root.plugin, 'plugin');
|
|
108
|
+
const createdAt = expectString(root.createdAt, 'createdAt');
|
|
109
|
+
const storage = parseStorageMeta(root.storage);
|
|
110
|
+
const rawEntries = expectArray(root.entries, 'entries');
|
|
111
|
+
const entries = rawEntries.map((entry, index) => parseEntry(entry, `entries[${index}]`));
|
|
112
|
+
return {
|
|
113
|
+
ok: true,
|
|
114
|
+
snapshot: {
|
|
115
|
+
version: SUPPORTED_VERSION,
|
|
116
|
+
plugin,
|
|
117
|
+
createdAt,
|
|
118
|
+
storage,
|
|
119
|
+
entries,
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
if (error instanceof ParseException) {
|
|
125
|
+
return { ok: false, error: { path: error.path, message: error.message } };
|
|
126
|
+
}
|
|
127
|
+
throw error;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
export const buildSnapshot = (args) => ({
|
|
131
|
+
version: 1,
|
|
132
|
+
plugin: PLUGIN_ID,
|
|
133
|
+
createdAt: new Date().toISOString(),
|
|
134
|
+
storage: {
|
|
135
|
+
adapterId: args.target.adapterId,
|
|
136
|
+
storageId: args.target.storageId,
|
|
137
|
+
adapterName: args.adapterName,
|
|
138
|
+
storageName: args.storageName,
|
|
139
|
+
capabilities: args.capabilities,
|
|
140
|
+
},
|
|
141
|
+
entries: args.entries,
|
|
142
|
+
});
|
|
143
|
+
export const computePreview = (snapshot, current) => {
|
|
144
|
+
const newKeys = [];
|
|
145
|
+
const overwriteKeys = [];
|
|
146
|
+
const skippedKeys = [];
|
|
147
|
+
const unsupportedTypes = [];
|
|
148
|
+
const acceptedEntryIndexes = [];
|
|
149
|
+
for (const [index, entry] of snapshot.entries.entries()) {
|
|
150
|
+
if (!supportsType(current.capabilities, entry.type)) {
|
|
151
|
+
unsupportedTypes.push({ key: entry.key, type: entry.type });
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (current.isBlacklisted(entry.key)) {
|
|
155
|
+
skippedKeys.push({ key: entry.key, reason: 'blacklist' });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
if (current.entryKeys.has(entry.key)) {
|
|
159
|
+
overwriteKeys.push(entry.key);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
newKeys.push(entry.key);
|
|
163
|
+
}
|
|
164
|
+
acceptedEntryIndexes.push(index);
|
|
165
|
+
// Duplicate keys are applied in source order, so every accepted duplicate
|
|
166
|
+
// after the first overwrites the value that preceded it in this import.
|
|
167
|
+
current.entryKeys.add(entry.key);
|
|
168
|
+
}
|
|
169
|
+
const metadataMismatch = snapshot.storage.adapterId !== current.target.adapterId ||
|
|
170
|
+
snapshot.storage.storageId !== current.target.storageId;
|
|
171
|
+
return {
|
|
172
|
+
newKeys,
|
|
173
|
+
overwriteKeys,
|
|
174
|
+
skippedKeys,
|
|
175
|
+
unsupportedTypes,
|
|
176
|
+
acceptedEntryIndexes,
|
|
177
|
+
metadataMismatch,
|
|
178
|
+
};
|
|
179
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type StorageEntry = {
|
|
2
|
+
key: string;
|
|
3
|
+
type: 'string';
|
|
4
|
+
value: string;
|
|
5
|
+
} | {
|
|
6
|
+
key: string;
|
|
7
|
+
type: 'number';
|
|
8
|
+
value: number;
|
|
9
|
+
} | {
|
|
10
|
+
key: string;
|
|
11
|
+
type: 'boolean';
|
|
12
|
+
value: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
key: string;
|
|
15
|
+
type: 'buffer';
|
|
16
|
+
value: number[];
|
|
17
|
+
};
|
|
18
|
+
export type StorageEntryType = StorageEntry['type'];
|
|
19
|
+
export type StorageEntryValue = StorageEntry['value'];
|
|
20
|
+
export type StorageEntryPreview = {
|
|
21
|
+
key: string;
|
|
22
|
+
type: StorageEntryType;
|
|
23
|
+
preview: string;
|
|
24
|
+
valueSize: number;
|
|
25
|
+
isTruncated: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type StorageCapabilities = {
|
|
28
|
+
supportedTypes: StorageEntryType[];
|
|
29
|
+
};
|
|
30
|
+
export type StorageDescriptor = {
|
|
31
|
+
target: StorageTarget;
|
|
32
|
+
adapterName: string;
|
|
33
|
+
storageName: string;
|
|
34
|
+
entryCount: number;
|
|
35
|
+
capabilities: StorageCapabilities;
|
|
36
|
+
supportsSubscriptions: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type StorageSubscription = {
|
|
39
|
+
remove: () => void;
|
|
40
|
+
};
|
|
41
|
+
export type SyncStorage = {
|
|
42
|
+
kind: 'sync';
|
|
43
|
+
getAllKeys: () => string[];
|
|
44
|
+
get: (key: string) => StorageEntry | undefined;
|
|
45
|
+
set: (entry: StorageEntry) => void;
|
|
46
|
+
delete: (key: string) => void;
|
|
47
|
+
clear: () => void;
|
|
48
|
+
subscribe?: (callback: (key: string) => void) => StorageSubscription;
|
|
49
|
+
};
|
|
50
|
+
export type AsyncStorage = {
|
|
51
|
+
kind: 'async';
|
|
52
|
+
getAllKeys: () => Promise<readonly string[]>;
|
|
53
|
+
get: (key: string) => Promise<StorageEntry | undefined>;
|
|
54
|
+
set: (entry: StorageEntry) => Promise<void>;
|
|
55
|
+
delete: (key: string) => Promise<void>;
|
|
56
|
+
clear: () => Promise<void>;
|
|
57
|
+
subscribe?: (callback: (key: string) => void) => StorageSubscription;
|
|
58
|
+
};
|
|
59
|
+
export type StorageNode = {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
storage: SyncStorage | AsyncStorage;
|
|
63
|
+
capabilities: StorageCapabilities;
|
|
64
|
+
blacklist?: RegExp;
|
|
65
|
+
shouldFilterKey?: (key: string) => boolean;
|
|
66
|
+
};
|
|
67
|
+
export type StorageAdapter = {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
storages: StorageNode[];
|
|
71
|
+
};
|
|
72
|
+
export type StorageTarget = {
|
|
73
|
+
adapterId: string;
|
|
74
|
+
storageId: string;
|
|
75
|
+
};
|
|
76
|
+
export declare const DEFAULT_SUPPORTED_TYPES: StorageEntryType[];
|
|
77
|
+
export declare const getStorageViewId: ({ adapterId, storageId }: StorageTarget) => string;
|
|
78
|
+
export declare const supportsType: (capabilities: StorageCapabilities, type: StorageEntryType) => boolean;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const DEFAULT_SUPPORTED_TYPES = [
|
|
2
|
+
'string',
|
|
3
|
+
'number',
|
|
4
|
+
'boolean',
|
|
5
|
+
'buffer',
|
|
6
|
+
];
|
|
7
|
+
export const getStorageViewId = ({ adapterId, storageId }) => `${adapterId}:${storageId}`;
|
|
8
|
+
export const supportsType = (capabilities, type) => capabilities.supportedTypes.includes(type);
|
package/dist/rozenite.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name":"@rozenite/storage-plugin","version":"2.
|
|
1
|
+
{"name":"@rozenite/storage-plugin","version":"2.3.0","description":"Generic Storage Inspector for Rozenite.","panels":[{"name":"Storage","source":"/devtools/panel.html"}],"integrations":["react-native"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { STORAGE_AGENT_ENTRY_TYPES, STORAGE_AGENT_PLUGIN_ID, storageToolDefinitions } from './src/shared/agent-tools.js';
|
|
2
|
+
export { STORAGE_AGENT_ENTRY_TYPES, STORAGE_AGENT_PLUGIN_ID, storageToolDefinitions };
|
|
3
|
+
export declare const storageTools: {
|
|
4
|
+
readonly listStorages: import("@rozenite/agent-shared").AgentToolDescriptor<undefined, import("./src/shared/agent-tools.js").StorageListStoragesResult>;
|
|
5
|
+
readonly listEntries: import("@rozenite/agent-shared").AgentToolDescriptor<import("./src/shared/agent-tools.js").StorageListEntriesArgs, import("./src/shared/agent-tools.js").StorageListEntriesResult>;
|
|
6
|
+
readonly readEntry: import("@rozenite/agent-shared").AgentToolDescriptor<import("./src/shared/agent-tools.js").StorageReadEntryArgs, import("./src/shared/agent-tools.js").StorageReadEntryResult>;
|
|
7
|
+
readonly createEntry: import("@rozenite/agent-shared").AgentToolDescriptor<(Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
8
|
+
key: string;
|
|
9
|
+
type: "string";
|
|
10
|
+
value: string;
|
|
11
|
+
}) | (Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
12
|
+
key: string;
|
|
13
|
+
type: "number";
|
|
14
|
+
value: number;
|
|
15
|
+
}) | (Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
16
|
+
key: string;
|
|
17
|
+
type: "boolean";
|
|
18
|
+
value: boolean;
|
|
19
|
+
}) | (Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
20
|
+
key: string;
|
|
21
|
+
type: "buffer";
|
|
22
|
+
value: number[];
|
|
23
|
+
}), import("./src/shared/agent-tools.js").StorageCreateEntryResult>;
|
|
24
|
+
readonly editEntry: import("@rozenite/agent-shared").AgentToolDescriptor<(Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
25
|
+
key: string;
|
|
26
|
+
type: "string";
|
|
27
|
+
value: string;
|
|
28
|
+
}) | (Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
29
|
+
key: string;
|
|
30
|
+
type: "number";
|
|
31
|
+
value: number;
|
|
32
|
+
}) | (Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
33
|
+
key: string;
|
|
34
|
+
type: "boolean";
|
|
35
|
+
value: boolean;
|
|
36
|
+
}) | (Partial<import("./src/shared/types.js").StorageTarget> & {
|
|
37
|
+
key: string;
|
|
38
|
+
type: "buffer";
|
|
39
|
+
value: number[];
|
|
40
|
+
}), import("./src/shared/agent-tools.js").StorageEditEntryResult>;
|
|
41
|
+
readonly removeEntry: import("@rozenite/agent-shared").AgentToolDescriptor<import("./src/shared/agent-tools.js").StorageRemoveEntryArgs, import("./src/shared/agent-tools.js").StorageRemoveEntryResult>;
|
|
42
|
+
};
|
|
43
|
+
export type { StorageCreateEntryArgs, StorageCreateEntryResult, StorageEditEntryArgs, StorageEditEntryResult, StorageListEntriesArgs, StorageListEntriesResult, StorageListStoragesArgs, StorageListStoragesItem, StorageListStoragesResult, StorageReadEntryArgs, StorageReadEntryResult, StorageRemoveEntryArgs, StorageRemoveEntryResult, StorageWriteEntryArgs, } from './src/shared/agent-tools.js';
|
|
44
|
+
export type { StorageAdapter, StorageCapabilities, StorageEntry, StorageEntryType, StorageEntryValue, StorageNode, StorageTarget, } from './src/shared/types.js';
|
package/dist/sdk/sdk.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.storageTools = exports.storageToolDefinitions = exports.STORAGE_AGENT_PLUGIN_ID = exports.STORAGE_AGENT_ENTRY_TYPES = void 0;
|
|
4
|
+
const agent_shared_1 = require("@rozenite/agent-shared");
|
|
5
|
+
const agent_tools_js_1 = require("./src/shared/agent-tools.js");
|
|
6
|
+
Object.defineProperty(exports, "STORAGE_AGENT_ENTRY_TYPES", { enumerable: true, get: function () { return agent_tools_js_1.STORAGE_AGENT_ENTRY_TYPES; } });
|
|
7
|
+
Object.defineProperty(exports, "STORAGE_AGENT_PLUGIN_ID", { enumerable: true, get: function () { return agent_tools_js_1.STORAGE_AGENT_PLUGIN_ID; } });
|
|
8
|
+
Object.defineProperty(exports, "storageToolDefinitions", { enumerable: true, get: function () { return agent_tools_js_1.storageToolDefinitions; } });
|
|
9
|
+
exports.storageTools = (0, agent_shared_1.defineAgentToolDescriptors)(agent_tools_js_1.STORAGE_AGENT_PLUGIN_ID, agent_tools_js_1.storageToolDefinitions);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { type AgentToolContract } from '@rozenite/agent-shared';
|
|
2
|
+
import type { StorageEntry, StorageEntryType, StorageTarget } from './types';
|
|
3
|
+
type StorageSelection = Partial<StorageTarget>;
|
|
4
|
+
export declare const STORAGE_AGENT_PLUGIN_ID = "@rozenite/storage-plugin";
|
|
5
|
+
export declare const STORAGE_AGENT_ENTRY_TYPES: readonly ["string", "number", "boolean", "buffer"];
|
|
6
|
+
export type StorageListStoragesArgs = undefined;
|
|
7
|
+
export type StorageListStoragesItem = {
|
|
8
|
+
adapterId: string;
|
|
9
|
+
storageId: string;
|
|
10
|
+
adapterName: string;
|
|
11
|
+
storageName: string;
|
|
12
|
+
supportedTypes: StorageEntryType[];
|
|
13
|
+
};
|
|
14
|
+
export type StorageListStoragesResult = {
|
|
15
|
+
storages: StorageListStoragesItem[];
|
|
16
|
+
};
|
|
17
|
+
export type StorageListEntriesArgs = StorageSelection & {
|
|
18
|
+
limit?: number;
|
|
19
|
+
cursor?: string;
|
|
20
|
+
/** @deprecated Use the opaque cursor returned by a previous page. */
|
|
21
|
+
offset?: number;
|
|
22
|
+
};
|
|
23
|
+
export type StorageListEntriesResult = {
|
|
24
|
+
adapterId: string;
|
|
25
|
+
storageId: string;
|
|
26
|
+
total: number;
|
|
27
|
+
items: Array<{
|
|
28
|
+
key: string;
|
|
29
|
+
}>;
|
|
30
|
+
page: {
|
|
31
|
+
limit: number;
|
|
32
|
+
hasMore: boolean;
|
|
33
|
+
nextCursor?: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type StorageReadEntryArgs = StorageSelection & {
|
|
37
|
+
key: string;
|
|
38
|
+
};
|
|
39
|
+
export type StorageReadEntryResult = {
|
|
40
|
+
adapterId: string;
|
|
41
|
+
storageId: string;
|
|
42
|
+
entry: StorageEntry;
|
|
43
|
+
};
|
|
44
|
+
export type StorageWriteEntryArgs = StorageSelection & StorageEntry;
|
|
45
|
+
export type StorageCreateEntryArgs = StorageWriteEntryArgs;
|
|
46
|
+
export type StorageCreateEntryResult = {
|
|
47
|
+
adapterId: string;
|
|
48
|
+
storageId: string;
|
|
49
|
+
created: true;
|
|
50
|
+
key: string;
|
|
51
|
+
};
|
|
52
|
+
export type StorageEditEntryArgs = StorageWriteEntryArgs;
|
|
53
|
+
export type StorageEditEntryResult = {
|
|
54
|
+
adapterId: string;
|
|
55
|
+
storageId: string;
|
|
56
|
+
edited: true;
|
|
57
|
+
key: string;
|
|
58
|
+
};
|
|
59
|
+
export type StorageRemoveEntryArgs = StorageSelection & {
|
|
60
|
+
key: string;
|
|
61
|
+
};
|
|
62
|
+
export type StorageRemoveEntryResult = {
|
|
63
|
+
adapterId: string;
|
|
64
|
+
storageId: string;
|
|
65
|
+
removed: boolean;
|
|
66
|
+
key: string;
|
|
67
|
+
};
|
|
68
|
+
export declare const storageToolDefinitions: {
|
|
69
|
+
readonly listStorages: AgentToolContract<undefined, StorageListStoragesResult>;
|
|
70
|
+
readonly listEntries: AgentToolContract<StorageListEntriesArgs, StorageListEntriesResult>;
|
|
71
|
+
readonly readEntry: AgentToolContract<StorageReadEntryArgs, StorageReadEntryResult>;
|
|
72
|
+
readonly createEntry: AgentToolContract<StorageWriteEntryArgs, StorageCreateEntryResult>;
|
|
73
|
+
readonly editEntry: AgentToolContract<StorageWriteEntryArgs, StorageEditEntryResult>;
|
|
74
|
+
readonly removeEntry: AgentToolContract<StorageRemoveEntryArgs, StorageRemoveEntryResult>;
|
|
75
|
+
};
|
|
76
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.storageToolDefinitions = exports.STORAGE_AGENT_ENTRY_TYPES = exports.STORAGE_AGENT_PLUGIN_ID = void 0;
|
|
4
|
+
const agent_shared_1 = require("@rozenite/agent-shared");
|
|
5
|
+
const sharedStorageProperties = {
|
|
6
|
+
adapterId: {
|
|
7
|
+
type: 'string',
|
|
8
|
+
description: 'Storage adapter ID. Required when multiple adapters are configured.',
|
|
9
|
+
},
|
|
10
|
+
storageId: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: 'Storage node ID within the adapter. Required when multiple storages are configured.',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
exports.STORAGE_AGENT_PLUGIN_ID = '@rozenite/storage-plugin';
|
|
16
|
+
exports.STORAGE_AGENT_ENTRY_TYPES = [
|
|
17
|
+
'string',
|
|
18
|
+
'number',
|
|
19
|
+
'boolean',
|
|
20
|
+
'buffer',
|
|
21
|
+
];
|
|
22
|
+
exports.storageToolDefinitions = {
|
|
23
|
+
listStorages: (0, agent_shared_1.defineAgentToolContract)({
|
|
24
|
+
name: 'list-storages',
|
|
25
|
+
description: 'List all storage adapters and their storage nodes currently available on the device, including supported entry types. Entry counts are omitted to avoid enumerating every storage.',
|
|
26
|
+
inputSchema: { type: 'object', properties: {} },
|
|
27
|
+
}),
|
|
28
|
+
listEntries: (0, agent_shared_1.definePaginatedAgentToolContract)({
|
|
29
|
+
name: 'list-entries',
|
|
30
|
+
description: 'List keys in a storage. This call intentionally does not return entry values to keep responses token-efficient.',
|
|
31
|
+
inputSchema: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
...sharedStorageProperties,
|
|
35
|
+
limit: {
|
|
36
|
+
type: 'number',
|
|
37
|
+
description: 'Pagination size. Defaults to 20 and is capped at 100.',
|
|
38
|
+
},
|
|
39
|
+
cursor: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
description: 'Opaque pagination cursor from a previous list-entries call.',
|
|
42
|
+
},
|
|
43
|
+
offset: {
|
|
44
|
+
type: 'number',
|
|
45
|
+
description: 'Deprecated initial pagination offset. Must be a non-negative integer and cannot be combined with cursor.',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
pagination: {
|
|
50
|
+
kind: 'cursor',
|
|
51
|
+
fields: ['key'],
|
|
52
|
+
defaultFields: ['key'],
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
readEntry: (0, agent_shared_1.defineAgentToolContract)({
|
|
56
|
+
name: 'read-entry',
|
|
57
|
+
description: 'Read a single storage entry value by key.',
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
...sharedStorageProperties,
|
|
62
|
+
key: { type: 'string', description: 'Entry key.' },
|
|
63
|
+
},
|
|
64
|
+
required: ['key'],
|
|
65
|
+
},
|
|
66
|
+
}),
|
|
67
|
+
createEntry: (0, agent_shared_1.defineAgentToolContract)({
|
|
68
|
+
name: 'create-entry',
|
|
69
|
+
description: 'Create a new storage entry. Fails if the key already exists.',
|
|
70
|
+
inputSchema: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
...sharedStorageProperties,
|
|
74
|
+
key: { type: 'string', description: 'Entry key.' },
|
|
75
|
+
type: {
|
|
76
|
+
type: 'string',
|
|
77
|
+
enum: [...exports.STORAGE_AGENT_ENTRY_TYPES],
|
|
78
|
+
description: 'Entry value type. Must be one of the supported types for the target storage (see list-storages).',
|
|
79
|
+
},
|
|
80
|
+
value: {
|
|
81
|
+
description: 'Entry value matching the provided type.',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
required: ['key', 'type', 'value'],
|
|
85
|
+
},
|
|
86
|
+
}),
|
|
87
|
+
editEntry: (0, agent_shared_1.defineAgentToolContract)({
|
|
88
|
+
name: 'edit-entry',
|
|
89
|
+
description: 'Edit an existing storage entry. Fails if the key does not exist.',
|
|
90
|
+
inputSchema: {
|
|
91
|
+
type: 'object',
|
|
92
|
+
properties: {
|
|
93
|
+
...sharedStorageProperties,
|
|
94
|
+
key: { type: 'string', description: 'Entry key.' },
|
|
95
|
+
type: {
|
|
96
|
+
type: 'string',
|
|
97
|
+
enum: [...exports.STORAGE_AGENT_ENTRY_TYPES],
|
|
98
|
+
description: 'Entry value type. Must be one of the supported types for the target storage (see list-storages).',
|
|
99
|
+
},
|
|
100
|
+
value: {
|
|
101
|
+
description: 'Entry value matching the provided type.',
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
required: ['key', 'type', 'value'],
|
|
105
|
+
},
|
|
106
|
+
}),
|
|
107
|
+
removeEntry: (0, agent_shared_1.defineAgentToolContract)({
|
|
108
|
+
name: 'remove-entry',
|
|
109
|
+
description: 'Remove a storage entry by key.',
|
|
110
|
+
inputSchema: {
|
|
111
|
+
type: 'object',
|
|
112
|
+
properties: {
|
|
113
|
+
...sharedStorageProperties,
|
|
114
|
+
key: { type: 'string', description: 'Entry key.' },
|
|
115
|
+
},
|
|
116
|
+
required: ['key'],
|
|
117
|
+
},
|
|
118
|
+
}),
|
|
119
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export type StorageEntry = {
|
|
2
|
+
key: string;
|
|
3
|
+
type: 'string';
|
|
4
|
+
value: string;
|
|
5
|
+
} | {
|
|
6
|
+
key: string;
|
|
7
|
+
type: 'number';
|
|
8
|
+
value: number;
|
|
9
|
+
} | {
|
|
10
|
+
key: string;
|
|
11
|
+
type: 'boolean';
|
|
12
|
+
value: boolean;
|
|
13
|
+
} | {
|
|
14
|
+
key: string;
|
|
15
|
+
type: 'buffer';
|
|
16
|
+
value: number[];
|
|
17
|
+
};
|
|
18
|
+
export type StorageEntryType = StorageEntry['type'];
|
|
19
|
+
export type StorageEntryValue = StorageEntry['value'];
|
|
20
|
+
export type StorageEntryPreview = {
|
|
21
|
+
key: string;
|
|
22
|
+
type: StorageEntryType;
|
|
23
|
+
preview: string;
|
|
24
|
+
valueSize: number;
|
|
25
|
+
isTruncated: boolean;
|
|
26
|
+
};
|
|
27
|
+
export type StorageCapabilities = {
|
|
28
|
+
supportedTypes: StorageEntryType[];
|
|
29
|
+
};
|
|
30
|
+
export type StorageDescriptor = {
|
|
31
|
+
target: StorageTarget;
|
|
32
|
+
adapterName: string;
|
|
33
|
+
storageName: string;
|
|
34
|
+
entryCount: number;
|
|
35
|
+
capabilities: StorageCapabilities;
|
|
36
|
+
supportsSubscriptions: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type StorageSubscription = {
|
|
39
|
+
remove: () => void;
|
|
40
|
+
};
|
|
41
|
+
export type SyncStorage = {
|
|
42
|
+
kind: 'sync';
|
|
43
|
+
getAllKeys: () => string[];
|
|
44
|
+
get: (key: string) => StorageEntry | undefined;
|
|
45
|
+
set: (entry: StorageEntry) => void;
|
|
46
|
+
delete: (key: string) => void;
|
|
47
|
+
clear: () => void;
|
|
48
|
+
subscribe?: (callback: (key: string) => void) => StorageSubscription;
|
|
49
|
+
};
|
|
50
|
+
export type AsyncStorage = {
|
|
51
|
+
kind: 'async';
|
|
52
|
+
getAllKeys: () => Promise<readonly string[]>;
|
|
53
|
+
get: (key: string) => Promise<StorageEntry | undefined>;
|
|
54
|
+
set: (entry: StorageEntry) => Promise<void>;
|
|
55
|
+
delete: (key: string) => Promise<void>;
|
|
56
|
+
clear: () => Promise<void>;
|
|
57
|
+
subscribe?: (callback: (key: string) => void) => StorageSubscription;
|
|
58
|
+
};
|
|
59
|
+
export type StorageNode = {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
storage: SyncStorage | AsyncStorage;
|
|
63
|
+
capabilities: StorageCapabilities;
|
|
64
|
+
blacklist?: RegExp;
|
|
65
|
+
shouldFilterKey?: (key: string) => boolean;
|
|
66
|
+
};
|
|
67
|
+
export type StorageAdapter = {
|
|
68
|
+
id: string;
|
|
69
|
+
name: string;
|
|
70
|
+
storages: StorageNode[];
|
|
71
|
+
};
|
|
72
|
+
export type StorageTarget = {
|
|
73
|
+
adapterId: string;
|
|
74
|
+
storageId: string;
|
|
75
|
+
};
|
|
76
|
+
export declare const DEFAULT_SUPPORTED_TYPES: StorageEntryType[];
|
|
77
|
+
export declare const getStorageViewId: ({ adapterId, storageId }: StorageTarget) => string;
|
|
78
|
+
export declare const supportsType: (capabilities: StorageCapabilities, type: StorageEntryType) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.supportsType = exports.getStorageViewId = exports.DEFAULT_SUPPORTED_TYPES = void 0;
|
|
4
|
+
exports.DEFAULT_SUPPORTED_TYPES = [
|
|
5
|
+
'string',
|
|
6
|
+
'number',
|
|
7
|
+
'boolean',
|
|
8
|
+
'buffer',
|
|
9
|
+
];
|
|
10
|
+
const getStorageViewId = ({ adapterId, storageId }) => `${adapterId}:${storageId}`;
|
|
11
|
+
exports.getStorageViewId = getStorageViewId;
|
|
12
|
+
const supportsType = (capabilities, type) => capabilities.supportedTypes.includes(type);
|
|
13
|
+
exports.supportsType = supportsType;
|