@zhin.js/adapter-sandbox 1.1.0 → 1.1.3

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.
@@ -1,92 +0,0 @@
1
- // Generated by build-plugin-runtime-entries.mjs. Do not edit.
2
- import { PLAYGROUND_STORAGE_KEY, createDefaultPlaygroundState, loadPlaygroundState, savePlaygroundState, } from './playgroundState.js';
3
- class MemoryStorage {
4
- values = new Map();
5
- getItem(key) { return this.values.get(key) ?? null; }
6
- setItem(key, value) { this.values.set(key, value); }
7
- }
8
- describe('sandbox playground persistence', () => {
9
- it('round-trips sessions, messages and per-session run configuration', () => {
10
- const storage = new MemoryStorage();
11
- const initial = createDefaultPlaygroundState('/workspace/zhin');
12
- const sessions = initial.sessions.map((session, index) => index === 0
13
- ? { ...session, runConfig: { ...session.runConfig, safetyMode: 'read-only', networkAccess: true } }
14
- : session);
15
- expect(savePlaygroundState({
16
- activeSessionId: sessions[0].id,
17
- sessions,
18
- messages: [{
19
- id: 'm1', type: 'sent', channelType: 'private', channelId: sessions[0].id,
20
- channelName: sessions[0].name, senderId: 'owner', senderName: 'Owner',
21
- content: [{ type: 'text', data: { text: 'hello' } }], timestamp: 42,
22
- interactionResolved: true,
23
- }],
24
- }, storage)).toBe(true);
25
- const restored = loadPlaygroundState(storage);
26
- expect(restored.activeSessionId).toBe('sandbox-user');
27
- expect(restored.sessions[0]?.runConfig).toMatchObject({
28
- workingDirectory: '/workspace/zhin', safetyMode: 'read-only', networkAccess: true,
29
- });
30
- expect(restored.messages[0]).toMatchObject({ id: 'm1', channelId: 'sandbox-user', interactionResolved: true });
31
- });
32
- it('fails closed to defaults for malformed storage', () => {
33
- const storage = new MemoryStorage();
34
- storage.values.set(PLAYGROUND_STORAGE_KEY, '{broken');
35
- expect(loadPlaygroundState(storage).sessions.map((session) => session.id)).toEqual([
36
- 'sandbox-user', 'sandbox-group', 'sandbox-channel',
37
- ]);
38
- });
39
- it('does not silently accept an unknown persisted schema version', () => {
40
- const storage = new MemoryStorage();
41
- storage.values.set(PLAYGROUND_STORAGE_KEY, JSON.stringify({ version: 2, sessions: [] }));
42
- expect(loadPlaygroundState(storage).activeSessionId).toBe('sandbox-user');
43
- });
44
- it('keeps complete message history instead of silently trimming old entries', () => {
45
- const storage = new MemoryStorage();
46
- const initial = createDefaultPlaygroundState('/workspace/zhin');
47
- const messages = Array.from({ length: 240 }, (_, index) => ({
48
- id: `m${index}`,
49
- type: 'sent',
50
- channelType: 'private',
51
- channelId: initial.sessions[0].id,
52
- channelName: initial.sessions[0].name,
53
- senderId: 'owner',
54
- senderName: 'Owner',
55
- content: [{ type: 'text', data: { text: `message ${index}` } }],
56
- timestamp: index,
57
- }));
58
- expect(savePlaygroundState({
59
- activeSessionId: initial.activeSessionId,
60
- sessions: initial.sessions,
61
- messages,
62
- }, storage)).toBe(true);
63
- expect(loadPlaygroundState(storage).messages).toHaveLength(240);
64
- });
65
- it('keeps sessions with the same id isolated by scope', () => {
66
- const storage = new MemoryStorage();
67
- const initial = createDefaultPlaygroundState('/workspace/zhin');
68
- const sessions = [
69
- { ...initial.sessions[0], id: 'shared', type: 'private' },
70
- { ...initial.sessions[1], id: 'shared', type: 'group' },
71
- ];
72
- expect(savePlaygroundState({
73
- activeSessionId: 'shared',
74
- activeSessionType: 'group',
75
- sessions,
76
- messages: sessions.map((session, index) => ({
77
- id: `m${index}`,
78
- type: 'sent',
79
- channelType: session.type,
80
- channelId: session.id,
81
- channelName: session.name,
82
- senderId: 'owner',
83
- senderName: 'Owner',
84
- content: [{ type: 'text', data: { text: session.type } }],
85
- timestamp: index,
86
- })),
87
- }, storage)).toBe(true);
88
- const restored = loadPlaygroundState(storage);
89
- expect(restored.activeSessionType).toBe('group');
90
- expect(restored.messages.map((message) => message.channelType)).toEqual(['private', 'group']);
91
- });
92
- });
@@ -1,105 +0,0 @@
1
- import {
2
- PLAYGROUND_STORAGE_KEY,
3
- createDefaultPlaygroundState,
4
- loadPlaygroundState,
5
- savePlaygroundState,
6
- type PlaygroundStorage,
7
- } from './playgroundState.js';
8
-
9
- class MemoryStorage implements PlaygroundStorage {
10
- readonly values = new Map<string, string>();
11
- getItem(key: string): string | null { return this.values.get(key) ?? null; }
12
- setItem(key: string, value: string): void { this.values.set(key, value); }
13
- }
14
-
15
- describe('sandbox playground persistence', () => {
16
- it('round-trips sessions, messages and per-session run configuration', () => {
17
- const storage = new MemoryStorage();
18
- const initial = createDefaultPlaygroundState('/workspace/zhin');
19
- const sessions = initial.sessions.map((session, index) => index === 0
20
- ? { ...session, runConfig: { ...session.runConfig, safetyMode: 'read-only' as const, networkAccess: true } }
21
- : session);
22
- expect(savePlaygroundState({
23
- activeSessionId: sessions[0]!.id,
24
- sessions,
25
- messages: [{
26
- id: 'm1', type: 'sent', channelType: 'private', channelId: sessions[0]!.id,
27
- channelName: sessions[0]!.name, senderId: 'owner', senderName: 'Owner',
28
- content: [{ type: 'text', data: { text: 'hello' } }], timestamp: 42,
29
- interactionResolved: true,
30
- }],
31
- }, storage)).toBe(true);
32
-
33
- const restored = loadPlaygroundState(storage);
34
- expect(restored.activeSessionId).toBe('sandbox-user');
35
- expect(restored.sessions[0]?.runConfig).toMatchObject({
36
- workingDirectory: '/workspace/zhin', safetyMode: 'read-only', networkAccess: true,
37
- });
38
- expect(restored.messages[0]).toMatchObject({ id: 'm1', channelId: 'sandbox-user', interactionResolved: true });
39
- });
40
-
41
- it('fails closed to defaults for malformed storage', () => {
42
- const storage = new MemoryStorage();
43
- storage.values.set(PLAYGROUND_STORAGE_KEY, '{broken');
44
- expect(loadPlaygroundState(storage).sessions.map((session) => session.id)).toEqual([
45
- 'sandbox-user', 'sandbox-group', 'sandbox-channel',
46
- ]);
47
- });
48
-
49
- it('does not silently accept an unknown persisted schema version', () => {
50
- const storage = new MemoryStorage();
51
- storage.values.set(PLAYGROUND_STORAGE_KEY, JSON.stringify({ version: 2, sessions: [] }));
52
- expect(loadPlaygroundState(storage).activeSessionId).toBe('sandbox-user');
53
- });
54
-
55
- it('keeps complete message history instead of silently trimming old entries', () => {
56
- const storage = new MemoryStorage();
57
- const initial = createDefaultPlaygroundState('/workspace/zhin');
58
- const messages = Array.from({ length: 240 }, (_, index) => ({
59
- id: `m${index}`,
60
- type: 'sent' as const,
61
- channelType: 'private' as const,
62
- channelId: initial.sessions[0]!.id,
63
- channelName: initial.sessions[0]!.name,
64
- senderId: 'owner',
65
- senderName: 'Owner',
66
- content: [{ type: 'text', data: { text: `message ${index}` } }],
67
- timestamp: index,
68
- }));
69
- expect(savePlaygroundState({
70
- activeSessionId: initial.activeSessionId,
71
- sessions: initial.sessions,
72
- messages,
73
- }, storage)).toBe(true);
74
- expect(loadPlaygroundState(storage).messages).toHaveLength(240);
75
- });
76
-
77
- it('keeps sessions with the same id isolated by scope', () => {
78
- const storage = new MemoryStorage();
79
- const initial = createDefaultPlaygroundState('/workspace/zhin');
80
- const sessions = [
81
- { ...initial.sessions[0]!, id: 'shared', type: 'private' as const },
82
- { ...initial.sessions[1]!, id: 'shared', type: 'group' as const },
83
- ];
84
- expect(savePlaygroundState({
85
- activeSessionId: 'shared',
86
- activeSessionType: 'group',
87
- sessions,
88
- messages: sessions.map((session, index) => ({
89
- id: `m${index}`,
90
- type: 'sent' as const,
91
- channelType: session.type,
92
- channelId: session.id,
93
- channelName: session.name,
94
- senderId: 'owner',
95
- senderName: 'Owner',
96
- content: [{ type: 'text', data: { text: session.type } }],
97
- timestamp: index,
98
- })),
99
- }, storage)).toBe(true);
100
-
101
- const restored = loadPlaygroundState(storage);
102
- expect(restored.activeSessionType).toBe('group');
103
- expect(restored.messages.map((message) => message.channelType)).toEqual(['private', 'group']);
104
- });
105
- });
File without changes
File without changes