@opentabs-dev/plugin-sdk 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.
- package/dist/index.d.ts +45 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/log.d.ts +41 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +144 -0
- package/dist/log.js.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -62,6 +62,49 @@ export declare abstract class OpenTabsPlugin {
|
|
|
62
62
|
* persistent side effects can omit this.
|
|
63
63
|
*/
|
|
64
64
|
teardown?(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Called once after the adapter is registered on
|
|
67
|
+
* `globalThis.__openTabs.adapters`. Use for setting up page-level event
|
|
68
|
+
* listeners, observers, or other resources that should exist for the
|
|
69
|
+
* adapter's lifetime.
|
|
70
|
+
*/
|
|
71
|
+
onActivate?(): void;
|
|
72
|
+
/**
|
|
73
|
+
* Called when the adapter is being removed — either before `teardown()`
|
|
74
|
+
* on plugin update, or when the tab navigates away from a matching URL.
|
|
75
|
+
* Use for cleanup of resources set up in `onActivate`.
|
|
76
|
+
*
|
|
77
|
+
* Ordering: `onDeactivate` fires before `teardown` when both are defined.
|
|
78
|
+
*/
|
|
79
|
+
onDeactivate?(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Called on in-page URL changes (pushState, replaceState, popstate,
|
|
82
|
+
* hashchange). Runs in the page context. If the plugin does not
|
|
83
|
+
* implement this method, no navigation listeners are set up.
|
|
84
|
+
*
|
|
85
|
+
* @param url — the new URL after the navigation (window.location.href)
|
|
86
|
+
*/
|
|
87
|
+
onNavigate?(url: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Called before each `tool.handle()` execution. Runs in the page context.
|
|
90
|
+
* Receives the tool name (unprefixed, e.g. "send_message" not
|
|
91
|
+
* "slack_send_message"). Errors thrown here are caught and logged — they
|
|
92
|
+
* do not prevent tool execution.
|
|
93
|
+
*
|
|
94
|
+
* @param toolName — the unprefixed tool name
|
|
95
|
+
*/
|
|
96
|
+
onToolInvocationStart?(toolName: string): void;
|
|
97
|
+
/**
|
|
98
|
+
* Called after each `tool.handle()` completes, whether it succeeded or
|
|
99
|
+
* threw. Receives the tool name, a boolean indicating success, and the
|
|
100
|
+
* wall-clock duration in milliseconds. Errors thrown here are caught and
|
|
101
|
+
* logged.
|
|
102
|
+
*
|
|
103
|
+
* @param toolName — the unprefixed tool name
|
|
104
|
+
* @param success — true if handle() resolved, false if it threw
|
|
105
|
+
* @param durationMs — wall-clock time of tool.handle() in milliseconds
|
|
106
|
+
*/
|
|
107
|
+
onToolInvocationEnd?(toolName: string, success: boolean, durationMs: number): void;
|
|
65
108
|
}
|
|
66
109
|
export { ToolError } from './errors.js';
|
|
67
110
|
export { waitForSelector, waitForSelectorRemoval, querySelectorAll, getTextContent, observeDOM } from './dom.js';
|
|
@@ -72,4 +115,6 @@ export { retry, sleep, waitUntil } from './timing.js';
|
|
|
72
115
|
export type { RetryOptions, WaitUntilOptions } from './timing.js';
|
|
73
116
|
export { getLocalStorage, setLocalStorage, getSessionStorage, getCookie } from './storage.js';
|
|
74
117
|
export { getPageGlobal, getCurrentUrl, getPageTitle } from './page-state.js';
|
|
118
|
+
export { log, _setLogTransport } from './log.js';
|
|
119
|
+
export type { LogLevel, LogEntry, LogTransport } from './log.js';
|
|
75
120
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAM7B,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,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IAAI,IAAI;IACrB;;;;;;OAMG;IACH,UAAU,CAAC,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAC9B;;;;;;;OAOG;IACH,qBAAqB,CAAC,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAC9C;;;;;;;;;OASG;IACH,mBAAmB,CAAC,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI;CACnF;AAMD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMxC,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACjH,YAAY,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAM1E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAChE,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMvD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMlE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAM9F,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM7E,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AACjD,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -35,4 +35,8 @@ export { getLocalStorage, setLocalStorage, getSessionStorage, getCookie } from '
|
|
|
35
35
|
// SDK utilities — Page State
|
|
36
36
|
// ---------------------------------------------------------------------------
|
|
37
37
|
export { getPageGlobal, getCurrentUrl, getPageTitle } from './page-state.js';
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
// SDK utilities — Logging
|
|
40
|
+
// ---------------------------------------------------------------------------
|
|
41
|
+
export { log, _setLogTransport } from './log.js';
|
|
38
42
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,gEAAgE;AAChE,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA0B3D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,MAAuC,EACN,EAAE,CAAC,MAAM,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAgB,cAAc;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,8EAA8E;AAC9E,gEAAgE;AAChE,8EAA8E;AAE9E,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1G,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AA0B3D,4EAA4E;AAC5E,MAAM,CAAC,MAAM,UAAU,GAAG,CACxB,MAAuC,EACN,EAAE,CAAC,MAAM,CAAC;AAE7C;;;GAGG;AACH,MAAM,OAAgB,cAAc;CA+EnC;AAED,8EAA8E;AAC9E,SAAS;AACT,8EAA8E;AAE9E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAGjH,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGhE,8EAA8E;AAC9E,yBAAyB;AACzB,8EAA8E;AAE9E,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGtD,8EAA8E;AAC9E,0BAA0B;AAC1B,8EAA8E;AAE9E,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAE9F,8EAA8E;AAC9E,6BAA6B;AAC7B,8EAA8E;AAE9E,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7E,8EAA8E;AAC9E,0BAA0B;AAC1B,8EAA8E;AAE9E,OAAO,EAAE,GAAG,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/log.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** Log levels matching the MCP LoggingLevel enum */
|
|
2
|
+
type LogLevel = 'debug' | 'info' | 'warning' | 'error';
|
|
3
|
+
/** A single structured log entry */
|
|
4
|
+
interface LogEntry {
|
|
5
|
+
level: LogLevel;
|
|
6
|
+
message: string;
|
|
7
|
+
data: unknown[];
|
|
8
|
+
ts: string;
|
|
9
|
+
}
|
|
10
|
+
/** Transport function signature — receives a log entry for delivery */
|
|
11
|
+
type LogTransport = (entry: LogEntry) => void;
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
* Replaces the active log transport. Called by the adapter IIFE wrapper to
|
|
15
|
+
* route log entries to the Chrome extension instead of the console.
|
|
16
|
+
* Returns a function that restores the default transport.
|
|
17
|
+
*/
|
|
18
|
+
declare const _setLogTransport: (transport: LogTransport) => (() => void);
|
|
19
|
+
/**
|
|
20
|
+
* Structured logging namespace for plugin tool handlers and lifecycle hooks.
|
|
21
|
+
*
|
|
22
|
+
* Log entries are routed to the MCP server when running inside the adapter
|
|
23
|
+
* runtime, or to the browser console when running standalone (unit tests, etc.).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { log } from '@opentabs-dev/plugin-sdk';
|
|
28
|
+
*
|
|
29
|
+
* log.info('Fetching channels', { workspaceId });
|
|
30
|
+
* log.error('Request failed', error);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare const log: Readonly<{
|
|
34
|
+
debug: (message: string, ...args: unknown[]) => void;
|
|
35
|
+
info: (message: string, ...args: unknown[]) => void;
|
|
36
|
+
warn: (message: string, ...args: unknown[]) => void;
|
|
37
|
+
error: (message: string, ...args: unknown[]) => void;
|
|
38
|
+
}>;
|
|
39
|
+
export { _setLogTransport, log };
|
|
40
|
+
export type { LogEntry, LogLevel, LogTransport };
|
|
41
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAIA,oDAAoD;AACpD,KAAK,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC;AAEvD,oCAAoC;AACpC,UAAU,QAAQ;IAChB,KAAK,EAAE,QAAQ,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,OAAO,EAAE,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,uEAAuE;AACvE,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI,CAAC;AA0F9C;;;;;GAKG;AACH,QAAA,MAAM,gBAAgB,GAAI,WAAW,YAAY,KAAG,CAAC,MAAM,IAAI,CAK9D,CAAC;AAkBF;;;;;;;;;;;;;GAaG;AACH,QAAA,MAAM,GAAG;qBAxBG,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;oBAAjC,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;oBAAjC,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;qBAAjC,MAAM,WAAW,OAAO,EAAE,KAAG,IAAI;EA6B3C,CAAC;AAiBH,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC;AACjC,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,CAAC"}
|
package/dist/log.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Structured logging API for plugin authors
|
|
3
|
+
// ---------------------------------------------------------------------------
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
// Safe serialization — entries travel over postMessage / WebSocket
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
const MAX_DATA_LENGTH = 10;
|
|
8
|
+
const MAX_STRING_LENGTH = 4096;
|
|
9
|
+
/**
|
|
10
|
+
* Produces a JSON-safe representation of a single argument.
|
|
11
|
+
* Handles circular references, DOM nodes, functions, and other
|
|
12
|
+
* non-serializable values without throwing.
|
|
13
|
+
*/
|
|
14
|
+
const safeSerializeArg = (value) => {
|
|
15
|
+
if (value === null || value === undefined)
|
|
16
|
+
return value;
|
|
17
|
+
const type = typeof value;
|
|
18
|
+
if (type === 'boolean' || type === 'number')
|
|
19
|
+
return value;
|
|
20
|
+
if (type === 'string') {
|
|
21
|
+
return value.length > MAX_STRING_LENGTH ? value.slice(0, MAX_STRING_LENGTH) + '…' : value;
|
|
22
|
+
}
|
|
23
|
+
if (type === 'function')
|
|
24
|
+
return `[Function: ${value.name || 'anonymous'}]`;
|
|
25
|
+
if (type === 'symbol')
|
|
26
|
+
return `[Symbol: ${value.description ?? ''}]`;
|
|
27
|
+
if (type === 'bigint')
|
|
28
|
+
return `[BigInt: ${value.toString()}]`;
|
|
29
|
+
// DOM nodes
|
|
30
|
+
if (typeof value.nodeType === 'number') {
|
|
31
|
+
const node = value;
|
|
32
|
+
const className = node.className ? `.${node.className.split(' ')[0] ?? ''}` : '';
|
|
33
|
+
return `[${node.nodeName ?? 'Node'}${node.id ? `#${node.id}` : ''}${className}]`;
|
|
34
|
+
}
|
|
35
|
+
// Errors
|
|
36
|
+
if (value instanceof Error) {
|
|
37
|
+
return { name: value.name, message: value.message, stack: value.stack };
|
|
38
|
+
}
|
|
39
|
+
// Fallback: attempt JSON round-trip to strip non-serializable properties
|
|
40
|
+
try {
|
|
41
|
+
const seen = new WeakSet();
|
|
42
|
+
const json = JSON.stringify(value, (_key, v) => {
|
|
43
|
+
if (typeof v === 'object' && v !== null) {
|
|
44
|
+
if (seen.has(v))
|
|
45
|
+
return '[Circular]';
|
|
46
|
+
seen.add(v);
|
|
47
|
+
}
|
|
48
|
+
if (typeof v === 'function')
|
|
49
|
+
return `[Function: ${v.name || 'anonymous'}]`;
|
|
50
|
+
if (typeof v === 'bigint')
|
|
51
|
+
return `[BigInt: ${v.toString()}]`;
|
|
52
|
+
if (typeof v === 'symbol')
|
|
53
|
+
return `[Symbol: ${v.description ?? ''}]`;
|
|
54
|
+
return v;
|
|
55
|
+
});
|
|
56
|
+
return JSON.parse(json);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return `[Unserializable: ${typeof value}]`;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Safely serializes an array of log arguments into a postMessage/JSON-safe form.
|
|
64
|
+
* Truncates to MAX_DATA_LENGTH items.
|
|
65
|
+
*/
|
|
66
|
+
const safeSerialize = (args) => {
|
|
67
|
+
const capped = args.length > MAX_DATA_LENGTH ? args.slice(0, MAX_DATA_LENGTH) : args;
|
|
68
|
+
return capped.map(safeSerializeArg);
|
|
69
|
+
};
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Default transport — console fallback
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
const CONSOLE_METHODS = {
|
|
74
|
+
debug: 'debug',
|
|
75
|
+
info: 'info',
|
|
76
|
+
warning: 'warn',
|
|
77
|
+
error: 'error',
|
|
78
|
+
};
|
|
79
|
+
const defaultTransport = (entry) => {
|
|
80
|
+
const method = CONSOLE_METHODS[entry.level];
|
|
81
|
+
console[method](`[sdk.log] ${entry.message}`, ...entry.data);
|
|
82
|
+
};
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// Transport slot — replaced by the adapter runtime (US-002)
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
let activeTransport = defaultTransport;
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
* Replaces the active log transport. Called by the adapter IIFE wrapper to
|
|
90
|
+
* route log entries to the Chrome extension instead of the console.
|
|
91
|
+
* Returns a function that restores the default transport.
|
|
92
|
+
*/
|
|
93
|
+
const _setLogTransport = (transport) => {
|
|
94
|
+
activeTransport = transport;
|
|
95
|
+
return () => {
|
|
96
|
+
activeTransport = defaultTransport;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
// Public API — sdk.log namespace
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
const makeLogMethod = (level) => (message, ...args) => {
|
|
103
|
+
const entry = {
|
|
104
|
+
level,
|
|
105
|
+
message,
|
|
106
|
+
data: safeSerialize(args),
|
|
107
|
+
ts: new Date().toISOString(),
|
|
108
|
+
};
|
|
109
|
+
activeTransport(entry);
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Structured logging namespace for plugin tool handlers and lifecycle hooks.
|
|
113
|
+
*
|
|
114
|
+
* Log entries are routed to the MCP server when running inside the adapter
|
|
115
|
+
* runtime, or to the browser console when running standalone (unit tests, etc.).
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* import { log } from '@opentabs-dev/plugin-sdk';
|
|
120
|
+
*
|
|
121
|
+
* log.info('Fetching channels', { workspaceId });
|
|
122
|
+
* log.error('Request failed', error);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
const log = Object.freeze({
|
|
126
|
+
debug: makeLogMethod('debug'),
|
|
127
|
+
info: makeLogMethod('info'),
|
|
128
|
+
warn: makeLogMethod('warning'),
|
|
129
|
+
error: makeLogMethod('error'),
|
|
130
|
+
});
|
|
131
|
+
// ---------------------------------------------------------------------------
|
|
132
|
+
// Runtime registration — allows the adapter IIFE wrapper to call
|
|
133
|
+
// _setLogTransport without an explicit import (which would fail if the
|
|
134
|
+
// plugin's installed SDK version predates the log module).
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
const ot = (globalThis.__openTabs ?? {});
|
|
137
|
+
globalThis.__openTabs = ot;
|
|
138
|
+
ot._setLogTransport = _setLogTransport;
|
|
139
|
+
ot.log = log;
|
|
140
|
+
// ---------------------------------------------------------------------------
|
|
141
|
+
// Exports
|
|
142
|
+
// ---------------------------------------------------------------------------
|
|
143
|
+
export { _setLogTransport, log };
|
|
144
|
+
//# sourceMappingURL=log.js.map
|
package/dist/log.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../src/log.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,4CAA4C;AAC5C,8EAA8E;AAgB9E,8EAA8E;AAC9E,mEAAmE;AACnE,8EAA8E;AAE9E,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAE/B;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAAW,EAAE;IACnD,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAExD,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC;IAC1B,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK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uE;AACvE,2DAA2D;AAC3D,8EAA8E;AAE9E,MAAM,EAAE,GAAG,CAAE,UAAsC,CAAC,UAAU,IAAI,EAAE,CAA4B,CAAC;AAChG,UAAsC,CAAC,UAAU,GAAG,EAAE,CAAC;AACxD,EAAE,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;AACvC,EAAE,CAAC,GAAG,GAAG,GAAG,CAAC;AAEb,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,OAAO,EAAE,gBAAgB,EAAE,GAAG,EAAE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentabs-dev/plugin-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"generate:icons": "bun scripts/generate-icon-names.ts"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@opentabs-dev/shared": "^0.0.
|
|
23
|
+
"@opentabs-dev/shared": "^0.0.13"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"zod": "^4.0.0"
|