opencode-qwen-cli-auth 1.0.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 (76) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +162 -0
  3. package/dist/index.d.ts +21 -0
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js +167 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/lib/auth/auth.d.ts +65 -0
  8. package/dist/lib/auth/auth.d.ts.map +1 -0
  9. package/dist/lib/auth/auth.js +419 -0
  10. package/dist/lib/auth/auth.js.map +1 -0
  11. package/dist/lib/auth/browser.d.ts +16 -0
  12. package/dist/lib/auth/browser.d.ts.map +1 -0
  13. package/dist/lib/auth/browser.js +37 -0
  14. package/dist/lib/auth/browser.js.map +1 -0
  15. package/dist/lib/config.d.ts +28 -0
  16. package/dist/lib/config.d.ts.map +1 -0
  17. package/dist/lib/config.js +63 -0
  18. package/dist/lib/config.js.map +1 -0
  19. package/dist/lib/constants.d.ts +105 -0
  20. package/dist/lib/constants.d.ts.map +1 -0
  21. package/dist/lib/constants.js +105 -0
  22. package/dist/lib/constants.js.map +1 -0
  23. package/dist/lib/logger.d.ts +33 -0
  24. package/dist/lib/logger.d.ts.map +1 -0
  25. package/dist/lib/logger.js +100 -0
  26. package/dist/lib/logger.js.map +1 -0
  27. package/dist/lib/prompts/fallback/opencode-qwen-prompt.txt +109 -0
  28. package/dist/lib/prompts/opencode-qwen.d.ts +14 -0
  29. package/dist/lib/prompts/opencode-qwen.d.ts.map +1 -0
  30. package/dist/lib/prompts/opencode-qwen.js +121 -0
  31. package/dist/lib/prompts/opencode-qwen.js.map +1 -0
  32. package/dist/lib/prompts/qwen-code.d.ts +25 -0
  33. package/dist/lib/prompts/qwen-code.d.ts.map +1 -0
  34. package/dist/lib/prompts/qwen-code.js +307 -0
  35. package/dist/lib/prompts/qwen-code.js.map +1 -0
  36. package/dist/lib/prompts/qwen-opencode-bridge.d.ts +15 -0
  37. package/dist/lib/prompts/qwen-opencode-bridge.d.ts.map +1 -0
  38. package/dist/lib/prompts/qwen-opencode-bridge.js +81 -0
  39. package/dist/lib/prompts/qwen-opencode-bridge.js.map +1 -0
  40. package/dist/lib/request/fetch-helpers.d.ts +19 -0
  41. package/dist/lib/request/fetch-helpers.d.ts.map +1 -0
  42. package/dist/lib/request/fetch-helpers.js +50 -0
  43. package/dist/lib/request/fetch-helpers.js.map +1 -0
  44. package/dist/lib/request/header-utils.d.ts +38 -0
  45. package/dist/lib/request/header-utils.d.ts.map +1 -0
  46. package/dist/lib/request/header-utils.js +75 -0
  47. package/dist/lib/request/header-utils.js.map +1 -0
  48. package/dist/lib/request/openai-chunk-builder.d.ts +68 -0
  49. package/dist/lib/request/openai-chunk-builder.d.ts.map +1 -0
  50. package/dist/lib/request/openai-chunk-builder.js +110 -0
  51. package/dist/lib/request/openai-chunk-builder.js.map +1 -0
  52. package/dist/lib/request/payload-analyzer.d.ts +34 -0
  53. package/dist/lib/request/payload-analyzer.d.ts.map +1 -0
  54. package/dist/lib/request/payload-analyzer.js +114 -0
  55. package/dist/lib/request/payload-analyzer.js.map +1 -0
  56. package/dist/lib/request/request-transformer.d.ts +39 -0
  57. package/dist/lib/request/request-transformer.d.ts.map +1 -0
  58. package/dist/lib/request/request-transformer.js +108 -0
  59. package/dist/lib/request/request-transformer.js.map +1 -0
  60. package/dist/lib/request/response-handler.d.ts +15 -0
  61. package/dist/lib/request/response-handler.d.ts.map +1 -0
  62. package/dist/lib/request/response-handler.js +90 -0
  63. package/dist/lib/request/response-handler.js.map +1 -0
  64. package/dist/lib/request/sse-parser.d.ts +36 -0
  65. package/dist/lib/request/sse-parser.d.ts.map +1 -0
  66. package/dist/lib/request/sse-parser.js +85 -0
  67. package/dist/lib/request/sse-parser.js.map +1 -0
  68. package/dist/lib/request/stream-normalizer.d.ts +18 -0
  69. package/dist/lib/request/stream-normalizer.d.ts.map +1 -0
  70. package/dist/lib/request/stream-normalizer.js +140 -0
  71. package/dist/lib/request/stream-normalizer.js.map +1 -0
  72. package/dist/lib/types.d.ts +180 -0
  73. package/dist/lib/types.d.ts.map +1 -0
  74. package/dist/lib/types.js +2 -0
  75. package/dist/lib/types.js.map +1 -0
  76. package/package.json +67 -0
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Constants for Qwen OAuth Plugin
3
+ */
4
+ /** Plugin identifier */
5
+ export declare const PLUGIN_NAME = "qwen-oauth-plugin";
6
+ /** Provider ID for opencode configuration (used in model references like alibaba/coder-model) */
7
+ export declare const PROVIDER_ID = "alibaba";
8
+ /** Dummy API key (actual auth via OAuth) */
9
+ export declare const DUMMY_API_KEY = "qwen-oauth";
10
+ /**
11
+ * Default Qwen Portal API base URL (fallback if resource_url is missing)
12
+ * Note: This plugin is for OAuth authentication only. For API key authentication,
13
+ * use OpenCode's built-in DashScope support.
14
+ *
15
+ * IMPORTANT: Portal API uses /v1 path (not /api/v1)
16
+ * - OAuth endpoints: /api/v1/oauth2/ (for authentication)
17
+ * - Chat API: /v1/ (for completions)
18
+ */
19
+ export declare const DEFAULT_QWEN_BASE_URL = "https://portal.qwen.ai/v1";
20
+ /** Qwen OAuth endpoints and configuration */
21
+ export declare const QWEN_OAUTH: {
22
+ readonly DEVICE_CODE_URL: "https://chat.qwen.ai/api/v1/oauth2/device/code";
23
+ readonly TOKEN_URL: "https://chat.qwen.ai/api/v1/oauth2/token";
24
+ /**
25
+ * Qwen OAuth Client ID
26
+ * Source: Qwen Code CLI (https://github.com/QwenLM/qwen-code)
27
+ * This is a public client ID used for OAuth Device Authorization Grant flow (RFC 8628)
28
+ */
29
+ readonly CLIENT_ID: "f0304373b74a44d2b584a3fb70ca9e56";
30
+ readonly SCOPE: "openid profile email model.completion";
31
+ readonly GRANT_TYPE_DEVICE: "urn:ietf:params:oauth:grant-type:device_code";
32
+ readonly GRANT_TYPE_REFRESH: "refresh_token";
33
+ };
34
+ /** HTTP Status Codes */
35
+ export declare const HTTP_STATUS: {
36
+ readonly OK: 200;
37
+ readonly BAD_REQUEST: 400;
38
+ readonly UNAUTHORIZED: 401;
39
+ readonly FORBIDDEN: 403;
40
+ readonly TOO_MANY_REQUESTS: 429;
41
+ };
42
+ /**
43
+ * Portal API headers
44
+ * Note: Portal API (OAuth) requires special header to indicate OAuth authentication
45
+ */
46
+ export declare const PORTAL_HEADERS: {
47
+ readonly AUTH_TYPE: "X-DashScope-AuthType";
48
+ readonly AUTH_TYPE_VALUE: "qwen_oauth";
49
+ };
50
+ /** Device flow polling configuration */
51
+ export declare const DEVICE_FLOW: {
52
+ readonly INITIAL_POLL_INTERVAL: 2000;
53
+ readonly MAX_POLL_INTERVAL: 10000;
54
+ readonly BACKOFF_MULTIPLIER: 1.5;
55
+ };
56
+ /** Error messages */
57
+ export declare const ERROR_MESSAGES: {
58
+ readonly TOKEN_REFRESH_FAILED: "Failed to refresh token, authentication required";
59
+ readonly DEVICE_AUTH_TIMEOUT: "Device authorization timed out";
60
+ readonly DEVICE_AUTH_DENIED: "User denied authorization";
61
+ readonly REQUEST_PARSE_ERROR: "Error parsing request";
62
+ readonly NO_RESOURCE_URL: "No resource_url in token response, using default";
63
+ };
64
+ /** OAuth error codes */
65
+ export declare const OAUTH_ERRORS: {
66
+ readonly AUTHORIZATION_PENDING: "authorization_pending";
67
+ readonly SLOW_DOWN: "slow_down";
68
+ readonly ACCESS_DENIED: "access_denied";
69
+ readonly EXPIRED_TOKEN: "expired_token";
70
+ };
71
+ /** Log stages for request logging */
72
+ export declare const LOG_STAGES: {
73
+ readonly BEFORE_TRANSFORM: "before-transform";
74
+ readonly AFTER_TRANSFORM: "after-transform";
75
+ readonly RESPONSE: "response";
76
+ readonly ERROR_RESPONSE: "error-response";
77
+ readonly DEVICE_CODE_REQUEST: "device-code-request";
78
+ readonly TOKEN_POLL: "token-poll";
79
+ };
80
+ /** Platform-specific browser opener commands */
81
+ export declare const PLATFORM_OPENERS: {
82
+ readonly darwin: "open";
83
+ readonly win32: "start";
84
+ readonly linux: "xdg-open";
85
+ };
86
+ /** OAuth authorization labels */
87
+ export declare const AUTH_LABELS: {
88
+ readonly OAUTH: "Qwen Account (OAuth)";
89
+ readonly INSTRUCTIONS: "Visit the URL shown in your browser to complete authentication.";
90
+ };
91
+ /** OAuth verification URI parameters */
92
+ export declare const VERIFICATION_URI: {
93
+ /** Query parameter key for client identification */
94
+ readonly CLIENT_PARAM_KEY: "client=";
95
+ /** Full query parameter for Qwen Code client */
96
+ readonly CLIENT_PARAM_VALUE: "client=qwen-code";
97
+ };
98
+ /** Token refresh buffer (refresh 5 minutes before expiry) */
99
+ export declare const TOKEN_REFRESH_BUFFER_MS: number;
100
+ /** Stream processing configuration */
101
+ export declare const STREAM_CONFIG: {
102
+ /** Maximum buffer size for SSE pass-through mode (1MB) */
103
+ readonly MAX_BUFFER_SIZE: number;
104
+ };
105
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAwB;AACxB,eAAO,MAAM,WAAW,sBAAsB,CAAC;AAE/C,iGAAiG;AACjG,eAAO,MAAM,WAAW,YAAY,CAAC;AAErC,4CAA4C;AAC5C,eAAO,MAAM,aAAa,eAAe,CAAC;AAE1C;;;;;;;;GAQG;AACH,eAAO,MAAM,qBAAqB,8BAA8B,CAAC;AAEjE,6CAA6C;AAC7C,eAAO,MAAM,UAAU;;;IAGtB;;;;OAIG;;;;;CAKM,CAAC;AAEX,wBAAwB;AACxB,eAAO,MAAM,WAAW;;;;;;CAMd,CAAC;AAEX;;;GAGG;AACH,eAAO,MAAM,cAAc;;;CAGjB,CAAC;AAEX,wCAAwC;AACxC,eAAO,MAAM,WAAW;;;;CAId,CAAC;AAEX,qBAAqB;AACrB,eAAO,MAAM,cAAc;;;;;;CAMjB,CAAC;AAEX,wBAAwB;AACxB,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,qCAAqC;AACrC,eAAO,MAAM,UAAU;;;;;;;CAOb,CAAC;AAEX,gDAAgD;AAChD,eAAO,MAAM,gBAAgB;;;;CAInB,CAAC;AAEX,iCAAiC;AACjC,eAAO,MAAM,WAAW;;;CAGd,CAAC;AAEX,wCAAwC;AACxC,eAAO,MAAM,gBAAgB;IAC5B,oDAAoD;;IAEpD,gDAAgD;;CAEvC,CAAC;AAEX,6DAA6D;AAC7D,eAAO,MAAM,uBAAuB,QAAgB,CAAC;AAErD,sCAAsC;AACtC,eAAO,MAAM,aAAa;IACzB,0DAA0D;;CAEjD,CAAC"}
@@ -0,0 +1,105 @@
1
+ /**
2
+ * Constants for Qwen OAuth Plugin
3
+ */
4
+ /** Plugin identifier */
5
+ export const PLUGIN_NAME = "qwen-oauth-plugin";
6
+ /** Provider ID for opencode configuration (used in model references like alibaba/coder-model) */
7
+ export const PROVIDER_ID = "alibaba";
8
+ /** Dummy API key (actual auth via OAuth) */
9
+ export const DUMMY_API_KEY = "qwen-oauth";
10
+ /**
11
+ * Default Qwen Portal API base URL (fallback if resource_url is missing)
12
+ * Note: This plugin is for OAuth authentication only. For API key authentication,
13
+ * use OpenCode's built-in DashScope support.
14
+ *
15
+ * IMPORTANT: Portal API uses /v1 path (not /api/v1)
16
+ * - OAuth endpoints: /api/v1/oauth2/ (for authentication)
17
+ * - Chat API: /v1/ (for completions)
18
+ */
19
+ export const DEFAULT_QWEN_BASE_URL = "https://portal.qwen.ai/v1";
20
+ /** Qwen OAuth endpoints and configuration */
21
+ export const QWEN_OAUTH = {
22
+ DEVICE_CODE_URL: "https://chat.qwen.ai/api/v1/oauth2/device/code",
23
+ TOKEN_URL: "https://chat.qwen.ai/api/v1/oauth2/token",
24
+ /**
25
+ * Qwen OAuth Client ID
26
+ * Source: Qwen Code CLI (https://github.com/QwenLM/qwen-code)
27
+ * This is a public client ID used for OAuth Device Authorization Grant flow (RFC 8628)
28
+ */
29
+ CLIENT_ID: "f0304373b74a44d2b584a3fb70ca9e56",
30
+ SCOPE: "openid profile email model.completion",
31
+ GRANT_TYPE_DEVICE: "urn:ietf:params:oauth:grant-type:device_code",
32
+ GRANT_TYPE_REFRESH: "refresh_token",
33
+ };
34
+ /** HTTP Status Codes */
35
+ export const HTTP_STATUS = {
36
+ OK: 200,
37
+ BAD_REQUEST: 400,
38
+ UNAUTHORIZED: 401,
39
+ FORBIDDEN: 403,
40
+ TOO_MANY_REQUESTS: 429,
41
+ };
42
+ /**
43
+ * Portal API headers
44
+ * Note: Portal API (OAuth) requires special header to indicate OAuth authentication
45
+ */
46
+ export const PORTAL_HEADERS = {
47
+ AUTH_TYPE: "X-DashScope-AuthType",
48
+ AUTH_TYPE_VALUE: "qwen_oauth",
49
+ };
50
+ /** Device flow polling configuration */
51
+ export const DEVICE_FLOW = {
52
+ INITIAL_POLL_INTERVAL: 2000, // 2 seconds
53
+ MAX_POLL_INTERVAL: 10000, // 10 seconds
54
+ BACKOFF_MULTIPLIER: 1.5,
55
+ };
56
+ /** Error messages */
57
+ export const ERROR_MESSAGES = {
58
+ TOKEN_REFRESH_FAILED: "Failed to refresh token, authentication required",
59
+ DEVICE_AUTH_TIMEOUT: "Device authorization timed out",
60
+ DEVICE_AUTH_DENIED: "User denied authorization",
61
+ REQUEST_PARSE_ERROR: "Error parsing request",
62
+ NO_RESOURCE_URL: "No resource_url in token response, using default",
63
+ };
64
+ /** OAuth error codes */
65
+ export const OAUTH_ERRORS = {
66
+ AUTHORIZATION_PENDING: "authorization_pending",
67
+ SLOW_DOWN: "slow_down",
68
+ ACCESS_DENIED: "access_denied",
69
+ EXPIRED_TOKEN: "expired_token",
70
+ };
71
+ /** Log stages for request logging */
72
+ export const LOG_STAGES = {
73
+ BEFORE_TRANSFORM: "before-transform",
74
+ AFTER_TRANSFORM: "after-transform",
75
+ RESPONSE: "response",
76
+ ERROR_RESPONSE: "error-response",
77
+ DEVICE_CODE_REQUEST: "device-code-request",
78
+ TOKEN_POLL: "token-poll",
79
+ };
80
+ /** Platform-specific browser opener commands */
81
+ export const PLATFORM_OPENERS = {
82
+ darwin: "open",
83
+ win32: "start",
84
+ linux: "xdg-open",
85
+ };
86
+ /** OAuth authorization labels */
87
+ export const AUTH_LABELS = {
88
+ OAUTH: "Qwen Account (OAuth)",
89
+ INSTRUCTIONS: "Visit the URL shown in your browser to complete authentication.",
90
+ };
91
+ /** OAuth verification URI parameters */
92
+ export const VERIFICATION_URI = {
93
+ /** Query parameter key for client identification */
94
+ CLIENT_PARAM_KEY: "client=",
95
+ /** Full query parameter for Qwen Code client */
96
+ CLIENT_PARAM_VALUE: "client=qwen-code",
97
+ };
98
+ /** Token refresh buffer (refresh 5 minutes before expiry) */
99
+ export const TOKEN_REFRESH_BUFFER_MS = 5 * 60 * 1000; // 5 minutes
100
+ /** Stream processing configuration */
101
+ export const STREAM_CONFIG = {
102
+ /** Maximum buffer size for SSE pass-through mode (1MB) */
103
+ MAX_BUFFER_SIZE: 1024 * 1024,
104
+ };
105
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../lib/constants.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAwB;AACxB,MAAM,CAAC,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAE/C,iGAAiG;AACjG,MAAM,CAAC,MAAM,WAAW,GAAG,SAAS,CAAC;AAErC,4CAA4C;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,YAAY,CAAC;AAE1C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAEjE,6CAA6C;AAC7C,MAAM,CAAC,MAAM,UAAU,GAAG;IACzB,eAAe,EAAE,gDAAgD;IACjE,SAAS,EAAE,0CAA0C;IACrD;;;;OAIG;IACH,SAAS,EAAE,kCAAkC;IAC7C,KAAK,EAAE,uCAAuC;IAC9C,iBAAiB,EAAE,8CAA8C;IACjE,kBAAkB,EAAE,eAAe;CAC1B,CAAC;AAEX,wBAAwB;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IAC1B,KAAK,EAAE,sBAAsB;IAC7B,YAAY,EAAE,iEAAiE;CACtE,CAAC;AAEX,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC/B,oDAAoD;IACpD,gBAAgB,EAAE,SAAS;IAC3B,gDAAgD;IAChD,kBAAkB,EAAE,kBAAkB;CAC7B,CAAC;AAEX,6DAA6D;AAC7D,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,YAAY;AAElE,sCAAsC;AACtC,MAAM,CAAC,MAAM,aAAa,GAAG;IAC5B,0DAA0D;IAC1D,eAAe,EAAE,IAAI,GAAG,IAAI;CACnB,CAAC"}
@@ -0,0 +1,33 @@
1
+ export declare const LOGGING_ENABLED: boolean;
2
+ export declare const DEBUG_ENABLED: boolean;
3
+ /**
4
+ * Log request data to file (only when LOGGING_ENABLED is true)
5
+ * @param stage - The stage of the request (e.g., "before-transform", "after-transform")
6
+ * @param data - The data to log
7
+ */
8
+ export declare function logRequest(stage: string, data: Record<string, unknown>): void;
9
+ /**
10
+ * Log debug information (only when DEBUG_ENABLED is true)
11
+ * @param message - Debug message
12
+ * @param data - Optional data to log
13
+ */
14
+ export declare function logDebug(message: string, data?: unknown): void;
15
+ /**
16
+ * Log error (always enabled for important issues)
17
+ * @param message - Error message
18
+ * @param data - Optional data to log
19
+ */
20
+ export declare function logError(message: string, data?: unknown): void;
21
+ /**
22
+ * Log warning (always enabled for important issues)
23
+ * @param message - Warning message
24
+ * @param data - Optional data to log
25
+ */
26
+ export declare function logWarn(message: string, data?: unknown): void;
27
+ /**
28
+ * Log info message (always enabled)
29
+ * @param message - Info message
30
+ * @param data - Optional data to log
31
+ */
32
+ export declare function logInfo(message: string, data?: unknown): void;
33
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../lib/logger.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,eAAe,SAAoD,CAAC;AACjF,eAAO,MAAM,aAAa,SAA2D,CAAC;AAatF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAiC7E;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAQ9D;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAM9D;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAM7D;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI,CAM7D"}
@@ -0,0 +1,100 @@
1
+ import { writeFileSync, mkdirSync, existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { homedir } from "node:os";
4
+ // Logging configuration
5
+ export const LOGGING_ENABLED = process.env.ENABLE_PLUGIN_REQUEST_LOGGING === "1";
6
+ export const DEBUG_ENABLED = process.env.DEBUG_QWEN_PLUGIN === "1" || LOGGING_ENABLED;
7
+ const LOG_DIR = join(homedir(), ".opencode", "logs", "qwen-plugin");
8
+ // Log startup message about logging state
9
+ if (LOGGING_ENABLED) {
10
+ console.log("[qwen-oauth-plugin] Request logging ENABLED - logs will be saved to:", LOG_DIR);
11
+ }
12
+ if (DEBUG_ENABLED && !LOGGING_ENABLED) {
13
+ console.log("[qwen-oauth-plugin] Debug logging ENABLED");
14
+ }
15
+ let requestCounter = 0;
16
+ /**
17
+ * Log request data to file (only when LOGGING_ENABLED is true)
18
+ * @param stage - The stage of the request (e.g., "before-transform", "after-transform")
19
+ * @param data - The data to log
20
+ */
21
+ export function logRequest(stage, data) {
22
+ // Only log if explicitly enabled via environment variable
23
+ if (!LOGGING_ENABLED)
24
+ return;
25
+ // Ensure log directory exists on first log
26
+ if (!existsSync(LOG_DIR)) {
27
+ mkdirSync(LOG_DIR, { recursive: true });
28
+ }
29
+ const timestamp = new Date().toISOString();
30
+ const requestId = ++requestCounter;
31
+ const filename = join(LOG_DIR, `request-${requestId}-${stage}.json`);
32
+ try {
33
+ writeFileSync(filename, JSON.stringify({
34
+ timestamp,
35
+ requestId,
36
+ stage,
37
+ ...data,
38
+ }, null, 2), "utf8");
39
+ console.log(`[qwen-oauth-plugin] Logged ${stage} to ${filename}`);
40
+ }
41
+ catch (e) {
42
+ const error = e;
43
+ console.error("[qwen-oauth-plugin] Failed to write log:", error.message);
44
+ }
45
+ }
46
+ /**
47
+ * Log debug information (only when DEBUG_ENABLED is true)
48
+ * @param message - Debug message
49
+ * @param data - Optional data to log
50
+ */
51
+ export function logDebug(message, data) {
52
+ if (!DEBUG_ENABLED)
53
+ return;
54
+ if (data !== undefined) {
55
+ console.log(`[qwen-oauth-plugin] ${message}`, data);
56
+ }
57
+ else {
58
+ console.log(`[qwen-oauth-plugin] ${message}`);
59
+ }
60
+ }
61
+ /**
62
+ * Log error (always enabled for important issues)
63
+ * @param message - Error message
64
+ * @param data - Optional data to log
65
+ */
66
+ export function logError(message, data) {
67
+ if (data !== undefined) {
68
+ console.error(`[qwen-oauth-plugin] ${message}`, data);
69
+ }
70
+ else {
71
+ console.error(`[qwen-oauth-plugin] ${message}`);
72
+ }
73
+ }
74
+ /**
75
+ * Log warning (always enabled for important issues)
76
+ * @param message - Warning message
77
+ * @param data - Optional data to log
78
+ */
79
+ export function logWarn(message, data) {
80
+ if (data !== undefined) {
81
+ console.warn(`[qwen-oauth-plugin] ${message}`, data);
82
+ }
83
+ else {
84
+ console.warn(`[qwen-oauth-plugin] ${message}`);
85
+ }
86
+ }
87
+ /**
88
+ * Log info message (always enabled)
89
+ * @param message - Info message
90
+ * @param data - Optional data to log
91
+ */
92
+ export function logInfo(message, data) {
93
+ if (data !== undefined) {
94
+ console.log(`[qwen-oauth-plugin] ${message}`, data);
95
+ }
96
+ else {
97
+ console.log(`[qwen-oauth-plugin] ${message}`);
98
+ }
99
+ }
100
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,wBAAwB;AACxB,MAAM,CAAC,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,6BAA6B,KAAK,GAAG,CAAC;AACjF,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,GAAG,IAAI,eAAe,CAAC;AACtF,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;AAEpE,0CAA0C;AAC1C,IAAI,eAAe,EAAE,CAAC;IACrB,OAAO,CAAC,GAAG,CAAC,sEAAsE,EAAE,OAAO,CAAC,CAAC;AAC9F,CAAC;AACD,IAAI,aAAa,IAAI,CAAC,eAAe,EAAE,CAAC;IACvC,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAC;AAC1D,CAAC;AAED,IAAI,cAAc,GAAG,CAAC,CAAC;AAEvB;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAA6B;IACtE,0DAA0D;IAC1D,IAAI,CAAC,eAAe;QAAE,OAAO;IAE7B,2CAA2C;IAC3C,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1B,SAAS,CAAC,OAAO,EAAE,EA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AC,uBAAuB,OAAO,EAAE,CAAC,CAAC;IACjD,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,IAAc;IACtD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,CAAC,IAAI,CAAC,uBAAuB,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IACtD,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,IAAI,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;IAChD,CAAC;AACF,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,IAAc;IACtD,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,uBAAuB,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,GAAG,CAAC,uBAAuB,OAAO,EAAE,CAAC,CAAC;IAC/C,CAAC;AACF,CAAC"}
@@ -0,0 +1,109 @@
1
+ You are opencode, an interactive CLI tool that helps users with software engineering tasks. Use the instructions below and the tools available to you to assist the user.
2
+
3
+ IMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code you MUST refuse.
4
+ IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure. If it seems malicious, refuse to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code).
5
+ IMPORTANT: You must NEVER generate or guess URLs for the user unless you are confident that the URLs are for helping the user with programming. You may use URLs provided by the user in their messages or local files.
6
+
7
+ If the user asks for help or wants to give feedback inform them of the following:
8
+ - /help: Get help with using opencode
9
+ - To give feedback, users should report the issue at https://github.com/sst/opencode/issues
10
+
11
+ When the user directly asks about opencode (eg 'can opencode do...', 'does opencode have...') or asks in second person (eg 'are you able...', 'can you do...'), first use the WebFetch tool to gather information to answer the question from opencode docs at https://opencode.ai
12
+
13
+ # Tone and style
14
+ You should be concise, direct, and to the point. When you run a non-trivial bash command, you should explain what the command does and why you are running it, to make sure the user understands what you are doing (this is especially important when you are running a command that will make changes to the user's system).
15
+ Remember that your output will be displayed on a command line interface. Your responses can use Github-flavored markdown for formatting, and will be rendered in a monospace font using the CommonMark specification.
16
+ Output text to communicate with the user; all text you output outside of tool use is displayed to the user. Only use tools to complete tasks. Never use tools like Bash or code comments as means to communicate with the user during the session.
17
+ If you cannot or will not help the user with something, please do not say why or what it could lead to, since this comes across as preachy and annoying. Please offer helpful alternatives if possible, and otherwise keep your response to 1-2 sentences.
18
+ Only use emojis if the user explicitly requests it. Avoid using emojis in all communication unless asked.
19
+ IMPORTANT: You should minimize output tokens as much as possible while maintaining helpfulness, quality, and accuracy. Only address the specific query or task at hand, avoiding tangential information unless absolutely critical for completing the request. If you can answer in 1-3 sentences or a short paragraph, please do.
20
+ IMPORTANT: You should NOT answer with unnecessary preamble or postamble (such as explaining your code or summarizing your action), unless the user asks you to.
21
+ IMPORTANT: Keep your responses short, since they will be displayed on a command line interface. You MUST answer concisely with fewer than 4 lines (not including tool use or code generation), unless user asks for detail. Answer the user's question directly, without elaboration, explanation, or details. One word answers are best. Avoid introductions, conclusions, and explanations. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...". Here are some examples to demonstrate appropriate verbosity:
22
+ <example>
23
+ user: 2 + 2
24
+ assistant: 4
25
+ </example>
26
+
27
+ <example>
28
+ user: what is 2+2?
29
+ assistant: 4
30
+ </example>
31
+
32
+ <example>
33
+ user: is 11 a prime number?
34
+ assistant: Yes
35
+ </example>
36
+
37
+ <example>
38
+ user: what command should I run to list files in the current directory?
39
+ assistant: ls
40
+ </example>
41
+
42
+ <example>
43
+ user: what command should I run to watch files in the current directory?
44
+ assistant: [use the ls tool to list the files in the current directory, then read docs/commands in the relevant file to find out how to watch files]
45
+ npm run dev
46
+ </example>
47
+
48
+ <example>
49
+ user: How many golf balls fit inside a jetta?
50
+ assistant: 150000
51
+ </example>
52
+
53
+ <example>
54
+ user: what files are in the directory src/?
55
+ assistant: [runs ls and sees foo.c, bar.c, baz.c]
56
+ user: which file contains the implementation of foo?
57
+ assistant: src/foo.c
58
+ </example>
59
+
60
+ <example>
61
+ user: write tests for new feature
62
+ assistant: [uses grep and glob search tools to find where similar tests are defined, uses concurrent read file tool use blocks in one tool call to read relevant files at the same time, uses edit file tool to write new tests]
63
+ </example>
64
+
65
+ # Proactiveness
66
+ You are allowed to be proactive, but only when the user asks you to do something. You should strive to strike a balance between:
67
+ 1. Doing the right thing when asked, including taking actions and follow-up actions
68
+ 2. Not surprising the user with actions you take without asking
69
+ For example, if the user asks you how to approach something, you should do your best to answer their question first, and not immediately jump into taking actions.
70
+ 3. Do not add additional code explanation summary unless requested by the user. After working on a file, just stop, rather than providing an explanation of what you did.
71
+
72
+ # Following conventions
73
+ When making changes to files, first understand the file's code conventions. Mimic code style, use existing libraries and utilities, and follow existing patterns.
74
+ - NEVER assume that a given library is available, even if it is well known. Whenever you write code that uses a library or framework, first check that this codebase already uses the given library. For example, you might look at neighboring files, or check the package.json (or cargo.toml, and so on depending on the language).
75
+ - When you create a new component, first look at existing components to see how they're written; then consider framework choice, naming conventions, typing, and other conventions.
76
+ - When you edit a piece of code, first look at the code's surrounding context (especially its imports) to understand the code's choice of frameworks and libraries. Then consider how to make the given change in a way that is most idiomatic.
77
+ - Always follow security best practices. Never introduce code that exposes or logs secrets and keys. Never commit secrets or keys to the repository.
78
+
79
+ # Code style
80
+ - IMPORTANT: DO NOT ADD ***ANY*** COMMENTS unless asked
81
+
82
+ # Doing tasks
83
+ The user will primarily request you perform software engineering tasks. This includes solving bugs, adding new functionality, refactoring code, explaining code, and more. For these tasks the following steps are recommended:
84
+ - Use the available search tools to understand the codebase and the user's query. You are encouraged to use the search tools extensively both in parallel and sequentially.
85
+ - Implement the solution using all tools available to you
86
+ - Verify the solution if possible with tests. NEVER assume specific test framework or test script. Check the README or search codebase to determine the testing approach.
87
+ - VERY IMPORTANT: When you have completed a task, you MUST run the lint and typecheck commands (eg. npm run lint, npm run typecheck, ruff, etc.) with Bash if they were provided to you to ensure your code is correct. If you are unable to find the correct command, ask the user for the command to run and if they supply it, proactively suggest writing it to AGENTS.md so that you will know to run it next time.
88
+ NEVER commit changes unless the user explicitly asks you to. It is VERY IMPORTANT to only commit when explicitly asked, otherwise the user will feel that you are being too proactive.
89
+
90
+ - Tool results and user messages may include <system-reminder> tags. <system-reminder> tags contain useful information and reminders. They are NOT part of the user's provided input or the tool result.
91
+
92
+ # Tool usage policy
93
+ - When doing file search, prefer to use the Task tool in order to reduce context usage.
94
+ - You have the capability to call multiple tools in a single response. When multiple independent pieces of information are requested, batch your tool calls together for optimal performance. When making multiple bash tool calls, you MUST send a single message with multiple tools calls to run the calls in parallel. For example, if you need to run "git status" and "git diff", send a single message with two tool calls to run the calls in parallel.
95
+
96
+ You MUST answer concisely with fewer than 4 lines of text (not including tool use or code generation), unless user asks for detail.
97
+
98
+ IMPORTANT: Refuse to write code or explain code that may be used maliciously; even if the user claims it is for educational purposes. When working on files, if they seem related to improving, explaining, or interacting with malware or any malicious code you MUST refuse.
99
+ IMPORTANT: Before you begin work, think about what the code you're editing is supposed to do based on the filenames directory structure. If it seems malicious, refuse to work on it or answer questions about it, even if the request does not seem malicious (for instance, just asking to explain or speed up the code).
100
+
101
+ # Code References
102
+
103
+ When referencing specific functions or pieces of code include the pattern `file_path:line_number` to allow the user to easily navigate to the source code location.
104
+
105
+ <example>
106
+ user: Where are errors from the client handled?
107
+ assistant: Clients are marked as failed in the `connectToServer` function in src/services/process.ts:712.
108
+ </example>
109
+
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Fetch OpenCode qwen.txt prompt from GitHub with ETag caching
3
+ * @returns OpenCode qwen.txt content
4
+ */
5
+ export declare function getOpenCodeQwenPrompt(): Promise<string>;
6
+ /**
7
+ * Check if message content matches OpenCode qwen.txt prompt
8
+ * Used for filtering in QWEN_MODE
9
+ * @param content - Message content to check
10
+ * @param qwenPrompt - OpenCode qwen.txt content
11
+ * @returns True if content matches OpenCode prompt
12
+ */
13
+ export declare function isOpenCodeQwenPrompt(content: string, qwenPrompt: string): boolean;
14
+ //# sourceMappingURL=opencode-qwen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-qwen.d.ts","sourceRoot":"","sources":["../../../lib/prompts/opencode-qwen.ts"],"names":[],"mappings":"AAoCA;;;GAGG;AACH,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,MAAM,CAAC,CAkF7D;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAcjF"}
@@ -0,0 +1,121 @@
1
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
2
+ import { getCacheDir } from "../config.js";
3
+ import { join } from "path";
4
+ import { fileURLToPath } from "url";
5
+ import { dirname } from "path";
6
+ // Get the directory of the current module for loading the fallback file
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = dirname(__filename);
9
+ /**
10
+ * Load the bundled OpenCode qwen.txt fallback
11
+ * This is used when GitHub is unavailable and no cache exists
12
+ */
13
+ function loadBundledFallback() {
14
+ const fallbackPath = join(__dirname, "fallback", "opencode-qwen-prompt.txt");
15
+ return readFileSync(fallbackPath, "utf-8");
16
+ }
17
+ /**
18
+ * OpenCode qwen.txt prompt URL
19
+ */
20
+ const OPENCODE_QWEN_URL = "https://raw.githubusercontent.com/sst/opencode/dev/packages/opencode/src/session/prompt/qwen.txt";
21
+ /**
22
+ * Cache paths
23
+ */
24
+ const CACHE_FILE = "opencode-qwen.txt";
25
+ const META_FILE = "opencode-qwen-meta.json";
26
+ /**
27
+ * Fetch OpenCode qwen.txt prompt from GitHub with ETag caching
28
+ * @returns OpenCode qwen.txt content
29
+ */
30
+ export async function getOpenCodeQwenPrompt() {
31
+ const cacheDir = getCacheDir();
32
+ const cachePath = join(cacheDir, CACHE_FILE);
33
+ const metaPath = join(cacheDir, META_FILE);
34
+ // Ensure cache directory exists
35
+ if (!existsSync(cacheDir)) {
36
+ mkdirSync(cacheDir, { recursive: true, mode: 0o700 });
37
+ }
38
+ // Load cached metadata
39
+ let metadata = null;
40
+ if (existsSync(metaPath)) {
41
+ try {
42
+ const content = readFileSync(metaPath, "utf-8");
43
+ metadata = JSON.parse(content);
44
+ }
45
+ catch {
46
+ // Ignore invalid metadata
47
+ }
48
+ }
49
+ // Fetch with ETag
50
+ const headers = {};
51
+ if (metadata?.etag) {
52
+ headers["If-None-Match"] = metadata.etag;
53
+ }
54
+ try {
55
+ const res = await fetch(OPENCODE_QWEN_URL, { headers });
56
+ // 304 Not Modified - use cache
57
+ if (res.status === 304 && existsSync(cachePath)) {
58
+ const cached = readFileSync(cachePath, "utf-8");
59
+ // Update last checked time
60
+ if (metadata) {
61
+ metadata.lastChecked = Date.now();
62
+ writeFileSync(metaPath, JSON.stringify(metadata, null, 2), "utf-8");
63
+ }
64
+ return cached;
65
+ }
66
+ // 200 OK - update cache
67
+ if (res.ok) {
68
+ const content = await res.text();
69
+ const etag = res.headers.get("etag");
70
+ // Save content
71
+ writeFileSync(cachePath, content, "utf-8");
72
+ // Save metadata
73
+ const newMetadata = {
74
+ etag,
75
+ lastChecked: Date.now(),
76
+ url: OPENCODE_QWEN_URL,
77
+ };
78
+ writeFileSync(metaPath, JSON.stringify(newMetadata, null, 2), "utf-8");
79
+ return content;
80
+ }
81
+ // Fetch failed - use cache if available
82
+ if (existsSync(cachePath)) {
83
+ console.warn("[qwen-oauth-plugin] Failed to fetch OpenCode qwen.txt (status: " + res.status + "), using cache");
84
+ return readFileSync(cachePath, "utf-8");
85
+ }
86
+ // No cache available - use bundled fallback
87
+ console.warn("[qwen-oauth-plugin] No cache available, using bundled fallback for OpenCode qwen.txt");
88
+ return loadBundledFallback();
89
+ }
90
+ catch (error) {
91
+ // Network error - use cache if available
92
+ if (existsSync(cachePath)) {
93
+ console.warn("[qwen-oauth-plugin] Network error fetching OpenCode qwen.txt, using cache");
94
+ return readFileSync(cachePath, "utf-8");
95
+ }
96
+ // No cache available - use bundled fallback as last resort
97
+ console.warn("[qwen-oauth-plugin] Network error and no cache, using bundled fallback for OpenCode qwen.txt");
98
+ return loadBundledFallback();
99
+ }
100
+ }
101
+ /**
102
+ * Check if message content matches OpenCode qwen.txt prompt
103
+ * Used for filtering in QWEN_MODE
104
+ * @param content - Message content to check
105
+ * @param qwenPrompt - OpenCode qwen.txt content
106
+ * @returns True if content matches OpenCode prompt
107
+ */
108
+ export function isOpenCodeQwenPrompt(content, qwenPrompt) {
109
+ // Exact match
110
+ if (content === qwenPrompt) {
111
+ return true;
112
+ }
113
+ // Fuzzy match - check for signature phrases
114
+ const signatures = [
115
+ "You are opencode, an interactive CLI tool",
116
+ "IMPORTANT: Refuse to write code or explain code that may be used maliciously",
117
+ "When the user directly asks about opencode",
118
+ ];
119
+ return signatures.every(sig => content.includes(sig));
120
+ }
121
+ //# sourceMappingURL=opencode-qwen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opencode-qwen.js","sourceRoot":"","sources":["../../../lib/prompts/opencode-qwen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,IAAI,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAE/B,wEAAwE;AACxE,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;;G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