Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
731 changes: 708 additions & 23 deletions content-scripts/custom-provider-driver.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions modules/custom-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const CUSTOM_PROVIDER_COOKIE_CONSENT_SCRIPT =
export const CUSTOM_API_PANEL_PATH = 'api-panel/api-panel.html';

const CUSTOM_CAPABILITIES = Object.freeze({
imageUpload: false,
imageUpload: true,
inPageNewChat: false,
snapshotStitch: false
});
Expand Down Expand Up @@ -432,7 +432,11 @@ export function toCustomProviderDescriptor(record, { extensionOrigin = null } =
id: record.frameRuleId,
urlFilter: `|${origin}/`
}),
tempChat: null,
tempChat: Object.freeze({
url: null,
normalUrl: normalizedUrl,
retry: true
}),
capabilities: CUSTOM_CAPABILITIES
});
}
Expand Down
66 changes: 56 additions & 10 deletions modules/panel-message-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ export const HOST_TO_FRAME_MESSAGES = Object.freeze([
'context'
],
senderFiles: ['multi-panel/multi-panel.js', 'modules/panel-action-results.js'],
receiverFiles: ['content-scripts/text-injection-all-providers.js']
receiverFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
]
}),
freezeContractEntry({
type: 'INJECT_TEXT_WITH_IMAGES',
Expand All @@ -63,15 +66,21 @@ export const HOST_TO_FRAME_MESSAGES = Object.freeze([
'context'
],
senderFiles: ['multi-panel/multi-panel.js', 'modules/panel-action-results.js'],
receiverFiles: ['content-scripts/text-injection-all-providers.js']
receiverFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
]
}),
freezeContractEntry({
type: 'TRIGGER_SEND',
action: null,
direction: 'host-to-frame',
payloadFields: ['type', 'requestId', 'providerMode', 'context'],
senderFiles: ['multi-panel/multi-panel.js'],
receiverFiles: ['content-scripts/text-injection-all-providers.js']
receiverFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
]
}),
freezeContractEntry({
type: 'NEW_CHAT',
Expand All @@ -87,23 +96,40 @@ export const HOST_TO_FRAME_MESSAGES = Object.freeze([
direction: 'host-to-frame',
payloadFields: ['type', 'providerMode', 'context'],
senderFiles: ['multi-panel/multi-panel.js'],
receiverFiles: ['content-scripts/text-injection-all-providers.js']
receiverFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
]
}),
freezeContractEntry({
type: 'DISABLE_TEMP_CHAT',
action: null,
direction: 'host-to-frame',
payloadFields: ['type', 'providerMode', 'context'],
senderFiles: ['multi-panel/multi-panel.js'],
receiverFiles: ['content-scripts/custom-provider-driver.js']
}),
freezeContractEntry({
type: 'CLEAR_INPUT',
action: null,
direction: 'host-to-frame',
payloadFields: ['type', 'clearImages', 'providerMode', 'context'],
senderFiles: ['multi-panel/multi-panel.js'],
receiverFiles: ['content-scripts/text-injection-all-providers.js']
receiverFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
]
}),
freezeContractEntry({
type: 'PANELIZE_RESTORE_USER_FOCUS',
action: null,
direction: 'host-to-frame',
payloadFields: ['type', 'context'],
senderFiles: ['multi-panel/multi-panel.js'],
receiverFiles: ['content-scripts/text-injection-all-providers.js']
receiverFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
]
}),
freezeContractEntry({
type: 'PANELIZE_SNAPSHOT_PREPARE',
Expand Down Expand Up @@ -156,15 +182,21 @@ export const FRAME_TO_HOST_MESSAGES = Object.freeze([
'succeededImageIds',
'reason'
],
senderFiles: ['content-scripts/text-injection-all-providers.js'],
senderFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
],
receiverFiles: ['modules/panel-action-results.js']
}),
freezeContractEntry({
type: 'PANELIZE_PROVIDER_LOCATION',
action: null,
direction: 'frame-to-host',
payloadFields: ['type', 'provider', 'url', 'context'],
senderFiles: ['content-scripts/text-injection-all-providers.js'],
senderFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
],
receiverFiles: ['multi-panel/multi-panel.js']
}),
freezeContractEntry({
Expand Down Expand Up @@ -196,15 +228,29 @@ export const FRAME_TO_HOST_MESSAGES = Object.freeze([
action: null,
direction: 'frame-to-host',
payloadFields: ['type', 'requestId', 'provider', 'phase', 'context'],
senderFiles: ['content-scripts/text-injection-all-providers.js'],
senderFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
],
receiverFiles: ['multi-panel/multi-panel.js']
}),
freezeContractEntry({
type: 'PANELIZE_TEMP_CHAT_ENABLED',
action: null,
direction: 'frame-to-host',
payloadFields: ['type', 'provider', 'context'],
senderFiles: ['content-scripts/text-injection-all-providers.js'],
senderFiles: [
'content-scripts/text-injection-all-providers.js',
'content-scripts/custom-provider-driver.js'
],
receiverFiles: ['multi-panel/multi-panel.js']
}),
freezeContractEntry({
type: 'PANELIZE_TEMP_CHAT_DISABLED',
action: null,
direction: 'frame-to-host',
payloadFields: ['type', 'provider', 'context'],
senderFiles: ['content-scripts/custom-provider-driver.js'],
receiverFiles: ['multi-panel/multi-panel.js']
}),
freezeContractEntry({
Expand Down
25 changes: 22 additions & 3 deletions modules/provider-registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const DEFAULT_BUILTIN_CAPABILITIES = Object.freeze({
});

const DEFAULT_CUSTOM_CAPABILITIES = Object.freeze({
imageUpload: false,
imageUpload: true,
inPageNewChat: false,
snapshotStitch: false
});
Expand Down Expand Up @@ -577,19 +577,38 @@ export function validateProviderDescriptor(
}
}

if (isCustom && descriptor.tempChat !== null) {
errors.push(`Provider "${id || '<unnamed>'}": custom provider tempChat must be null`);
if (isCustomApi && descriptor.tempChat !== null) {
errors.push(`Provider "${id || '<unnamed>'}": custom API provider tempChat must be null`);
} else if (descriptor.tempChat !== null && descriptor.tempChat !== undefined) {
const tc = descriptor.tempChat;
if (
typeof tc !== 'object' ||
Array.isArray(tc) ||
(tc.url !== null && tc.url !== undefined && !isHttpOrHttpsUrl(tc.url)) ||
!isHttpOrHttpsUrl(tc.normalUrl) ||
typeof tc.retry !== 'boolean'
) {
errors.push(
`Provider "${id || '<unnamed>'}": tempChat must have nullable http(s) url, http(s) normalUrl, and boolean retry`
);
} else if (isCustom) {
if ((tc.url === null || tc.url === undefined) && tc.retry !== true) {
errors.push(
`Provider "${id || '<unnamed>'}": custom provider non-URL tempChat must specify retry: true`
);
}
if (customOrigin !== null) {
if (new URL(tc.normalUrl).origin !== customOrigin) {
errors.push(
`Provider "${id || '<unnamed>'}": custom provider tempChat.normalUrl origin must match frameOrigins[0]`
);
}
if (tc.url && new URL(tc.url).origin !== customOrigin) {
errors.push(
`Provider "${id || '<unnamed>'}": custom provider tempChat.url origin must match frameOrigins[0]`
);
}
}
}
}

Expand Down
Loading
Loading