@seekskyworld/open-browser 0.0.0-stage → 0.1.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.
Files changed (109) hide show
  1. package/CONTRIBUTING.md +15 -0
  2. package/Docs/Agent/346/265/217/350/247/210/345/231/250/346/200/273/344/275/223/346/236/266/346/236/204.md +58 -0
  3. package/Docs/THIRD-PARTY-NOTICES.md +12 -0
  4. package/Docs/open-browser-api.d.ts +273 -0
  5. package/Docs/open-browser/344/273/273/345/212/241/350/257/204/346/265/213/346/214/207/345/215/227.md +59 -0
  6. package/Docs/open-browser/351/232/220/347/247/201/344/270/216/345/274/200/346/272/220/345/256/241/350/256/241.md +37 -0
  7. package/Docs//346/216/247/345/210/266/345/217/260/345/210/206/347/273/204/344/270/216/346/216/245/347/256/241/346/226/271/346/241/210.md +31 -0
  8. package/Docs//350/267/250/345/271/263/345/217/260/350/257/225/347/224/250/344/270/216/345/217/221/350/241/214.md +36 -0
  9. package/LICENSE +200 -0
  10. package/README.md +150 -2
  11. package/README.zh-CN.md +155 -0
  12. package/SECURITY.md +9 -0
  13. package/access-registry.mjs +151 -0
  14. package/action-execution.mjs +374 -0
  15. package/activity-notifier.mjs +34 -0
  16. package/api-contract.mjs +122 -0
  17. package/browser-extension/icons/open-browser-128.png +0 -0
  18. package/browser-extension/icons/open-browser-16.png +0 -0
  19. package/browser-extension/icons/open-browser-32.png +0 -0
  20. package/browser-extension/icons/open-browser-48.png +0 -0
  21. package/browser-extension/icons/open-browser-wordmark.png +0 -0
  22. package/browser-extension/manifest.json +38 -0
  23. package/browser-extension/newtab.css +20 -0
  24. package/browser-extension/newtab.html +19 -0
  25. package/browser-extension/newtab.js +123 -0
  26. package/browser-extension/phase-labels.js +9 -0
  27. package/browser-extension/popup.css +19 -0
  28. package/browser-extension/popup.html +46 -0
  29. package/browser-extension/popup.js +324 -0
  30. package/browser-extension/tab-action.js +137 -0
  31. package/browser-extension/worker.js +188 -0
  32. package/browser-extension/workspace-title.js +15 -0
  33. package/capability-matrix.mjs +21 -0
  34. package/chromium-host.mjs +149 -0
  35. package/chromium-shell.mjs +150 -0
  36. package/cli.mjs +83 -0
  37. package/contract-validation.mjs +27 -0
  38. package/control.mjs +107 -0
  39. package/desktop/Info.plist +13 -0
  40. package/desktop/Launcher.m +117 -0
  41. package/desktop/OBControlBar.h +7 -0
  42. package/desktop/OBControlBar.m +213 -0
  43. package/desktop/OBPageView.h +6 -0
  44. package/desktop/OBPageView.m +348 -0
  45. package/desktop/WorkspacePanel.h +16 -0
  46. package/desktop/WorkspacePanel.m +915 -0
  47. package/desktop/archive-release.py +129 -0
  48. package/desktop/brand-keychain.py +95 -0
  49. package/desktop/brand-locales.py +93 -0
  50. package/desktop/brand-macos-icons.py +24 -0
  51. package/desktop/brand-windows-icons.mjs +48 -0
  52. package/desktop/build-macos.mjs +96 -0
  53. package/desktop/build-portable.mjs +95 -0
  54. package/desktop/build.mjs +5 -0
  55. package/desktop/create-shortcut.ps1 +9 -0
  56. package/desktop/generate-icons.py +39 -0
  57. package/desktop/icons/open-browser.icns +0 -0
  58. package/desktop/icons/open-browser.ico +0 -0
  59. package/desktop/install-menu-entry.mjs +24 -0
  60. package/desktop/package-assets.mjs +34 -0
  61. package/desktop/patches/chromium-macos-keychain-service.patch +18 -0
  62. package/desktop/portable-archive.py +22 -0
  63. package/desktop/sign.mjs +33 -0
  64. package/desktop/smoke-portable.mjs +65 -0
  65. package/desktop/start.mjs +12 -0
  66. package/desktop/verify-upgrade.mjs +74 -0
  67. package/desktop/verify-version.mjs +12 -0
  68. package/desktop-page.mjs +211 -0
  69. package/diagnostics.mjs +28 -0
  70. package/downloads.mjs +110 -0
  71. package/engine-service.mjs +1002 -0
  72. package/hosted/README.md +74 -0
  73. package/hosted/cli.mjs +17 -0
  74. package/hosted/directory.mjs +261 -0
  75. package/hosted/init.mjs +37 -0
  76. package/hosted/server.mjs +129 -0
  77. package/managed-popup.mjs +54 -0
  78. package/mcp.mjs +43 -0
  79. package/network-policy.mjs +107 -0
  80. package/output-store.mjs +96 -0
  81. package/package.json +57 -4
  82. package/page-activity.mjs +121 -0
  83. package/page-dialogs.mjs +53 -0
  84. package/page-observation.mjs +280 -0
  85. package/paths.mjs +20 -0
  86. package/privacy-config.mjs +95 -0
  87. package/receipt-store.mjs +191 -0
  88. package/runtime.mjs +44 -0
  89. package/scheduler.mjs +70 -0
  90. package/sdk.mjs +176 -0
  91. package/service.mjs +271 -0
  92. package/site-workflow.mjs +115 -0
  93. package/skills/open-browser/SKILL.md +86 -0
  94. package/skills/open-browser/scripts/bootstrap.mjs +134 -0
  95. package/skills/open-browser/scripts/open-browser +21 -0
  96. package/skills/open-browser/scripts/open-browser.cmd +9 -0
  97. package/skills/open-browser/workflows/login-export.json +10 -0
  98. package/skills/open-browser/workflows/upload-verify.json +8 -0
  99. package/studio/demo-site.mjs +111 -0
  100. package/studio/demo.css +1 -0
  101. package/studio/index.html +66 -0
  102. package/studio/index.mjs +57 -0
  103. package/studio/native-demo.mjs +124 -0
  104. package/studio/studio.css +119 -0
  105. package/studio/studio.js +438 -0
  106. package/uploads.mjs +63 -0
  107. package/visual-page.mjs +306 -0
  108. package/workspace-lifecycle.mjs +170 -0
  109. package/workspace-state.mjs +95 -0
@@ -0,0 +1,117 @@
1
+ #import <AppKit/AppKit.h>
2
+ #import <signal.h>
3
+ #import "OBControlBar.h"
4
+
5
+ // Chromium owns the window, menus and web input. The bundle launcher owns
6
+ // the local service lifetime and forwards Dock reopen events to its window.
7
+ @interface Launcher : NSObject <NSApplicationDelegate>
8
+ @property(strong) NSTask *service;
9
+ @property(strong) OBControlBar *bar;
10
+ @property(strong) NSFileHandle *input;
11
+ @property(strong) dispatch_queue_t writer;
12
+ @property BOOL ready;
13
+ @property BOOL quitting;
14
+ @end
15
+
16
+ @implementation Launcher
17
+ - (void)applicationDidFinishLaunching:(NSNotification *)note {
18
+ NSURL *resources = NSBundle.mainBundle.resourceURL;
19
+ NSURL *app = [resources URLByAppendingPathComponent:@"app"];
20
+ self.service = [NSTask new];
21
+ self.service.currentDirectoryURL = app;
22
+ self.service.executableURL = [resources URLByAppendingPathComponent:@"node/bin/node"];
23
+ self.service.arguments = @[[app URLByAppendingPathComponent:@"service.mjs"].path, @"--chromium", @"--desktop-bar"];
24
+ NSPipe *output = [NSPipe pipe];
25
+ self.service.standardOutput = output;
26
+ NSPipe *input = [NSPipe pipe];
27
+ self.service.standardInput = input;
28
+ self.input = input.fileHandleForWriting;
29
+ self.writer = dispatch_queue_create("open-browser.desktop.bar.write", DISPATCH_QUEUE_SERIAL);
30
+ signal(SIGPIPE, SIG_IGN);
31
+ __weak Launcher *owner = self;
32
+ self.service.terminationHandler = ^(NSTask *task) {
33
+ dispatch_async(dispatch_get_main_queue(), ^{
34
+ [owner.bar stop];
35
+ owner.ready = NO;
36
+ if (owner.quitting) { [NSApp replyToApplicationShouldTerminate:YES]; return; }
37
+ if (task.terminationStatus != 0) [owner showError:@"本机浏览器服务已退出。请检查是否已从源码启动同一服务。"];
38
+ [NSApp terminate:nil];
39
+ });
40
+ };
41
+ NSError *error = nil;
42
+ if (![self.service launchAndReturnError:&error]) {
43
+ [self showError:error.localizedDescription]; [NSApp terminate:nil]; return;
44
+ }
45
+ self.bar = [[OBControlBar alloc] initWithEngineRoot:[app URLByAppendingPathComponent:@".open-browser/engine"]
46
+ servicePID:self.service.processIdentifier send:^(NSDictionary *event) { [owner sendEvent:event]; }];
47
+ dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{
48
+ [owner readEvents:output.fileHandleForReading];
49
+ });
50
+ }
51
+
52
+ - (void)sendEvent:(NSDictionary *)event {
53
+ if (!self.ready || self.quitting || !self.service.running) return;
54
+ NSMutableData *line = [[NSJSONSerialization dataWithJSONObject:event options:0 error:NULL] mutableCopy];
55
+ if (!line) return;
56
+ [line appendBytes:"\n" length:1];
57
+ dispatch_async(self.writer, ^{ [self.input writeData:line error:NULL]; });
58
+ }
59
+
60
+ - (void)readEvents:(NSFileHandle *)handle {
61
+ NSMutableData *line = [NSMutableData data];
62
+ BOOL skip = NO;
63
+ for (;;) @autoreleasepool {
64
+ NSData *chunk = handle.availableData;
65
+ if (!chunk.length) return;
66
+ const uint8_t *start = chunk.bytes, *end = start + chunk.length;
67
+ while (start < end) {
68
+ const uint8_t *newline = memchr(start, '\n', end - start);
69
+ NSUInteger count = (newline ?: end) - start;
70
+ if (!skip && line.length + count <= 65536) [line appendBytes:start length:count];
71
+ else skip = YES;
72
+ if (!newline) break;
73
+ if (!skip) {
74
+ id message = [NSJSONSerialization JSONObjectWithData:line options:0 error:NULL];
75
+ BOOL ready = [line isEqualToData:[@"open-browser ready" dataUsingEncoding:NSUTF8StringEncoding]];
76
+ dispatch_async(dispatch_get_main_queue(), ^{
77
+ if (!self.service.running || self.quitting) return;
78
+ NSDictionary *event = [message isKindOfClass:NSDictionary.class] ? message : nil;
79
+ if (ready || [event[@"ready"] isEqual:@YES]) self.ready = YES;
80
+ if ([event[@"event"] isEqual:@"desktop.bar"]) [self.bar update:event[@"bar"]];
81
+ });
82
+ }
83
+ [line setLength:0]; skip = NO;
84
+ start = newline + 1;
85
+ }
86
+ }
87
+ }
88
+ - (void)showError:(NSString *)message {
89
+ NSAlert *alert = [NSAlert new];
90
+ alert.messageText = @"open-browser";
91
+ alert.informativeText = message;
92
+ [NSApp activateIgnoringOtherApps:YES];
93
+ [alert runModal];
94
+ }
95
+ - (BOOL)applicationShouldHandleReopen:(NSApplication *)app hasVisibleWindows:(BOOL)flag {
96
+ if (self.ready && self.service.running) kill(self.service.processIdentifier, SIGUSR2);
97
+ return YES;
98
+ }
99
+ - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)app {
100
+ if (!self.service.running) return NSTerminateNow;
101
+ self.quitting = YES;
102
+ [self.bar stop];
103
+ [self.service terminate];
104
+ return NSTerminateLater;
105
+ }
106
+ @end
107
+
108
+ int main(int argc, const char *argv[]) {
109
+ @autoreleasepool {
110
+ NSApplication *app = [NSApplication sharedApplication];
111
+ [app setActivationPolicy:NSApplicationActivationPolicyAccessory];
112
+ __attribute__((objc_precise_lifetime)) Launcher *delegate = [Launcher new];
113
+ app.delegate = delegate;
114
+ [app run];
115
+ }
116
+ return 0;
117
+ }
@@ -0,0 +1,7 @@
1
+ #import <AppKit/AppKit.h>
2
+
3
+ @interface OBControlBar : NSObject
4
+ - (instancetype)initWithEngineRoot:(NSURL *)root servicePID:(pid_t)servicePID send:(void (^)(NSDictionary *event))send;
5
+ - (void)update:(NSDictionary *)bar;
6
+ - (void)stop;
7
+ @end
@@ -0,0 +1,213 @@
1
+ #import "OBControlBar.h"
2
+ #import <CoreGraphics/CoreGraphics.h>
3
+ #import <sys/sysctl.h>
4
+
5
+ @interface OBPanel : NSPanel
6
+ @end
7
+ @implementation OBPanel
8
+ - (BOOL)canBecomeKeyWindow { return NO; }
9
+ - (BOOL)canBecomeMainWindow { return NO; }
10
+ @end
11
+
12
+ @interface OBBarButton : NSButton
13
+ @property(copy) NSDictionary *binding;
14
+ @property(copy) NSDictionary *pressedBinding;
15
+ @end
16
+ @implementation OBBarButton
17
+ - (BOOL)acceptsFirstResponder { return NO; }
18
+ - (BOOL)acceptsFirstMouse:(NSEvent *)event { return YES; }
19
+ - (void)mouseDown:(NSEvent *)event {
20
+ self.pressedBinding = self.binding;
21
+ [super mouseDown:event];
22
+ self.pressedBinding = nil;
23
+ }
24
+ @end
25
+
26
+ static BOOL IsChildOfService(pid_t pid, pid_t servicePID) {
27
+ for (int i = 0; i < 8 && pid > 1; i++) {
28
+ if (pid == servicePID) return YES;
29
+ struct kinfo_proc info = {0};
30
+ size_t size = sizeof(info);
31
+ int mib[] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
32
+ if (sysctl(mib, 4, &info, &size, NULL, 0) < 0 || size != sizeof(info)) return NO;
33
+ pid = info.kp_eproc.e_ppid;
34
+ }
35
+ return NO;
36
+ }
37
+
38
+ // WindowServer and chrome.windows both express these bounds in desktop points,
39
+ // measured from the top left of the primary display.
40
+ static BOOL FrontWindowMatches(pid_t pid, CGRect expected) {
41
+ NSArray *windows = CFBridgingRelease(CGWindowListCopyWindowInfo(
42
+ kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements, kCGNullWindowID));
43
+ for (NSDictionary *info in windows) {
44
+ if ([info[(id)kCGWindowOwnerPID] intValue] != pid || [info[(id)kCGWindowLayer] integerValue] != 0) continue;
45
+ CGRect bounds;
46
+ if (!CGRectMakeWithDictionaryRepresentation((__bridge CFDictionaryRef)info[(id)kCGWindowBounds], &bounds)) continue;
47
+ return fabs(bounds.origin.x - expected.origin.x) <= 3 && fabs(bounds.origin.y - expected.origin.y) <= 3 &&
48
+ fabs(bounds.size.width - expected.size.width) <= 3 && fabs(bounds.size.height - expected.size.height) <= 3;
49
+ }
50
+ return NO;
51
+ }
52
+
53
+ static NSString *Text(id value) { return [value isKindOfClass:NSString.class] ? value : @""; }
54
+
55
+ @interface OBControlBar ()
56
+ @property(strong) OBPanel *panel;
57
+ @property(strong) NSTextField *agent, *status;
58
+ @property(strong) OBBarButton *button, *delivery;
59
+ @property(strong) NSView *dot;
60
+ @property(copy) NSDictionary *bar, *pending;
61
+ @property(copy) NSString *rootPrefix;
62
+ @property(copy) void (^send)(NSDictionary *);
63
+ @property pid_t servicePID;
64
+ @property(strong) NSTimer *timer;
65
+ @end
66
+
67
+ @implementation OBControlBar
68
+ - (instancetype)initWithEngineRoot:(NSURL *)root servicePID:(pid_t)pid send:(void (^)(NSDictionary *))send {
69
+ if (!(self = [super init])) return nil;
70
+ _servicePID = pid;
71
+ _rootPrefix = [root.URLByResolvingSymlinksInPath.path stringByAppendingString:@"/"];
72
+ _send = [send copy];
73
+ _panel = [[OBPanel alloc] initWithContentRect:NSMakeRect(0, 0, 248, 42)
74
+ styleMask:NSWindowStyleMaskBorderless | NSWindowStyleMaskNonactivatingPanel backing:NSBackingStoreBuffered defer:NO];
75
+ _panel.title = @"open-browser 控制条";
76
+ _panel.floatingPanel = YES;
77
+ _panel.level = NSFloatingWindowLevel;
78
+ _panel.hidesOnDeactivate = NO;
79
+ _panel.opaque = NO;
80
+ _panel.backgroundColor = NSColor.clearColor;
81
+ _panel.hasShadow = YES;
82
+ _panel.releasedWhenClosed = NO;
83
+ _panel.excludedFromWindowsMenu = YES;
84
+ _panel.collectionBehavior = NSWindowCollectionBehaviorCanJoinAllSpaces | NSWindowCollectionBehaviorFullScreenAuxiliary | NSWindowCollectionBehaviorIgnoresCycle;
85
+
86
+ NSVisualEffectView *surface = [NSVisualEffectView new];
87
+ surface.material = NSVisualEffectMaterialPopover;
88
+ surface.state = NSVisualEffectStateActive;
89
+ surface.wantsLayer = YES;
90
+ surface.layer.cornerRadius = 13;
91
+ surface.layer.masksToBounds = YES;
92
+ _panel.contentView = surface;
93
+ _dot = [NSView new];
94
+ _dot.wantsLayer = YES;
95
+ _dot.layer.cornerRadius = 4;
96
+ [_dot.widthAnchor constraintEqualToConstant:8].active = YES;
97
+ [_dot.heightAnchor constraintEqualToConstant:8].active = YES;
98
+ _agent = [NSTextField labelWithString:@""];
99
+ _agent.font = [NSFont systemFontOfSize:13 weight:NSFontWeightSemibold];
100
+ _agent.lineBreakMode = NSLineBreakByTruncatingTail;
101
+ [_agent setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
102
+ _status = [NSTextField labelWithString:@""];
103
+ _status.font = [NSFont systemFontOfSize:12];
104
+ _status.textColor = NSColor.secondaryLabelColor;
105
+ _button = [OBBarButton buttonWithTitle:@"人工接管" target:self action:@selector(click:)];
106
+ _button.bezelStyle = NSBezelStyleRounded;
107
+ _button.controlSize = NSControlSizeSmall;
108
+ _button.focusRingType = NSFocusRingTypeNone;
109
+ _delivery = [OBBarButton buttonWithTitle:@"结束" target:self action:@selector(click:)];
110
+ _delivery.bezelStyle = NSBezelStyleRounded;
111
+ _delivery.controlSize = NSControlSizeSmall;
112
+ _delivery.toolTip = @"结束当前 Agent 任务并保留现有页面";
113
+ NSStackView *row = [NSStackView stackViewWithViews:@[_dot, _agent, _status, _button, _delivery]];
114
+ row.spacing = 8;
115
+ row.alignment = NSLayoutAttributeCenterY;
116
+ row.translatesAutoresizingMaskIntoConstraints = NO;
117
+ [surface addSubview:row];
118
+ [NSLayoutConstraint activateConstraints:@[
119
+ [row.leadingAnchor constraintEqualToAnchor:surface.leadingAnchor constant:13],
120
+ [row.trailingAnchor constraintEqualToAnchor:surface.trailingAnchor constant:-10],
121
+ [row.centerYAnchor constraintEqualToAnchor:surface.centerYAnchor]
122
+ ]];
123
+ NSNotificationCenter *events = NSWorkspace.sharedWorkspace.notificationCenter;
124
+ [events addObserver:self selector:@selector(frontChanged:) name:NSWorkspaceDidActivateApplicationNotification object:nil];
125
+ [events addObserver:self selector:@selector(frontChanged:) name:NSWorkspaceActiveSpaceDidChangeNotification object:nil];
126
+ return self;
127
+ }
128
+
129
+ - (void)frontChanged:(NSNotification *)note { [self place]; }
130
+
131
+ - (BOOL)frontMatches:(CGRect)bounds {
132
+ NSRunningApplication *front = NSWorkspace.sharedWorkspace.frontmostApplication;
133
+ if (![front.bundleIdentifier isEqual:@"local.open-browser.chromium"] || front.hidden) return NO;
134
+ NSString *path = front.executableURL.URLByResolvingSymlinksInPath.path;
135
+ return [path hasPrefix:self.rootPrefix] && [path hasSuffix:@"/open-browser.app/Contents/MacOS/open-browser"] &&
136
+ IsChildOfService(front.processIdentifier, self.servicePID) && FrontWindowMatches(front.processIdentifier, bounds);
137
+ }
138
+
139
+ - (void)place {
140
+ if (!self.bar) return;
141
+ CGRect bounds = CGRectMake([self.bar[@"left"] doubleValue], [self.bar[@"top"] doubleValue],
142
+ [self.bar[@"width"] doubleValue], [self.bar[@"height"] doubleValue]);
143
+ CGFloat viewport = MIN([self.bar[@"viewportWidth"] doubleValue], bounds.size.width);
144
+ if (![self frontMatches:bounds] || viewport < 150 || bounds.size.height < 120) { [self.panel orderOut:nil]; return; }
145
+ CGFloat textWidth = ceil(MIN(160, self.agent.intrinsicContentSize.width) + self.status.intrinsicContentSize.width +
146
+ self.button.intrinsicContentSize.width + self.delivery.intrinsicContentSize.width + 66);
147
+ CGFloat width = MIN(viewport - 12, MAX(175, textWidth));
148
+ NSScreen *primary = NSScreen.screens.firstObject;
149
+ if (!primary) { [self.panel orderOut:nil]; return; }
150
+ NSRect frame = NSMakeRect(round(CGRectGetMaxX(bounds) - viewport/2 - width/2),
151
+ round(NSMaxY(primary.frame) - CGRectGetMaxY(bounds) + 16), width, 40);
152
+ if (!NSEqualRects(self.panel.frame, frame)) [self.panel setFrame:frame display:YES];
153
+ if (!self.panel.visible) [self.panel orderFrontRegardless];
154
+ }
155
+
156
+ - (void)update:(NSDictionary *)bar {
157
+ if (![bar isKindOfClass:NSDictionary.class] || !Text(bar[@"workspaceId"]).length ||
158
+ !Text(bar[@"pageId"]).length || !Text(bar[@"controlGeneration"]).length ||
159
+ ![@[@"human", @"agent", @"transferring"] containsObject:Text(bar[@"mode"])]) bar = nil;
160
+ for (NSString *key in @[@"windowId", @"left", @"top", @"width", @"height", @"viewportWidth"]) {
161
+ if (![bar[key] isKindOfClass:NSNumber.class] || !isfinite([bar[key] doubleValue])) { bar = nil; break; }
162
+ }
163
+ self.bar = bar;
164
+ if (!bar) {
165
+ self.pending = nil;
166
+ self.button.binding = nil;
167
+ [self.timer invalidate]; self.timer = nil;
168
+ [self.panel orderOut:nil];
169
+ return;
170
+ }
171
+ NSMutableDictionary *binding = [NSMutableDictionary dictionaryWithObject:@"desktop.bar.click" forKey:@"event"];
172
+ for (NSString *key in @[@"workspaceId", @"pageId", @"windowId", @"controlGeneration", @"mode"]) binding[key] = bar[key];
173
+ self.button.binding = binding;
174
+ NSMutableDictionary *delivery = [binding mutableCopy];
175
+ delivery[@"action"] = @"delivery";
176
+ self.delivery.binding = delivery;
177
+ if (![self.pending isEqual:binding]) self.pending = nil;
178
+ BOOL human = [bar[@"mode"] isEqual:@"human"], transferring = [bar[@"mode"] isEqual:@"transferring"];
179
+ NSDictionary *states = @{@"actionability":@"检查目标", @"dispatching":@"正在派发", @"waiting":@"等待页面", @"verifying":@"核对结果", @"dispatched":@"已派发", @"running":@"执行中", @"queued":@"已排队", @"idle":@"待命", @"completed":@"已完成",
180
+ @"needs_credential":@"等待凭据", @"failed":@"失败", @"cancelled":@"已取消", @"outcome_unknown":@"待核实"};
181
+ self.agent.stringValue = Text(bar[@"agentName"]).length ? bar[@"agentName"] : @"Agent";
182
+ self.agent.toolTip = self.agent.stringValue;
183
+ self.status.stringValue = transferring ? @"交接中" : human ? @"人工控制" : states[Text(bar[@"phase"])] ?: @"待命";
184
+ self.button.title = human ? @"交回 Agent" : @"人工接管";
185
+ self.delivery.enabled = !transferring;
186
+ self.button.enabled = !transferring && !self.pending;
187
+ NSColor *color = transferring ? NSColor.systemOrangeColor : human ? NSColor.systemGreenColor : NSColor.systemBlueColor;
188
+ self.dot.layer.backgroundColor = color.CGColor;
189
+ if (!self.timer) {
190
+ __weak typeof(self) owner = self;
191
+ self.timer = [NSTimer scheduledTimerWithTimeInterval:0.35 repeats:YES block:^(NSTimer *timer) { [owner place]; }];
192
+ }
193
+ [self place];
194
+ }
195
+
196
+ - (void)click:(OBBarButton *)button {
197
+ [self place];
198
+ NSDictionary *binding = button.pressedBinding ?: button.binding;
199
+ if (!binding || !button.enabled || !self.panel.visible || ![binding isEqual:button.binding]) return;
200
+ self.pending = binding;
201
+ button.enabled = NO;
202
+ self.send(binding);
203
+ __weak typeof(self) owner = self;
204
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3*NSEC_PER_SEC), dispatch_get_main_queue(), ^{
205
+ if (owner.pending == binding) { owner.pending = nil; [owner update:owner.bar]; }
206
+ });
207
+ }
208
+
209
+ - (void)stop {
210
+ [NSWorkspace.sharedWorkspace.notificationCenter removeObserver:self];
211
+ [self update:nil];
212
+ }
213
+ @end
@@ -0,0 +1,6 @@
1
+ #import "WorkspacePanel.h"
2
+
3
+ @interface OBPageView : NSView <NSTextInputClient>
4
+ - (instancetype)initWithCall:(WorkspaceCall)call;
5
+ - (void)displayPage:(NSDictionary *)handle mode:(NSString *)mode generation:(NSString *)generation;
6
+ @end